From 1ef66a202312ab322ea1e71d415557eab0d523db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20R=C3=BCmpelein?= Date: Mon, 28 Dec 2020 18:24:13 +0100 Subject: [PATCH] Create types for items. --- src/module/config.ts | 2 +- src/module/item/item-data.ts | 38 ++++++++++++++++++++++++++++++++++- src/module/item/item-sheet.ts | 10 ++++----- src/template.json | 14 ++++++------- 4 files changed, 50 insertions(+), 14 deletions(-) diff --git a/src/module/config.ts b/src/module/config.ts index 777c6a6b..09bcfe5a 100644 --- a/src/module/config.ts +++ b/src/module/config.ts @@ -49,7 +49,7 @@ export const DS4 = { */ armorTypes: { body: "DS4.ArmorTypeBody", - helment: "DS4.ArmorTypeHelmet", + helmet: "DS4.ArmorTypeHelmet", vambrace: "DS4.ArmorTypeVambrace", greaves: "DS4.ArmorTypeGreaves", vambraceGreaves: "DS4.ArmorTypeVambraceGreaves", diff --git a/src/module/item/item-data.ts b/src/module/item/item-data.ts index 7cdfd20b..fed78643 100644 --- a/src/module/item/item-data.ts +++ b/src/module/item/item-data.ts @@ -1,2 +1,38 @@ // TODO: Actually add a type for data -export type DS4ItemDataType = unknown; +export type DS4ItemDataType = DS4Weapon | DS4Armor | DS4Shield | DS4Trinket | DS4Equipment; + +// types + +interface DS4Weapon extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable { + attackType: "melee" | "ranged" | "meleeRanged"; + weaponBonus: number; + opponentDefense: number; +} + +interface DS4Armor extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective { + armorMaterialType: "cloth" | "leather" | "chain" | "plate"; + armorType: "body" | "helmet" | "vambrace" | "greaves" | "vambraceGreaves"; +} + +interface DS4Shield extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable, DS4ItemProtective {} +interface DS4Trinket extends DS4ItemBase, DS4ItemPhysical, DS4ItemEquipable {} +interface DS4Equipment extends DS4ItemBase, DS4ItemPhysical {} + +// templates + +interface DS4ItemBase { + description: string; +} +interface DS4ItemPhysical { + quantity: number; + price: number; + availability: "hamlet" | "village" | "city" | "elves" | "dwarves" | "none"; +} + +interface DS4ItemEquipable { + equipped: boolean; +} + +interface DS4ItemProtective { + armorValue: number; +} diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts index f6e95420..27fb6a92 100644 --- a/src/module/item/item-sheet.ts +++ b/src/module/item/item-sheet.ts @@ -54,16 +54,16 @@ export class DS4ItemSheet extends ItemSheet { if (!this.options.editable) return; - html.find(".effect-create").click(this._onEffectCreate.bind(this)); + html.find(".effect-create").on("click", this._onEffectCreate.bind(this)); - html.find(".effect-edit").click((ev) => { + html.find(".effect-edit").on("click", (ev) => { const li = $(ev.currentTarget).parents(".effect"); console.log(li.data("effectId")); - const effect = this.item["effects"].get(li.data("effectId")); // TODO: replace ["..."] + const effect = this.item["effects"].get(li.data("effectId")); // effect.sheet.render(true); }); - html.find(".effect-delete").click(async (ev) => { + html.find(".effect-delete").on("click", async (ev) => { const li = $(ev.currentTarget).parents(".effect"); await this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId")); }); @@ -74,7 +74,7 @@ export class DS4ItemSheet extends ItemSheet { * @param {Event} event The originating click event * @private */ - async _onEffectCreate(event: JQuery.ClickEvent): Promise { + private async _onEffectCreate(event: JQuery.ClickEvent): Promise { event.preventDefault(); const label = `New Effect`; diff --git a/src/template.json b/src/template.json index 196d74a8..f81bd603 100644 --- a/src/template.json +++ b/src/template.json @@ -50,24 +50,24 @@ }, "equipable": { "equipped": false + }, + "protective": { + "armorValue": 0 } }, "weapon": { "templates": ["base", "physical", "equipable"], "attackType": "melee", "weaponBonus": 0, - "opponentDefense": 0, - "properties": {} + "opponentDefense": 0 }, "armor": { - "templates": ["base", "physical", "equipable"], + "templates": ["base", "physical", "equipable", "protective"], "armorMaterialType": "cloth", - "armorType": "body", - "armorValue": 0 + "armorType": "body" }, "shield": { - "templates": ["base", "physical", "equipable"], - "armorValue": 0 + "templates": ["base", "physical", "equipable", "protective"] }, "trinket": { "templates": ["base", "physical", "equipable"]