Merge branch '009-templateTypes' into 'master'

Create types for items.

Closes #9

See merge request dungeonslayers/ds4!3
This commit is contained in:
Johannes Loher 2020-12-28 19:35:27 +01:00
commit bdae6b2f2f
4 changed files with 49 additions and 13 deletions

View file

@ -49,7 +49,7 @@ export const DS4 = {
*/ */
armorTypes: { armorTypes: {
body: "DS4.ArmorTypeBody", body: "DS4.ArmorTypeBody",
helment: "DS4.ArmorTypeHelmet", helmet: "DS4.ArmorTypeHelmet",
vambrace: "DS4.ArmorTypeVambrace", vambrace: "DS4.ArmorTypeVambrace",
greaves: "DS4.ArmorTypeGreaves", greaves: "DS4.ArmorTypeGreaves",
vambraceGreaves: "DS4.ArmorTypeVambraceGreaves", vambraceGreaves: "DS4.ArmorTypeVambraceGreaves",

View file

@ -1,2 +1,38 @@
// TODO: Actually add a type for data // 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; 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"); const li = $(ev.currentTarget).parents(".effect");
console.log(li.data("effectId")); 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")); // TODO: replace ["..."]
effect.sheet.render(true); 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"); const li = $(ev.currentTarget).parents(".effect");
await this.item.deleteEmbeddedEntity("ActiveEffect", li.data("effectId")); 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 * @param {Event} event The originating click event
* @private * @private
*/ */
async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> { private async _onEffectCreate(event: JQuery.ClickEvent): Promise<unknown> {
event.preventDefault(); event.preventDefault();
const label = `New Effect`; const label = `New Effect`;

View file

@ -50,24 +50,24 @@
}, },
"equipable": { "equipable": {
"equipped": false "equipped": false
},
"protective": {
"armorValue": 0
} }
}, },
"weapon": { "weapon": {
"templates": ["base", "physical", "equipable"], "templates": ["base", "physical", "equipable"],
"attackType": "melee", "attackType": "melee",
"weaponBonus": 0, "weaponBonus": 0,
"opponentDefense": 0, "opponentDefense": 0
"properties": {}
}, },
"armor": { "armor": {
"templates": ["base", "physical", "equipable"], "templates": ["base", "physical", "equipable", "protective"],
"armorMaterialType": "cloth", "armorMaterialType": "cloth",
"armorType": "body", "armorType": "body"
"armorValue": 0
}, },
"shield": { "shield": {
"templates": ["base", "physical", "equipable"], "templates": ["base", "physical", "equipable", "protective"]
"armorValue": 0
}, },
"trinket": { "trinket": {
"templates": ["base", "physical", "equipable"] "templates": ["base", "physical", "equipable"]