diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 63ec0fcd..3dd1bfb5 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -24,6 +24,7 @@ export class DS4ActorSheet extends ActorSheet { for (let attr of Object.values(data.data.attributes)) { attr.isCheckbox = attr.dtype === "Boolean"; } + console.log(data); return data; } diff --git a/module/actor/actor.js b/module/actor/actor.js index ea94e0df..c14d8560 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -3,35 +3,36 @@ * @extends {Actor} */ export class DS4Actor extends Actor { - - /** - * Augment the basic actor data with additional dynamic data. - */ - prepareData() { - super.prepareData(); - - const actorData = this.data; - const data = actorData.data; - const flags = actorData.flags; - - // Make separate methods for each Actor type (character, npc, etc.) to keep - // things organized. - if (actorData.type === 'character') this._prepareCharacterData(actorData); + /** @override */ + prepareDerivedData() { + const data = this.data; + this._prepareCombatValues(data); } - /** - * Prepare Character type specific data - */ - _prepareCharacterData(actorData) { - const data = actorData.data; + _prepareCombatValues(data) { + const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0; + setProperty( + data, + "data.combatValues.hitPoints.max", + data.data.attributes.body.initial + data.data.traits.constitution.initial + 10 + hitPointsModifier + ); - // Make modifications to data here. For example: - - // Loop through ability scores, and add their modifiers to our sheet output. - for (let [key, ability] of Object.entries(data.abilities)) { - // Calculate the modifier using d20 rules. - ability.mod = Math.floor((ability.value - 10) / 2); - } + const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0; + setProperty( + data, + "data.combatValues.defense.value", + data.data.attributes.body.initial + + data.data.traits.constitution.initial + + this._getArmorValue() + + defenseModifier + ); } -} \ No newline at end of file + _getArmorValue() { + return this.data.items + .filter((item) => ["armor", "shield"].includes(item.type)) + .filter((item) => item.data.equipped) + .map((item) => item.data.armorValue) + .reduce((a, b) => a + b, 0); + } +} diff --git a/module/item/item-sheet.js b/module/item/item-sheet.js index e2d09acc..24fb5d67 100644 --- a/module/item/item-sheet.js +++ b/module/item/item-sheet.js @@ -47,9 +47,41 @@ export class DS4ItemSheet extends ItemSheet { activateListeners(html) { super.activateListeners(html); - // Everything below here is only needed if the sheet is editable if (!this.options.editable) return; - // Roll handlers, click handlers, etc. would go here. + html.find(".effect-create").click(this._onEffectCreate.bind(this)); + + html.find(".effect-edit").click((ev) => { + const li = $(ev.currentTarget).parents(".effect"); + console.log(li.data("effectId")); + const effect = this.item.effects.get(li.data("effectId")); + effect.sheet.render(true); + }); + + html.find(".effect-delete").click(async (ev) => { + const li = $(ev.currentTarget).parents(".effect"); + await this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId")); + }); + } + + /** + * Handle creating a new ActiveEffect for the item using initial data defined in the HTML dataset + * @param {Event} event The originating click event + * @private + */ + async _onEffectCreate(event) { + event.preventDefault(); + + const label = `New Effect`; + + const createData = { + label: label, + changes: [], + duration: {}, + transfer: true, + }; + + const effect = ActiveEffect.create(createData, this.item); + return effect.create(); } } diff --git a/template.json b/template.json index d528720f..6bfe0639 100644 --- a/template.json +++ b/template.json @@ -1,46 +1,38 @@ { "Actor": { "types": ["character"], - "templates": { - "base": { - "health": { - "value": 10, - "min": 0, - "max": 10 - }, - "power": { - "value": 5, - "min": 0, - "max": 5 - } - } - }, + "templates": {}, "character": { - "templates": ["base"], - "biography": "", + "templates": [], "attributes": { - "level": { - "value": 1 + "body": { + "initial": 8 + }, + "mobility": { + "initial": 0 + }, + "mind": { + "initial": 0 } }, - "abilities": { - "str": { - "value": 10 + "traits": { + "strength": { + "initial": 4 }, - "dex": { - "value": 10 + "constitution": { + "initial": 0 }, - "con": { - "value": 10 + "agility": { + "initial": 0 }, - "int": { - "value": 10 + "dexterity": { + "initial": 0 }, - "wis": { - "value": 10 + "intellect": { + "initial": 0 }, - "cha": { - "value": 10 + "aura": { + "initial": 0 } } } diff --git a/templates/actor/actor-sheet.html b/templates/actor/actor-sheet.html index 09201083..ec1ab311 100644 --- a/templates/actor/actor-sheet.html +++ b/templates/actor/actor-sheet.html @@ -65,7 +65,7 @@