diff --git a/src/lang/en.json b/src/lang/en.json index d522bf1..6eea01c 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -44,6 +44,7 @@ "WJMAIS.Hardpoints": "Hardpoints", "WJMAIS.LandingTypes": "Landing Types", + "WJMAIS.TraitLandingTypesPlural.other": "Landing Types", "WJMAIS.LandingLand": "Land", "WJMAIS.LandingWater": "Water", "WJMAIS.LandingSpaceDock": "Space Dock", diff --git a/src/module/patch.js b/src/module/patch.js index 6dbb3c1..b52207c 100644 --- a/src/module/patch.js +++ b/src/module/patch.js @@ -126,8 +126,25 @@ function patchRollData() { ); } +function patchPrepareData() { + libWrapper.register( + "wjmais", + "game.dnd5e.documents.Actor5e.prototype.prepareData", + function (wrapped, ...args) { + if (this.flags?.wjmais?.traits?.lt?.value) + this.flags.wjmais.traits.lt.value = new Set( + this.flags.wjmais.traits.lt.value + ); + + return wrapped(...args); + }, + "MIXED" + ); +} + export function applyPatches() { patchCompendiumImport(); patchResourceBars(); patchRollData(); + patchPrepareData(); } diff --git a/src/module/wildjammer-sheet.js b/src/module/wildjammer-sheet.js index ba820fe..5917524 100644 --- a/src/module/wildjammer-sheet.js +++ b/src/module/wildjammer-sheet.js @@ -190,34 +190,38 @@ export default class WildjammerSheet extends dnd5e.applications.actor } /** - * Prepare the data structure for traits data like languages, resistances & vulnerabilities, and proficiencies - * @param {object} traits The raw traits data object from the actor data - * @private + * Prepare the data structure for traits data like languages, resistances & vulnerabilities, and proficiencies. + * @param {object} systemData System data for the Actor being prepared. + * @returns {object} Prepared trait data. + * @protected */ - _prepareTraits(traits) { - const map = { - lt: CONFIG.WJMAIS.landingTypes, - }; - for (let [t, choices] of Object.entries(map)) { - if (!traits) break; - const trait = traits[t]; - if (!trait) continue; - let values = []; - if (trait.value) { - values = trait.value instanceof Array ? trait.value : [trait.value]; - } - trait.selected = values.reduce((obj, t) => { - obj[t] = choices[t]; - return obj; - }, {}); - // Add custom entry - if (trait.custom) { - trait.custom - .split(";") - .forEach((c, i) => (trait.selected[`custom${i + 1}`] = c.trim())); - } - trait.cssClass = !foundry.utils.isEmpty(trait.selected) ? "" : "inactive"; - } + _prepareTraits(systemData) { + let traits = super._prepareTraits(systemData); + const flagData = this.actor.flags.wjmais; + const key = "traits.lt"; + const data = foundry.utils.deepClone( + foundry.utils.getProperty(flagData, key) + ); + foundry.utils.setProperty(traits, key, data); + + let values = data.value; + if (!values) values = []; + else if (values instanceof Set) values = Array.from(values); + else if (!Array.isArray(values)) values = [values]; + + data.selected = values.reduce((obj, key) => { + obj[key] = CONFIG.WJMAIS.landingTypes[key]; + return obj; + }, {}); + + // Add custom entries + if (data.custom) + data.custom + .split(";") + .forEach((c, i) => (data.selected[`custom${i + 1}`] = c.trim())); + data.cssClass = !foundry.utils.isEmpty(data.selected) ? "" : "inactive"; + + return traits; } async getData(options) { @@ -989,6 +993,10 @@ export default class WildjammerSheet extends dnd5e.applications.actor choices, allowCustom: false, }; - new dnd5e.applications.TraitSelector(this.actor, options).render(true); + new dnd5e.applications.actor.TraitSelector( + this.actor, + "lt", + options + ).render(true); } } diff --git a/src/module/wjmais.js b/src/module/wjmais.js index 45b3ba6..b253d25 100644 --- a/src/module/wjmais.js +++ b/src/module/wjmais.js @@ -51,6 +51,16 @@ function configProperties() { formula: "10 + @ship.ac.mod", }; + CONFIG.DND5E.lt = CONFIG.WJMAIS.landingTypes; + CONFIG.DND5E.traits.lt = { + actorKeyPath: "flags.wjmais.traits.lt", + labels: { + title: "Landing Types", + localization: "WJMAIS.TraitLandingTypesPlural", + }, + icon: "systems/dnd5e/icons/svg/trait-languages.svg", + }; + foundry.utils.mergeObject( globalThis.game.dnd5e.config.equipmentTypes, translateObject({ diff --git a/src/templates/actors/wildjammer.html b/src/templates/actors/wildjammer.html index f918311..259882d 100644 --- a/src/templates/actors/wildjammer.html +++ b/src/templates/actors/wildjammer.html @@ -171,13 +171,14 @@