From d1ce14411476467e72af104e6fc5514142206dc8 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Fri, 17 Jan 2025 19:24:53 -0700 Subject: [PATCH] RC-106 | Add equipped armour display --- module/Apps/ActorSheets/HeroSummaryCardV1.mjs | 15 +++++++++ module/data/Actor/Hero.mjs | 33 +++++++++++++++++++ module/data/Item/Armour.mjs | 5 +++ templates/Apps/HeroSummaryCardV1/content.hbs | 4 +++ templates/Apps/HeroSummaryCardV1/style.css | 10 ++++++ 5 files changed, 67 insertions(+) diff --git a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs index 888ae4d..434846e 100644 --- a/module/Apps/ActorSheets/HeroSummaryCardV1.mjs +++ b/module/Apps/ActorSheets/HeroSummaryCardV1.mjs @@ -72,6 +72,7 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi ctx = await HeroSummaryCardV1.prepareGuts(ctx); ctx = await HeroSummaryCardV1.prepareWeapons(ctx); + ctx = await HeroSummaryCardV1.prepareArmor(ctx); ctx = await HeroSummaryCardV1.prepareFatePath(ctx); ctx = await HeroSummaryCardV1.prepareAbilityRow(ctx); ctx = await HeroSummaryCardV1.prepareSpeed(ctx); @@ -136,6 +137,20 @@ export class HeroSummaryCardV1 extends GenericAppMixin(HandlebarsApplicationMixi return ctx; }; + static async prepareArmor(ctx) { + ctx.armours = {}; + const equipped = ctx.actor.system.equippedArmour; + for (const slot of gameTerms.Anatomy) { + const item = equipped[slot]; + ctx.armours[slot] = { + name: item?.name ?? ``, + uuid: item?.uuid ?? ``, + defense: 0, + }; + }; + return ctx; + }; + static async prepareWeapons(ctx) { const limit = ctx.actor.system.limit.weapons; const embedded = ctx.actor.itemTypes.weapon; diff --git a/module/data/Actor/Hero.mjs b/module/data/Actor/Hero.mjs index b38d26b..0521699 100644 --- a/module/data/Actor/Hero.mjs +++ b/module/data/Actor/Hero.mjs @@ -147,4 +147,37 @@ export class HeroData extends foundry.abstract.TypeDataModel { run: (this.ability.gait + 3) * 2, }; }; + + // #region Getters + get equippedArmour() { + const armours = this.parent.itemTypes.armour; + const slots = Object.fromEntries( + gameTerms.Anatomy.map(v => [v, null]), + ); + for (const armour of armours) { + if (!armour.system.equipped) { continue }; + for (const locationTag of [...armour.system.location.values()]) { + const location = locationTag.toLowerCase(); + slots[location] = armour; + }; + }; + return slots; + }; + + get equippedShield() { + return null; + }; + + get defense() { + const defenses = {}; + const armour = this.equippedArmour; + for (const slot in armour) { + defenses[slot] = armour[slot]?.system.protection ?? 0; + }; + + // TODO: add shield defenses + + return defenses; + }; + // #endregion }; diff --git a/module/data/Item/Armour.mjs b/module/data/Item/Armour.mjs index 2bcc23c..b12e969 100644 --- a/module/data/Item/Armour.mjs +++ b/module/data/Item/Armour.mjs @@ -20,6 +20,11 @@ export class ArmourData extends foundry.abstract.TypeDataModel { required: true, }, ), + equipped: new fields.BooleanField({ + initial: false, + required: true, + nullable: false, + }), }; }; diff --git a/templates/Apps/HeroSummaryCardV1/content.hbs b/templates/Apps/HeroSummaryCardV1/content.hbs index 66058a4..2c0ab0b 100644 --- a/templates/Apps/HeroSummaryCardV1/content.hbs +++ b/templates/Apps/HeroSummaryCardV1/content.hbs @@ -54,15 +54,19 @@