From aa5c6d5aba652e055b571783f966d733f98830d2 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Wed, 20 Mar 2024 17:56:41 -0600 Subject: [PATCH] Improve how capacity consumption calculations are performed --- module/documents/Item/GenericItem.mjs | 13 ++++++++++++- module/documents/Item/Material.mjs | 9 +++++++++ module/documents/Item/_proxy.mjs | 2 ++ module/models/Item/CommonItemData.mjs | 4 ++++ module/settings/world_settings.mjs | 10 ++++++++++ module/sheets/Actors/PC/PlayerSheetV2.mjs | 2 +- 6 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 module/documents/Item/Material.mjs diff --git a/module/documents/Item/GenericItem.mjs b/module/documents/Item/GenericItem.mjs index 1869073..d015404 100644 --- a/module/documents/Item/GenericItem.mjs +++ b/module/documents/Item/GenericItem.mjs @@ -1 +1,12 @@ -export class DotDungeonItem extends Item {}; +export class DotDungeonItem extends Item { + get usedCapacity() { + let capacity = 0; + if (this.system.uses_inventory_slot && this.system.quantity > 0) { + capacity++; + }; + if (this.system.quantity_affects_used_capacity) { + capacity *= this.system.quantity; + }; + return capacity; + }; +}; diff --git a/module/documents/Item/Material.mjs b/module/documents/Item/Material.mjs new file mode 100644 index 0000000..ee0fbed --- /dev/null +++ b/module/documents/Item/Material.mjs @@ -0,0 +1,9 @@ +import { DotDungeonItem } from "./GenericItem.mjs"; + +export class Material extends DotDungeonItem { + get usedCapacity() { + let affects = game.settings.get(`dotdungeon`, `materialsAffectCapacity`); + console.log(`materialsAffectCapacity =`, affects) + return affects ? super.usedCapacity : 0; + }; +}; diff --git a/module/documents/Item/_proxy.mjs b/module/documents/Item/_proxy.mjs index 2ab6d4f..b579136 100644 --- a/module/documents/Item/_proxy.mjs +++ b/module/documents/Item/_proxy.mjs @@ -1,8 +1,10 @@ import { DotDungeonItem } from "./GenericItem.mjs"; import { Aspect } from "./Aspect.mjs"; +import { Material } from "./Material.mjs"; const classes = { aspect: Aspect, + material: Material, }; const defaultClass = DotDungeonItem; diff --git a/module/models/Item/CommonItemData.mjs b/module/models/Item/CommonItemData.mjs index dd1e85a..e926b44 100644 --- a/module/models/Item/CommonItemData.mjs +++ b/module/models/Item/CommonItemData.mjs @@ -14,6 +14,10 @@ export class CommonItemData extends foundry.abstract.TypeDataModel { initial: true, nullable: false, }), + quantity_affects_used_capacity: new fields.BooleanField({ + initial: true, + nullable: false, + }), buy: new fields.NumberField({ initial: null, nullable: true, diff --git a/module/settings/world_settings.mjs b/module/settings/world_settings.mjs index a8a3e02..cac1757 100644 --- a/module/settings/world_settings.mjs +++ b/module/settings/world_settings.mjs @@ -9,6 +9,16 @@ export default function() { requiresReload: false, }); + game.settings.register(`dotdungeon`, `materialsAffectCapacity`, { + name: `dotdungeon.settings.materialsAffectCapacity.name`, + hint: `dotdungeon.settings.materialsAffectCapacity.description`, + scope: `world`, + config: true, + type: Boolean, + default: true, + requiresReload: false, + }); + game.settings.register(`dotdungeon`, `resourcesOrSupplies`, { name: `dotdungeon.settings.resourcesOrSupplies.name`, hint: `dotdungeon.settings.resourcesOrSupplies.description`, diff --git a/module/sheets/Actors/PC/PlayerSheetV2.mjs b/module/sheets/Actors/PC/PlayerSheetV2.mjs index c9fc1be..05de19e 100644 --- a/module/sheets/Actors/PC/PlayerSheetV2.mjs +++ b/module/sheets/Actors/PC/PlayerSheetV2.mjs @@ -144,7 +144,7 @@ export class PlayerSheetv2 extends GenericActorSheet { get #inventoryCapacity() { return { used: this.actor.items - .reduce((sum, i) => sum + (i.system.uses_inventory_slot ? i.system.quantity : 0), 0), + .reduce((sum, i) => sum + i.usedCapacity, 0), max: this.actor.system.inventory_slots, }; };