diff --git a/package-lock.json b/package-lock.json index 4bf17502..f9b1dfbe 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2678,7 +2678,7 @@ } }, "foundry-pc-types": { - "version": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#a94b1270e74d5e139c7c5d361764d9b0bc505c6f", + "version": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#211c36bdde13400f02421dc0f911b255767dac76", "from": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#f3l-fixes", "dev": true, "requires": { diff --git a/src/module/actor/actor-data.ts b/src/module/actor/actor-data.ts index d6575c24..93bb7883 100644 --- a/src/module/actor/actor-data.ts +++ b/src/module/actor/actor-data.ts @@ -1,2 +1,26 @@ -// TODO: Actually add a type for data -export type DS4ActorDataType = unknown; +export interface DS4ActorDataType { + attributes: DS4ActorDataAttributes; + traits: DS4ActorDataTraits; +} + +interface DS4ActorDataAttributes { + body: BodyAttribute; + mobility: ExtensibleData; + mind: ExtensibleData; +} + +interface ExtensibleData { + initial: T; +} + +// Blueprint in case we need more detailed differentiation +type BodyAttribute = ExtensibleData; + +interface DS4ActorDataTraits { + strength: ExtensibleData; + constitution: ExtensibleData; + agility: ExtensibleData; + dexterity: ExtensibleData; + intellect: ExtensibleData; + aura: ExtensibleData; +} diff --git a/src/module/actor/actor-sheet.ts b/src/module/actor/actor-sheet.ts index 4a16bfa7..43af361c 100644 --- a/src/module/actor/actor-sheet.ts +++ b/src/module/actor/actor-sheet.ts @@ -19,18 +19,6 @@ export class DS4ActorSheet extends ActorSheet { /* -------------------------------------------- */ - /** @override */ - getData(): ActorSheetData { - // TODO: replace ["..."] access with . - const data = super.getData(); - data["dtypes"] = ["String", "Number", "Boolean"]; - for (const attr of Object.values(data.data["attributes"])) { - attr["isCheckbox"] = attr["dtype"] === "Boolean"; - } - console.log(data); - return data; - } - /** @override */ activateListeners(html: JQuery): void { super.activateListeners(html); @@ -39,17 +27,17 @@ export class DS4ActorSheet extends ActorSheet { if (!this.options.editable) return; // Add Inventory Item - html.find(".item-create").click(this._onItemCreate.bind(this)); + html.find(".item-create").on("click", this._onItemCreate.bind(this)); // Update Inventory Item - html.find(".item-edit").click((ev) => { + html.find(".item-edit").on("click", (ev) => { const li = $(ev.currentTarget).parents(".item"); const item = this.actor.getOwnedItem(li.data("itemId")); item.sheet.render(true); }); // Delete Inventory Item - html.find(".item-delete").click((ev) => { + html.find(".item-delete").on("click", (ev) => { const li = $(ev.currentTarget).parents(".item"); this.actor.deleteOwnedItem(li.data("itemId")); li.slideUp(200, () => this.render(false)); @@ -66,7 +54,7 @@ export class DS4ActorSheet extends ActorSheet { * @param {Event} event The originating click event * @private */ - _onItemCreate(event: JQuery.ClickEvent): Promise { + private _onItemCreate(event: JQuery.ClickEvent): Promise { event.preventDefault(); const header = event.currentTarget; // Get the type of item to create. @@ -93,13 +81,13 @@ export class DS4ActorSheet extends ActorSheet { * @param {Event} event The originating click event * @private */ - _onRoll(event: JQuery.ClickEvent): void { + private _onRoll(event: JQuery.ClickEvent): void { event.preventDefault(); const element = event.currentTarget; const dataset = element.dataset; if (dataset.roll) { - const roll = new Roll(dataset.roll, this.actor.data.data as Record); + const roll = new Roll(dataset.roll, this.actor.data.data); const label = dataset.label ? `Rolling ${dataset.label}` : ""; roll.roll().toMessage({ speaker: ChatMessage.getSpeaker({ actor: this.actor }), diff --git a/src/module/actor/actor.ts b/src/module/actor/actor.ts index 38292ed7..5f67e96e 100644 --- a/src/module/actor/actor.ts +++ b/src/module/actor/actor.ts @@ -11,29 +11,27 @@ export class DS4Actor extends Actor { this._prepareCombatValues(data); } - _prepareCombatValues(data: ActorData): void { + private _prepareCombatValues(data: ActorData): void { const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0; + const actorData = data.data; setProperty( data, "data.combatValues.hitPoints.max", - data.data["attributes"]["body"].initial + // TODO: replace ["..."] - data.data["traits"]["constitution"].initial + // TODO: replace ["..."] - 10 + - hitPointsModifier, + actorData.attributes.body.initial + actorData.traits.constitution.initial + 10 + hitPointsModifier, ); const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0; setProperty( data, "data.combatValues.defense.value", - data.data["attributes"]["body"].initial + // TODO: replace ["..."] - data.data["traits"]["constitution"].initial + // TODO: replace ["..."] + actorData.attributes.body.initial + + actorData.traits.constitution.initial + this._getArmorValue() + defenseModifier, ); } - _getArmorValue(): number { + private _getArmorValue(): number { return this.data["items"] .filter((item) => ["armor", "shield"].includes(item.type)) .filter((item) => item.data.equipped) diff --git a/src/module/config.ts b/src/module/config.ts index 4c7b53df..777c6a6b 100644 --- a/src/module/config.ts +++ b/src/module/config.ts @@ -1,11 +1,11 @@ export const DS4 = { // ASCII Artwork - ASCII: `_____________________________________________________________________________________________ - ____ _ _ _ _ ____ _____ ___ _ _ ____ _ _ __ _______ ____ ____ _ _ -| _ \\| | | | \\ | |/ ___| ____/ _ \\| \\ | / ___|| | / \\\\ \\ / / ____| _ \\/ ___| | || | -| | | | | | | \\| | | _| _|| | | | \\| \\___ \\| | / _ \\\\ V /| _| | |_) \\___ \\ | || |_ -| |_| | |_| | |\\ | |_| | |__| |_| | |\\ |___) | |___ / ___ \\| | | |___| _ < ___) | |__ _| -|____/ \\___/|_| \\_|\\____|_____\\___/|_| \\_|____/|_____/_/ \\_\\_| |_____|_| \\_\\____/ |_| + ASCII: String.raw`_____________________________________________________________________________________________ + ____ _ _ _ _ ____ _____ ___ _ _ ____ _ _ __ _______ ____ ____ _ _ +| _ \| | | | \ | |/ ___| ____/ _ \| \ | / ___|| | / \\ \ / / ____| _ \/ ___| | || | +| | | | | | | \| | | _| _|| | | | \| \___ \| | / _ \\ V /| _| | |_) \___ \ | || |_ +| |_| | |_| | |\ | |_| | |__| |_| | |\ |___) | |___ / ___ \| | | |___| _ < ___) | |__ _| +|____/ \___/|_| \_|\____|_____\___/|_| \_|____/|_____/_/ \_\_| |_____|_| \_\____/ |_| =============================================================================================`, /** diff --git a/src/module/ds4.ts b/src/module/ds4.ts index bd76905c..002e9314 100644 --- a/src/module/ds4.ts +++ b/src/module/ds4.ts @@ -18,8 +18,8 @@ Hooks.once("init", async function () { CONFIG.DS4 = DS4; // Define custom Entity classes - CONFIG.Actor.entityClass = DS4Actor as typeof Actor; // TODO: Can we remove the casts? - CONFIG.Item.entityClass = DS4Item as typeof Item; // TODO: Can we remove the casts? + CONFIG.Actor.entityClass = DS4Actor as typeof Actor; + CONFIG.Item.entityClass = DS4Item as typeof Item; // Register sheet application classes Actors.unregisterSheet("core", ActorSheet); diff --git a/src/module/item/item-sheet.ts b/src/module/item/item-sheet.ts index d9258449..f6e95420 100644 --- a/src/module/item/item-sheet.ts +++ b/src/module/item/item-sheet.ts @@ -1,4 +1,3 @@ -import { DS4ActorDataType } from "../actor/actor-data"; import { DS4Item } from "./item"; import { DS4ItemDataType } from "./item-data"; @@ -6,7 +5,7 @@ import { DS4ItemDataType } from "./item-data"; * Extend the basic ItemSheet with some very simple modifications * @extends {ItemSheet} */ -export class DS4ItemSheet extends ItemSheet { +export class DS4ItemSheet extends ItemSheet { /** @override */ static get defaultOptions(): FormApplicationOptions { return mergeObject(super.defaultOptions, { @@ -26,7 +25,7 @@ export class DS4ItemSheet extends ItemSheet { /* -------------------------------------------- */ /** @override */ - getData(): ItemSheetData { + getData(): ItemSheetData { const data = { ...super.getData(), config: CONFIG.DS4 }; console.log(data); return data; @@ -35,11 +34,15 @@ export class DS4ItemSheet extends ItemSheet { /* -------------------------------------------- */ /** @override */ - setPosition(options = {}): unknown { + setPosition(options: ApplicationPosition = {}): ApplicationPosition { const position = super.setPosition(options); - const sheetBody = (this.element as JQuery).find(".sheet-body"); // TODO: Why is the cast necessary? - const bodyHeight = position.height - 192; - sheetBody.css("height", bodyHeight); + if ("find" in this.element) { + const sheetBody = this.element.find(".sheet-body"); + const bodyHeight = position.height - 192; + sheetBody.css("height", bodyHeight); + } else { + console.log("Failure setting position."); + } return position; }