Merge branch '009-templateTypes' into 'master'

Resolve "Prepare template types"

Closes #9

See merge request dungeonslayers/ds4!1
This commit is contained in:
Johannes Loher 2020-12-28 17:50:58 +01:00
commit b95514bcdb
7 changed files with 57 additions and 44 deletions

2
package-lock.json generated
View file

@ -2678,7 +2678,7 @@
} }
}, },
"foundry-pc-types": { "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", "from": "git+https://git.f3l.de/dungeonslayers/foundry-pc-types.git#f3l-fixes",
"dev": true, "dev": true,
"requires": { "requires": {

View file

@ -1,2 +1,26 @@
// TODO: Actually add a type for data export interface DS4ActorDataType {
export type DS4ActorDataType = unknown; attributes: DS4ActorDataAttributes;
traits: DS4ActorDataTraits;
}
interface DS4ActorDataAttributes {
body: BodyAttribute;
mobility: ExtensibleData<number>;
mind: ExtensibleData<number>;
}
interface ExtensibleData<T extends any> {
initial: T;
}
// Blueprint in case we need more detailed differentiation
type BodyAttribute = ExtensibleData<number>;
interface DS4ActorDataTraits {
strength: ExtensibleData<number>;
constitution: ExtensibleData<number>;
agility: ExtensibleData<number>;
dexterity: ExtensibleData<number>;
intellect: ExtensibleData<number>;
aura: ExtensibleData<number>;
}

View file

@ -19,18 +19,6 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @override */
getData(): ActorSheetData<DS4ActorDataType> {
// 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 */ /** @override */
activateListeners(html: JQuery): void { activateListeners(html: JQuery): void {
super.activateListeners(html); super.activateListeners(html);
@ -39,17 +27,17 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
if (!this.options.editable) return; if (!this.options.editable) return;
// Add Inventory Item // 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 // Update Inventory Item
html.find(".item-edit").click((ev) => { html.find(".item-edit").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".item"); const li = $(ev.currentTarget).parents(".item");
const item = this.actor.getOwnedItem(li.data("itemId")); const item = this.actor.getOwnedItem(li.data("itemId"));
item.sheet.render(true); item.sheet.render(true);
}); });
// Delete Inventory Item // Delete Inventory Item
html.find(".item-delete").click((ev) => { html.find(".item-delete").on("click", (ev) => {
const li = $(ev.currentTarget).parents(".item"); const li = $(ev.currentTarget).parents(".item");
this.actor.deleteOwnedItem(li.data("itemId")); this.actor.deleteOwnedItem(li.data("itemId"));
li.slideUp(200, () => this.render(false)); li.slideUp(200, () => this.render(false));
@ -66,7 +54,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
* @param {Event} event The originating click event * @param {Event} event The originating click event
* @private * @private
*/ */
_onItemCreate(event: JQuery.ClickEvent): Promise<Item> { private _onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
event.preventDefault(); event.preventDefault();
const header = event.currentTarget; const header = event.currentTarget;
// Get the type of item to create. // Get the type of item to create.
@ -93,13 +81,13 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
* @param {Event} event The originating click event * @param {Event} event The originating click event
* @private * @private
*/ */
_onRoll(event: JQuery.ClickEvent): void { private _onRoll(event: JQuery.ClickEvent): void {
event.preventDefault(); event.preventDefault();
const element = event.currentTarget; const element = event.currentTarget;
const dataset = element.dataset; const dataset = element.dataset;
if (dataset.roll) { if (dataset.roll) {
const roll = new Roll(dataset.roll, this.actor.data.data as Record<string, unknown>); const roll = new Roll(dataset.roll, this.actor.data.data);
const label = dataset.label ? `Rolling ${dataset.label}` : ""; const label = dataset.label ? `Rolling ${dataset.label}` : "";
roll.roll().toMessage({ roll.roll().toMessage({
speaker: ChatMessage.getSpeaker({ actor: this.actor }), speaker: ChatMessage.getSpeaker({ actor: this.actor }),

View file

@ -11,29 +11,27 @@ export class DS4Actor extends Actor<DS4ActorDataType> {
this._prepareCombatValues(data); this._prepareCombatValues(data);
} }
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void { private _prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0; const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
const actorData = data.data;
setProperty( setProperty(
data, data,
"data.combatValues.hitPoints.max", "data.combatValues.hitPoints.max",
data.data["attributes"]["body"].initial + // TODO: replace ["..."] actorData.attributes.body.initial + actorData.traits.constitution.initial + 10 + hitPointsModifier,
data.data["traits"]["constitution"].initial + // TODO: replace ["..."]
10 +
hitPointsModifier,
); );
const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0; const defenseModifier = getProperty(data, "data.combatValues.defense.modifier") || 0;
setProperty( setProperty(
data, data,
"data.combatValues.defense.value", "data.combatValues.defense.value",
data.data["attributes"]["body"].initial + // TODO: replace ["..."] actorData.attributes.body.initial +
data.data["traits"]["constitution"].initial + // TODO: replace ["..."] actorData.traits.constitution.initial +
this._getArmorValue() + this._getArmorValue() +
defenseModifier, defenseModifier,
); );
} }
_getArmorValue(): number { private _getArmorValue(): number {
return this.data["items"] return this.data["items"]
.filter((item) => ["armor", "shield"].includes(item.type)) .filter((item) => ["armor", "shield"].includes(item.type))
.filter((item) => item.data.equipped) .filter((item) => item.data.equipped)

View file

@ -1,11 +1,11 @@
export const DS4 = { export const DS4 = {
// ASCII Artwork // ASCII Artwork
ASCII: `_____________________________________________________________________________________________ ASCII: String.raw`_____________________________________________________________________________________________
____ _ _ _ _ ____ _____ ___ _ _ ____ _ _ __ _______ ____ ____ _ _ ____ _ _ _ _ ____ _____ ___ _ _ ____ _ _ __ _______ ____ ____ _ _
| _ \\| | | | \\ | |/ ___| ____/ _ \\| \\ | / ___|| | / \\\\ \\ / / ____| _ \\/ ___| | || | | _ \| | | | \ | |/ ___| ____/ _ \| \ | / ___|| | / \\ \ / / ____| _ \/ ___| | || |
| | | | | | | \\| | | _| _|| | | | \\| \\___ \\| | / _ \\\\ V /| _| | |_) \\___ \\ | || |_ | | | | | | | \| | | _| _|| | | | \| \___ \| | / _ \\ V /| _| | |_) \___ \ | || |_
| |_| | |_| | |\\ | |_| | |__| |_| | |\\ |___) | |___ / ___ \\| | | |___| _ < ___) | |__ _| | |_| | |_| | |\ | |_| | |__| |_| | |\ |___) | |___ / ___ \| | | |___| _ < ___) | |__ _|
|____/ \\___/|_| \\_|\\____|_____\\___/|_| \\_|____/|_____/_/ \\_\\_| |_____|_| \\_\\____/ |_| |____/ \___/|_| \_|\____|_____\___/|_| \_|____/|_____/_/ \_\_| |_____|_| \_\____/ |_|
=============================================================================================`, =============================================================================================`,
/** /**

View file

@ -18,8 +18,8 @@ Hooks.once("init", async function () {
CONFIG.DS4 = DS4; CONFIG.DS4 = DS4;
// Define custom Entity classes // Define custom Entity classes
CONFIG.Actor.entityClass = DS4Actor as typeof Actor; // TODO: Can we remove the casts? CONFIG.Actor.entityClass = DS4Actor as typeof Actor;
CONFIG.Item.entityClass = DS4Item as typeof Item; // TODO: Can we remove the casts? CONFIG.Item.entityClass = DS4Item as typeof Item;
// Register sheet application classes // Register sheet application classes
Actors.unregisterSheet("core", ActorSheet); Actors.unregisterSheet("core", ActorSheet);

View file

@ -1,4 +1,3 @@
import { DS4ActorDataType } from "../actor/actor-data";
import { DS4Item } from "./item"; import { DS4Item } from "./item";
import { DS4ItemDataType } from "./item-data"; import { DS4ItemDataType } from "./item-data";
@ -6,7 +5,7 @@ import { DS4ItemDataType } from "./item-data";
* Extend the basic ItemSheet with some very simple modifications * Extend the basic ItemSheet with some very simple modifications
* @extends {ItemSheet} * @extends {ItemSheet}
*/ */
export class DS4ItemSheet extends ItemSheet<DS4ActorDataType, DS4Item> { export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
/** @override */ /** @override */
static get defaultOptions(): FormApplicationOptions { static get defaultOptions(): FormApplicationOptions {
return mergeObject(super.defaultOptions, { return mergeObject(super.defaultOptions, {
@ -26,7 +25,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ActorDataType, DS4Item> {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @override */ /** @override */
getData(): ItemSheetData<DS4ItemDataType> { getData(): ItemSheetData<DS4ItemDataType, DS4Item> {
const data = { ...super.getData(), config: CONFIG.DS4 }; const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data); console.log(data);
return data; return data;
@ -35,11 +34,15 @@ export class DS4ItemSheet extends ItemSheet<DS4ActorDataType, DS4Item> {
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @override */ /** @override */
setPosition(options = {}): unknown { setPosition(options: ApplicationPosition = {}): ApplicationPosition {
const position = super.setPosition(options); const position = super.setPosition(options);
const sheetBody = (this.element as JQuery).find(".sheet-body"); // TODO: Why is the cast necessary? if ("find" in this.element) {
const sheetBody = this.element.find(".sheet-body");
const bodyHeight = position.height - 192; const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight); sheetBody.css("height", bodyHeight);
} else {
console.log("Failure setting position.");
}
return position; return position;
} }