Type-ify Actor.
This commit is contained in:
parent
7a4cb7110b
commit
d9440b27a6
4 changed files with 35 additions and 12 deletions
src/module
|
@ -1,2 +1,26 @@
|
||||||
|
export type DS4ActorDataType = EntityData<DS4ActorData>;
|
||||||
|
|
||||||
// TODO: Actually add a type for data
|
// TODO: Actually add a type for data
|
||||||
export type DS4ActorDataType = unknown;
|
export class DS4ActorData {
|
||||||
|
public attributes: DS4ActorDataAttributes;
|
||||||
|
public traits: DS4ActorDataTraits;
|
||||||
|
}
|
||||||
|
|
||||||
|
class DS4ActorDataAttributes {
|
||||||
|
public body: ExpandableAttribute<number>;
|
||||||
|
public mobility: ExpandableAttribute<number>;
|
||||||
|
public mind: ExpandableAttribute<number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExpandableAttribute<T extends any> {
|
||||||
|
public 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>;
|
||||||
|
}
|
||||||
|
|
|
@ -21,9 +21,9 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
|
||||||
|
|
||||||
/** @override */
|
/** @override */
|
||||||
getData(): ActorSheetData<DS4ActorDataType> {
|
getData(): ActorSheetData<DS4ActorDataType> {
|
||||||
// TODO: replace ["..."] access with .
|
|
||||||
const data = super.getData();
|
const data = super.getData();
|
||||||
data["dtypes"] = ["String", "Number", "Boolean"];
|
const checkboxTypes = [typeof String, typeof Number, typeof Boolean];
|
||||||
|
console.log(data.data["attributes"]);
|
||||||
for (const attr of Object.values(data.data["attributes"])) {
|
for (const attr of Object.values(data.data["attributes"])) {
|
||||||
attr["isCheckbox"] = attr["dtype"] === "Boolean";
|
attr["isCheckbox"] = attr["dtype"] === "Boolean";
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ export class DS4ActorSheet extends ActorSheet<DS4ActorDataType, DS4Actor> {
|
||||||
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 }),
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { DS4ActorDataType } from "./actor-data";
|
import { DS4ActorData, DS4ActorDataType } from "./actor-data";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system.
|
||||||
|
@ -13,21 +13,20 @@ export class DS4Actor extends Actor<DS4ActorDataType> {
|
||||||
|
|
||||||
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
|
_prepareCombatValues(data: ActorData<DS4ActorDataType>): void {
|
||||||
const hitPointsModifier = getProperty(data, "data.combatValues.hitPoints.modifier") || 0;
|
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;
|
||||||
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,
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,7 +6,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, {
|
||||||
|
|
Loading…
Reference in a new issue