Update to new data bindings, everythings an interface now.

This commit is contained in:
Oliver Rümpelein 2020-12-28 17:34:40 +01:00
parent 78be1c2370
commit 9385917edd
6 changed files with 40 additions and 50 deletions

2
package-lock.json generated
View file

@ -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": {

View file

@ -1,26 +1,26 @@
export type DS4ActorDataType = EntityData<DS4ActorData>;
// TODO: Actually add a type for data
export class DS4ActorData {
public attributes: DS4ActorDataAttributes;
public traits: DS4ActorDataTraits;
export interface DS4ActorDataType {
attributes: DS4ActorDataAttributes;
traits: DS4ActorDataTraits;
}
class DS4ActorDataAttributes {
public body: ExpandableAttribute<number>;
public mobility: ExpandableAttribute<number>;
public mind: ExpandableAttribute<number>;
interface DS4ActorDataAttributes {
body: BodyAttribute;
mobility: ExtensibleData<number>;
mind: ExtensibleData<number>;
}
class ExpandableAttribute<T extends any> {
public initial: T;
interface ExtensibleData<T extends any> {
initial: T;
}
class DS4ActorDataTraits {
public strength: ExpandableAttribute<number>;
public constitution: ExpandableAttribute<number>;
public agility: ExpandableAttribute<number>;
public dexterity: ExpandableAttribute<number>;
public intellect: ExpandableAttribute<number>;
public aura: ExpandableAttribute<number>;
// 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> {
const data = super.getData();
const checkboxTypes = [typeof String, typeof Number, typeof Boolean];
console.log(data.data["attributes"]);
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<DS4ActorDataType, DS4Actor> {
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("clock", (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<DS4ActorDataType, DS4Actor> {
* @param {Event} event The originating click event
* @private
*/
_onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
private _onItemCreate(event: JQuery.ClickEvent): Promise<Item> {
event.preventDefault();
const header = event.currentTarget;
// Get the type of item to create.
@ -93,7 +81,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
* @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;

View file

@ -1,4 +1,4 @@
import { DS4ActorData, DS4ActorDataType } from "./actor-data";
import { DS4ActorDataType } from "./actor-data";
/**
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
@ -11,10 +11,9 @@ export class DS4Actor extends Actor<DS4ActorDataType> {
this._prepareCombatValues(data);
}
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
private _prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
// data.data seems to get initialized with the enitity's data
const actorData = (data.data as unknown) as DS4ActorData;
const actorData = data.data;
setProperty(
data,
"data.combatValues.hitPoints.max",
@ -32,7 +31,7 @@ export class DS4Actor extends Actor<DS4ActorDataType> {
);
}
_getArmorValue(): number {
private _getArmorValue(): number {
return this.data["items"]
.filter((item) => ["armor", "shield"].includes(item.type))
.filter((item) => item.data.equipped)

View file

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

View file

@ -1,4 +1,3 @@
import { DS4ActorDataType } from "../actor/actor-data";
import { DS4Item } from "./item";
import { DS4ItemDataType } from "./item-data";
@ -26,7 +25,7 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
/* -------------------------------------------- */
/** @override */
getData(): ItemSheetData<DS4ItemDataType> {
getData(): ItemSheetData<DS4ItemDataType, DS4Item> {
const data = { ...super.getData(), config: CONFIG.DS4 };
console.log(data);
return data;
@ -35,11 +34,15 @@ export class DS4ItemSheet extends ItemSheet<DS4ItemDataType, DS4Item> {
/* -------------------------------------------- */
/** @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");
const bodyHeight = position.height - 192;
sheetBody.css("height", bodyHeight);
} else {
console.log("Failure setting position.");
}
return position;
}