Update types

This commit is contained in:
Carlos Fernandez 2026-07-02 00:21:17 -04:00
parent 731be03277
commit 1e30d4973b
5 changed files with 66 additions and 8 deletions

View file

@ -114,7 +114,10 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
return this._id;
}
/** Returns true if the current user is the owner of the containing item */
/**
* Returns true if the current user is the owner of the containing item.
* @returns {boolean}
*/
get isOwner() {
return this.item?.isOwner ?? true;
}
@ -143,6 +146,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
/**
* Return the first Actor parent found.
* @returns {DhpActor | null}
*/
get actor() {
return this.item instanceof DhpActor
@ -155,6 +159,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
/**
* Returns true if the action is usable.
* An action is usable on any actor type. For example, an adversary might have a base attack action.
* @returns {boolean}
*/
get usable() {
const actor = this.actor;

View file

@ -2,6 +2,10 @@ import { getWorldActor } from '../../../helpers/utils.mjs';
const fields = foundry.data.fields;
/**
* @import DHSummonAction from '../../action/summonAction.mjs'
*/
export default class DHSummonField extends fields.SchemaField {
/**
* Action Workflow order
@ -22,6 +26,11 @@ export default class DHSummonField extends fields.SchemaField {
super(transformFields, options, context);
}
/**
* Runs the execute. This is run on behalf of DHSummonAction.
* @todo move this function to be on the summon action.
* @this DHSummonAction
*/
static async execute() {
if (!this.transform.actorUUID) {
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.noTransformActor'));
@ -39,10 +48,11 @@ export default class DHSummonField extends fields.SchemaField {
return false;
}
const activeTokens = this.actor.getActiveTokens().map(x => x.document);
const activeTokens = this.actor.getActiveTokens(false, true);
const controlledMatchingTokens = canvas.tokens.controlled
.filter(x => x.actor && x.actor.uuid === this.actor.uuid)
.map(x => x.document);
/** @type {typeof game.system.api.documents.DhToken | null} */
const token = this.actor.token ?? (
activeTokens.length === 1 ? activeTokens[0] :
(controlledMatchingTokens.length === 1 ? controlledMatchingTokens[0] : null)
@ -62,9 +72,10 @@ export default class DHSummonField extends fields.SchemaField {
const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes;
const tokenSize = actor?.system.metadata.usesSize ? tokenSizes[actor.system.size] : actor.prototypeToken.width;
const createdTokens = await canvas.scene.createEmbeddedDocuments(
const prototypeTokenData = actor.prototypeToken.toObject();
const createdToken = (await canvas.scene.createEmbeddedDocuments(
'Token', [{
...actor.prototypeToken.toObject(),
...prototypeTokenData,
actorId: actor.id,
x: token.x,
y: token.y,
@ -74,8 +85,7 @@ export default class DHSummonField extends fields.SchemaField {
elevation: token.elevation
}],
{ controlObject: true, parent: canvas.scene }
);
const createdToken = createdTokens[0];
))[0];
/* Swap out previous combatant for a new one if applicable */
if (token.combatant) {

View file

@ -3,17 +3,26 @@ import DHItem from './item.mjs';
import BaseDataItem from '../data/item/base.mjs';
import DhActiveEffect from './activeEffect.mjs';
import EmbeddedCollection from '@common/abstract/embedded-collection.mjs';
import DHToken from './token.mjs';
import Actor from '@client/documents/actor.mjs';
import Item from '@client/documents/item.mjs';
declare module './actor.mjs' {
export default interface DhpActor<T extends BaseDataActor = BaseDataActor> {
export default interface DhpActor<T extends BaseDataActor = BaseDataActor> extends Actor {
system: T;
items: EmbeddedCollection<DHItem>;
effects: EmbeddedCollection<DhActiveEffect>;
get token(): DHToken | null;
/** @inheritdoc */
getActiveTokens(linked?: boolean, document?: boolean): (DHToken | foundry.canvas.placeables.Token)[];
getActiveTokens(linked?: boolean, document: true): DHToken[];
getActiveTokens(linked?: boolean, document: false): foundry.canvas.placeables.Token[];
}
}
declare module './item.mjs' {
export default interface DHItem<T extends BaseDataItem = BaseDataItem> {
export default interface DHItem<T extends BaseDataItem = BaseDataItem> extends Item {
parent: DhpActor;
actor: DhpActor;
system: T;

View file

@ -1,6 +1,10 @@
import { diceTypes, getDiceSoNicePresets, getDiceSoNicePreset, range } from '../config/generalConfig.mjs';
import Tagify from '@yaireo/tagify';
/**
* @import DhpActor from '../documents/actor.mjs';
*/
export const capitalize = string => {
return string.charAt(0).toUpperCase() + string.slice(1);
};
@ -891,6 +895,13 @@ export function shouldUseHopeFearAutomation(options = { gmAsPlayer: true }) {
return (!game.user.isGM || options.gmAsPlayer) ? hopeFear.players : hopeFear.gm;
}
/**
* Returns the given actor if its a world actor,
* finds a world actor equivalent,
* or imports the actor and returns the imported actor.
* @param {DhpActor} baseActor
* @returns {Promise<DhpActor>} a world actor
*/
export async function getWorldActor(baseActor) {
if (baseActor.inCompendium) {
const worldActorCandidates = game.actors.filter(x =>