Create types for items.

This commit is contained in:
Oliver Rümpelein 2020-12-28 18:24:13 +01:00
parent a84df2d80b
commit 1ef66a2023
4 changed files with 50 additions and 14 deletions

View file

@ -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",

View file

@ -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;
}

View file

@ -54,16 +54,16 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
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<DS4ItemDataType, DS4Item> {
* @param {Event} event The originating click event
* @private
*/
async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> {
private async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> {
event.preventDefault();
const label = `New Effect`;

View file

@ -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"]