mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-07-23 19:09:55 +02:00
[Fix] BaseAction Getter Fixes (#2105)
This commit is contained in:
parent
80cc7f1502
commit
a9000e5408
3 changed files with 39 additions and 19 deletions
23
module/data/action/_types.d.ts
vendored
Normal file
23
module/data/action/_types.d.ts
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
import { DHDamageData, DHResourceData } from '../fields/action/damageField.mjs';
|
||||||
|
|
||||||
|
declare module './baseAction.mjs' {
|
||||||
|
export default interface DHBaseAction {
|
||||||
|
_id: string;
|
||||||
|
systemPath: string;
|
||||||
|
type?: string;
|
||||||
|
baseAction: boolean;
|
||||||
|
name?: string;
|
||||||
|
description: string;
|
||||||
|
img?: string;
|
||||||
|
chatDisplay: boolean;
|
||||||
|
originItem: object;
|
||||||
|
actionType: string;
|
||||||
|
targetUuid?: string;
|
||||||
|
|
||||||
|
damage: {
|
||||||
|
main: DHDamageData;
|
||||||
|
/** An iterable record of items (todo: type the iterable record) */
|
||||||
|
resources: Record<string, DHResourceData>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -429,11 +429,11 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
||||||
}
|
}
|
||||||
|
|
||||||
get hasDamage() {
|
get hasDamage() {
|
||||||
return this.type !== 'healing' && (Boolean(this.damage?.main) || !foundry.utils.isEmpty(this.damage?.resources));
|
return this.type !== 'healing' && (Boolean(this.damage?.main) || Object.keys(this.damage?.resources ?? {}).length);
|
||||||
}
|
}
|
||||||
|
|
||||||
get hasHealing() {
|
get hasHealing() {
|
||||||
return this.type === 'healing' && !foundry.utils.isEmpty(this.damage?.resources);
|
return this.type === 'healing' && Object.keys(this.damage?.resources ?? {}).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
get hasSave() {
|
get hasSave() {
|
||||||
|
|
|
||||||
|
|
@ -6,27 +6,24 @@ export default class IterableTypedObjectField extends foundry.data.fields.TypedO
|
||||||
|
|
||||||
#elementClass;
|
#elementClass;
|
||||||
|
|
||||||
/** Initializes an object with an iterator. This modifies the prototype instead of */
|
/** Initializes an object with an iterator, where foundry.utils.getType() returns "Object" */
|
||||||
initialize(values) {
|
initialize(values) {
|
||||||
const object = Object.create(IterableObjectPrototype);
|
const object = {};
|
||||||
for (const [key, value] of Object.entries(values)) {
|
for (const [key, value] of Object.entries(values)) {
|
||||||
object[key] = new this.#elementClass(value);
|
object[key] = new this.#elementClass(value);
|
||||||
}
|
}
|
||||||
|
object[Symbol.iterator] = function* () {
|
||||||
|
for (const value of Object.values(this)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object.defineProperties(object, {
|
||||||
|
map: {
|
||||||
|
value: function (func) {
|
||||||
|
return Array.from(this, func);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The prototype of an iterable object.
|
|
||||||
* This allows the functionality of a class but also allows foundry.utils.getType() to return "Object" instead of "Unknown".
|
|
||||||
*/
|
|
||||||
const IterableObjectPrototype = {
|
|
||||||
[Symbol.iterator]: function* () {
|
|
||||||
for (const value of Object.values(this)) {
|
|
||||||
yield value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
map: function (func) {
|
|
||||||
return Array.from(this, func);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue