Skip to content

Commit

Permalink
chore: fix merge from 0.17.11
Browse files Browse the repository at this point in the history
Also:
* Add new settings: SETTING_PDF_OPEN_FIRST
* Add new methods to Item and Actor to be used in external modules.
* Add new field in Actor/Items: `originalName`
  • Loading branch information
chrismaille committed Sep 23, 2024
1 parent 2738aef commit 36b5ad7
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 16 deletions.
2 changes: 2 additions & 0 deletions lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@
"GURPS.settingHintBasicPDFs": "Wähle 'Kombiniert' oder 'Getrennt' und verwende die entsprechenden PDF-Codes bei der Konfiguration von PDFoundry. Hinweis: Wenn 'Getrennt' gewählt wird, sollte sich das Basic Set Campaigns PDF während des PDFoundry-Tests auf Seite 340 öffnen.",
"GURPS.settingBasicPDFsCombined": "Kombiniertes Basic Set (code 'B')",
"GURPS.settingBasicPDFsSeparate": "Getrennt (Characters, 'B'; Campaigns, 'BX')",
"GURPS.settingPDFOpenFirst": "Öffne das erste gefundene PDF",
"GURPS.settingHintPDFOpenFirst": "Wenn diese Option aktiviert ist, wird das System das erste gefundene PDF öffnen, wenn mehrere Seitenreferenzen angegeben sind. Wenn diese Option deaktiviert ist, wird das System alle gefundenen PDFs öffnen.",
"GURPS.settingImportIgnoreName": "Import: Attribut 'Name' ignorieren",
"GURPS.settingHintImportIgnoreName": "Wenn diese Option aktiviert ist, ignoriert das System das Attribut 'Name' des Akteurs während des Imports. Dies ist nützlich, wenn der Name, der in Foundry verwendet wird, von GCA/GCS abweicht und nicht gewollt ist, dass er bei jedem Import überschrieben wird.",
"GURPS.settingBlockImport": "Nur SERIÖSE Spieler dürfen importieren",
Expand Down
3 changes: 3 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,8 @@
"GURPS.settingHintBasicPDFs": "Select 'Combined' or 'Separate' and use the associated PDF codes when configuring PDFoundry. Note: If you select 'Separate', the Basic Set Campaigns PDF should open up to page 340 during the PDFoundry test.",
"GURPS.settingBasicPDFsCombined": "Combined Basic Set (code 'B')",
"GURPS.settingBasicPDFsSeparate": "Separate (Characters, 'B'; Campaigns, 'BX')",
"GURPS.settingPDFOpenFirst": "Open first PDF found",
"GURPS.settingHintPDFOpenFirst": "If checked, the system will open the first PDF found when multiple Page Refs are informed. If unchecked, system will open all PDFs founded.",
"GURPS.settingImportIgnoreName": "Import: Ignore 'name' attribute",
"GURPS.settingHintImportIgnoreName": "If checked, the system will ignore the 'name' attribute of the Actor during imports. This is useful if the name that you use in Foundry differs from GCA/GCS and you don't want it overwritten on every import.",
"GURPS.settingBlockImport": "Only TRUSTED players may Import",
Expand Down Expand Up @@ -992,6 +994,7 @@
"GURPS.current": "Current",
"GURPS.currentdodge": "Dodge",
"GURPS.damageAbove": "Damage above ",
"GURPS.disadvantage": "Disadvantage",
"GURPS.dead": "Dead",
"GURPS.defense": "Defense",
"GURPS.destroyed": "Destroyed",
Expand Down
2 changes: 2 additions & 0 deletions lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,8 @@
"GURPS.settingHintBasicPDFs": "Sélectionnez 'Combiné' ou 'Separé' et utilisez les codes PDF associés lors de la configuration de PDFFoundry. Note: Si vous sélectionnez 'Separate', le PDF Basic Set Campaigns devrait s'ouvrir à la page 340 pendant le test de PDFoundry.",
"GURPS.settingBasicPDFsCombined": "Basic Set Combiné (code 'B')",
"GURPS.settingBasicPDFsSeparate": "Séparé (Personnages, 'B'; Campagnes, 'BX')",
"GURPS.settingPDFOpenFirst": "Ouvrir le premier PDF trouvé",
"GURPS.settingHintPDFOpenFirst": "Si coché, le système ouvrira le premier PDF trouvé lorsque plusieurs références de page sont indiquées. Si décoché, le système ouvrira tous les PDF trouvés.",
"GURPS.settingImportIgnoreName": "Import: Ignorer l'attribut 'Nom'",
"GURPS.settingHintImportIgnoreName": "Si coché, le système ignorera l'attribut 'Nom' de l'Acteur durant les imports. C'est utile si le nom sur Foundry est différent de GCA/GCS et que vous ne voulez pas écraser à chaque import.",
"GURPS.settingBlockImport": "Seuls les joueurs de 'Trusted' peuvent Importer",
Expand Down
2 changes: 2 additions & 0 deletions lang/pt_br.json
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,8 @@
"GURPS.settingHintBasicPDFs": "Selecione 'Combinado' ou 'Separado' e utilize os códigos de PDF associados quando for configurar o PDFoundry. Nota: Se você selecionar 'Separado', o PDF do Módulo Básico Campanhas deve abrir a partir da página 340 ao executar os testes do PDFoundry.",
"GURPS.settingBasicPDFsCombined": "Módulo Básico Combinado (código 'B')",
"GURPS.settingBasicPDFsSeparate": "Separado (Personagens, 'B'; Campanhas, 'BX')",
"GURPS.settingPDFOpenFirst": "Abrir o primeiro PDF encontrado",
"GURPS.settingHintPDFOpenFirst": "Se marcado, o sistema vai abrir o primeiro PDF encontrado quando múltiplas referências de página forem informadas. Se desmarcado, o sistema vai abrir todos os PDFs encontrados.",
"GURPS.settingImportIgnoreName": "Importação: Ignorar atributo 'nome'",
"GURPS.settingHintImportIgnoreName": "Se marcado, o sistema vai ignorar o atributo 'nome' do Ator durante a importação. Isso é útil caso o nome que você utiliza no Foundry for diferente daquele que consta no GCA/GCS e se você não quiser ter que modificá-lo cada vez que fizer uma importação.",
"GURPS.settingBlockImport": "Apenas jogadores CONFIÁVEIS podem Importar",
Expand Down
11 changes: 11 additions & 0 deletions lib/miscellaneous-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const SETTING_WHISPER_STATUS_EFFECTS = 'whisper-status-effectss'
export const SETTING_CHANGELOG_VERSION = 'changelogVersion'
export const SETTING_SHOW_CHANGELOG = 'showChangelogv2' //change setting to 'reset' for everyone... now that change log only displays changes since last start
export const SETTING_BASICSET_PDF = 'basicsetpdf'
export const SETTING_PDF_OPEN_FIRST = 'pdf-open-first'
export const SETTING_RANGE_TO_BUCKET = 'range-to-bucket'
export const SETTING_MODIFIER_TOOLTIP = 'modifier_tooltip'
export const SETTING_IGNORE_IMPORT_NAME = 'ignore_import_name'
Expand Down Expand Up @@ -168,6 +169,16 @@ export function initializeSettings() {
onChange: value => console.log(`Basic Set PDFs : ${value}`),
})

game.settings.register(SYSTEM_NAME, 'pdf-open-first', {
name: i18n('GURPS.settingPDFOpenFirst'),
hint: i18n('GURPS.settingHintPDFOpenFirst'),
scope: 'world',
config: true,
type: Boolean,
default: false,
onChange: value => console.log(`On multiple Page Refs open first PDF found : ${value}`),
})

// GCS/GCA Import Configuration ----

game.settings.register(SYSTEM_NAME, SETTING_USE_FOUNDRY_ITEMS, {
Expand Down
13 changes: 13 additions & 0 deletions module/actor/actor-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class _Base {
this.contains = {}
this.uuid = ''
this.parentuuid = ''
this.originalName = ''
}

/**
Expand Down Expand Up @@ -345,6 +346,7 @@ export class Skill extends Leveled {
level: this.level || 0,
relativelevel: this.relativelevel || '',
name: this.name,
originalName: this.originalName || '',
['type']: this['type'] || '',
otf: this.otf || '',
checkotf: this.checkotf || '',
Expand All @@ -371,6 +373,7 @@ export class Skill extends Leveled {
skill = data
} else {
skill = new Skill(data.name)
skill.originalName = data.originalName || ''
skill.notes = data.notes
skill.contains = data.contains || {}
skill.uuid = data.uuid
Expand All @@ -391,6 +394,7 @@ export class Skill extends Leveled {
} else {
const itemData = item.system[item.itemSysKey]
result =
itemData.originalName !== this.originalName ||
itemData.notes !== this.notes ||
itemData.pageref !== this.pageref ||
!arraysEqual(Object.keys(itemData.contains), Object.keys(this.contains)) ||
Expand Down Expand Up @@ -449,6 +453,7 @@ export class Spell extends Leveled {
level: this.level || 0,
relativelevel: this.relativelevel || '',
name: this.name,
originalName: this.originalName || '',
['class']: this['class'] || '',
college: this.college || '',
cost: this.cost || '',
Expand Down Expand Up @@ -482,6 +487,7 @@ export class Spell extends Leveled {
spell = data
} else {
spell = new Spell(data.name)
spell.originalName = data.originalName || ''
spell.notes = data.notes
spell.pageref = data.pageref
spell.contains = data.contains || {}
Expand Down Expand Up @@ -511,6 +517,7 @@ export class Spell extends Leveled {
} else {
const itemData = item.system[item.itemSysKey]
result =
itemData.originalName !== this.originalName ||
itemData.notes !== this.notes ||
itemData.pageref !== this.pageref ||
!arraysEqual(Object.keys(itemData.contains), Object.keys(this.contains)) ||
Expand Down Expand Up @@ -573,6 +580,7 @@ export class Advantage extends NamedCost {
userdesc: this.userdesc || '',
note: this.note || '',
name: this.name,
originalName: this.originalName || '',
checkotf: this.checkotf || '',
duringotf: this.duringotf || '',
passotf: this.passotf || '',
Expand All @@ -597,6 +605,7 @@ export class Advantage extends NamedCost {
adv = data
} else {
adv = new Advantage(data.name)
adv.originalName = data.originalName || ''
adv.notes = data.notes
adv.pageref = data.pageref
adv.contains = data.contains || {}
Expand All @@ -616,6 +625,7 @@ export class Advantage extends NamedCost {
} else {
const itemData = item.system[item.itemSysKey]
result =
itemData.originalName !== this.originalName ||
itemData.notes !== this.notes ||
(itemData.pageref || '') !== (this.pageref || '') ||
!arraysEqual(Object.keys(itemData.contains), Object.keys(this.contains)) ||
Expand Down Expand Up @@ -828,6 +838,7 @@ export class Equipment extends Named {
system: {
eqt: {
name: this.name,
originalName: this.originalName || '',
notes: this.notes,
pageref: this.pageref,
count: this.count,
Expand Down Expand Up @@ -868,6 +879,7 @@ export class Equipment extends Named {
equip = data
} else {
equip = new Equipment(data.name, data.save)
equip.originalName = data.originalName || ''
equip.count = data.count
equip.cost = data.cost
equip.weight = data.weight
Expand Down Expand Up @@ -897,6 +909,7 @@ export class Equipment extends Named {
} else {
const itemData = item.system[item.itemSysKey]
result =
itemData.originalName !== this.originalName ||
itemData.notes !== this.notes ||
itemData.pageref !== this.pageref ||
itemData.cost !== this.cost ||
Expand Down
12 changes: 12 additions & 0 deletions module/actor/actor-importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ export class ActorImporter {
let j = json[key]
let a = new Advantage()
a.name = t(j.name)
a.originalName = t(j.name)
a.points = this.intFrom(j.points)
a.setNotes(t(j.text))
a.pageRef(t(j.pageref) || a.pageref)
Expand Down Expand Up @@ -754,6 +755,7 @@ export class ActorImporter {
let j = json[key]
let sk = new Skill()
sk.name = t(j.name)
sk.originalName = t(j.name)
sk.type = t(j.type)
sk.import = t(j.level)
if (sk.level == 0) sk.level = ''
Expand Down Expand Up @@ -807,6 +809,7 @@ export class ActorImporter {
let j = json[key]
let sp = new Spell()
sp.name = t(j.name)
sp.originalName = t(j.name)
sp.class = t(j.class)
sp.college = t(j.college)
let cm = t(j.costmaintain)
Expand Down Expand Up @@ -869,6 +872,7 @@ export class ActorImporter {
let j2 = j.meleemodelist[k2]
let m = new Melee()
m.name = t(j.name)
m.originalName = t(j.name)
m.st = t(j.st)
m.weight = t(j.weight)
m.techlevel = t(j.tl)
Expand Down Expand Up @@ -916,6 +920,7 @@ export class ActorImporter {
let j2 = j.rangedmodelist[k2]
let r = new Ranged()
r.name = t(j.name)
r.originalName = t(j.name)
r.st = t(j.st)
r.bulk = t(j.bulk)
r.legalityclass = t(j.lc)
Expand Down Expand Up @@ -1057,6 +1062,7 @@ export class ActorImporter {
let parentuuid = t(j.parentuuid)
let eqt = new Equipment()
eqt.name = name
eqt.originalName = t(j.name)
eqt.count = t(j.count)
eqt.cost = !!parentuuid ? t(j.cost) : 0
eqt.location = t(j.location)
Expand Down Expand Up @@ -1678,6 +1684,7 @@ export class ActorImporter {
i.type = i.id.startsWith('t') ? 'trait' : 'trait_container'
}
a.name = i.name + (i.levels ? ' ' + i.levels.toString() : '') || 'Trait'
a.originalName = i.name
a.points = i.calc?.points
a.notes = i.calc?.resolved_notes ?? i.notes ?? ''
a.userdesc = i.userdesc
Expand Down Expand Up @@ -1753,6 +1760,7 @@ export class ActorImporter {
name += addition + ')'
}
let s = new Skill(name, '')
s.originalName = i.name
s.pageRef(i.reference || '')
s.uuid = i.id
s.parentuuid = p
Expand Down Expand Up @@ -1811,6 +1819,7 @@ export class ActorImporter {
i.type = i.id.startsWith('r') ? 'ritual_magic_spell' : i.id.startsWith('p') ? 'spell' : 'spell_container'
}
s.name = i.name || 'Spell'
s.originalName = i.name
s.uuid = i.id
s.parentuuid = p
s.pageRef(i.reference || '')
Expand Down Expand Up @@ -1921,6 +1930,7 @@ export class ActorImporter {
i.type = i.id.startsWith('e') ? 'equipment' : 'equipment_container'
}
e.name = i.description || 'Equipment'
e.originalName = i.description
e.count = i.type == 'equipment_container' ? '1' : i.quantity || '0'
e.cost =
(parseFloat(i.calc?.extended_value) / (i.type == 'equipment_container' ? 1 : i.quantity || 1)).toString() || ''
Expand Down Expand Up @@ -2291,6 +2301,7 @@ export class ActorImporter {
if (w.type == 'melee_weapon') {
let m = new Melee()
m.name = i.name || i.description || ''
m.originalName = i.name
m.st = w.strength || ''
m.weight = i.weight || ''
m.techlevel = i.tech_level || ''
Expand All @@ -2311,6 +2322,7 @@ export class ActorImporter {
} else if (w.type == 'ranged_weapon') {
let r = new Ranged()
r.name = i.name || i.description || ''
r.originalName = i.name
r.st = w.strength || ''
r.bulk = w.bulk || ''
r.legalityclass = i.legality_class || '4'
Expand Down
24 changes: 24 additions & 0 deletions module/actor/actor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,4 +2314,28 @@ export class GurpsActor extends Actor {
}
return canEdit
}

/**
* Executes a GURPS action parsed from a given OTF string.
*
* This is intended for external libraries like Argon Combat HUD.
*
* @param {string} otf - The On-The-Fly (OTF) string representing the action to be performed.
* @return {Promise<void>} A promise that resolves once the action has been performed.
*/
async runOTF(otf) {
const action = parselink(otf)
await GURPS.performAction(action.action, this)
}

/**
* Retrieves the value of the 'usingQuintessence' setting from the game settings.
*
* This is intended for external libraries like Argon Combat HUD.
*
* @return {boolean} The value of the 'usingQuintessence' setting.
*/
get usingQuintessence() {
return game.settings.get(Settings.SYSTEM_NAME, Settings.SETTING_USE_QUINTESSENCE)
}
}
51 changes: 51 additions & 0 deletions module/item.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { recurselist } from '../lib/utilities.js'

export class GurpsItem extends Item {
/**
* @param {Item} item
Expand All @@ -11,6 +13,55 @@ export class GurpsItem extends Item {
super.prepareData()
}

/**
* Return Item Attacks from melee and ranged Actor Components
*
* This is intended for external libraries like Argon Combat HUD,
* but can be used anytime you have only the Item UUID and need
* to know if this Item has any Melee or Ranged attacks registered
* on Actor System.
*
* Because GCA import did not populate the `uuid` field on these Actor Components
* we need to compare the Item original name for both Item and Component.
*
* @param getAttOptions
* @returns {*[]|boolean}
*/
getItemAttacks(getAttOptions = {}) {
const { attackType = 'both', checkOnly = false } = getAttOptions
const originalName = this.system[this.itemSysKey].originalName
const currentName = this.system[this.itemSysKey].name
const actorComponentUUID = this.system[this.itemSysKey].uuid
// Look at Melee and Ranged attacks in actor.system
let attacks = []
let attackTypes = ['melee', 'ranged']
if (attackType !== 'both') attackTypes = [attackType]
for (let at of attackTypes) {
recurselist(this.actor.system[at], (e, _k, _d) => {
let key = undefined
if (!!actorComponentUUID && e.uuid === actorComponentUUID) {
key = this.actor._findSysKeyForId('uuid', e.uuid, at)
} else if (!!originalName && e.originalName === originalName) {
key = this.actor._findSysKeyForId('originalName', e.originalName, at)
} else if (!!currentName && e.name === currentName) {
key = this.actor._findSysKeyForId('name', e.name, at)
}
if (!!key) {
attacks.push({
component: e,
key,
})
}
})
}
if (!!checkOnly) return !!attacks.length > 0
return attacks
}

get hasAttacks() {
return !!this.getItemAttacks({ checkOnly: true })
}

async internalUpdate(data, context) {
let ctx = { render: !this.ignoreRender }
if (!!context) ctx = { ...context, ...ctx }
Expand Down
Loading

0 comments on commit 36b5ad7

Please sign in to comment.