mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
Initial
This commit is contained in:
parent
bca7e0d3c9
commit
36eac51041
14 changed files with 171 additions and 8 deletions
|
|
@ -2,6 +2,7 @@ import DhpActor from '../../documents/actor.mjs';
|
|||
import D20RollDialog from '../../applications/dialogs/d20RollDialog.mjs';
|
||||
import { ActionMixin } from '../fields/actionField.mjs';
|
||||
import { originItemField } from '../chat-message/actorRoll.mjs';
|
||||
import TriggerField from '../fields/triggerField.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
|
|
@ -34,7 +35,8 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
nullable: false,
|
||||
required: true
|
||||
}),
|
||||
targetUuid: new fields.StringField({ initial: undefined })
|
||||
targetUuid: new fields.StringField({ initial: undefined }),
|
||||
triggers: new fields.ArrayField(new TriggerField())
|
||||
};
|
||||
|
||||
this.extraSchemas.forEach(s => {
|
||||
|
|
@ -343,6 +345,10 @@ export class ResourceUpdateMap extends Map {
|
|||
}
|
||||
|
||||
addResources(resources) {
|
||||
if (!resources?.length) return;
|
||||
const invalidResources = resources.some(resource => !resource.key);
|
||||
if (invalidResources) return;
|
||||
|
||||
for (const resource of resources) {
|
||||
if (!resource.key) continue;
|
||||
|
||||
|
|
|
|||
|
|
@ -2,5 +2,6 @@ export { ActionCollection } from './actionField.mjs';
|
|||
export { default as FormulaField } from './formulaField.mjs';
|
||||
export { default as ForeignDocumentUUIDField } from './foreignDocumentUUIDField.mjs';
|
||||
export { default as ForeignDocumentUUIDArrayField } from './foreignDocumentUUIDArrayField.mjs';
|
||||
export { default as TriggerField } from './triggerField.mjs';
|
||||
export { default as MappingField } from './mappingField.mjs';
|
||||
export * as ActionFields from './action/_module.mjs';
|
||||
|
|
|
|||
15
module/data/fields/triggerField.mjs
Normal file
15
module/data/fields/triggerField.mjs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
export default class TriggerField extends foundry.data.fields.SchemaField {
|
||||
constructor(context) {
|
||||
super(
|
||||
{
|
||||
trigger: new foundry.data.fields.StringField({
|
||||
nullable: false,
|
||||
initial: CONFIG.DH.TRIGGER.triggers.dualityRoll.id,
|
||||
choices: CONFIG.DH.TRIGGER.triggers
|
||||
}),
|
||||
command: new foundry.data.fields.JavaScriptField({ async: true })
|
||||
},
|
||||
context
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
* @property {boolean} isInventoryItem- Indicates whether items of this type is a Inventory Item
|
||||
*/
|
||||
|
||||
import { addLinkedItemsDiff, createScrollText, getScrollTextData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
||||
import { addLinkedItemsDiff, getScrollTextData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
||||
import { ActionsField } from '../fields/actionField.mjs';
|
||||
import FormulaField from '../fields/formulaField.mjs';
|
||||
|
||||
|
|
@ -135,6 +135,26 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
return data;
|
||||
}
|
||||
|
||||
prepareBaseData() {
|
||||
super.prepareBaseData();
|
||||
|
||||
for (const action of this.actions) {
|
||||
const actionsToRegister = [];
|
||||
for (let i = 0; i < action.triggers.length; i++) {
|
||||
const trigger = action.triggers[i];
|
||||
const fn = new foundry.utils.AsyncFunction('roll', 'actor', `{${trigger.command}\n}`);
|
||||
actionsToRegister.push(fn.bind(action));
|
||||
if (i === action.triggers.length - 1)
|
||||
game.system.registeredTriggers.registerTriggers(
|
||||
trigger.trigger,
|
||||
action.actor?.uuid,
|
||||
this.parent.uuid,
|
||||
actionsToRegister
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
// Skip if no initial action is required or actions already exist
|
||||
if (this.metadata.hasInitialAction && foundry.utils.isEmpty(this.actions)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue