mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 15:39:02 +01:00
Merge branch 'main' into feature/death-moves
This commit is contained in:
commit
3447afc213
22 changed files with 265 additions and 85 deletions
|
|
@ -80,6 +80,7 @@ CONFIG.ux.ContextMenu = applications.ux.DHContextMenu;
|
|||
CONFIG.ux.TooltipManager = documents.DhTooltipManager;
|
||||
CONFIG.ux.TemplateManager = new TemplateManager();
|
||||
CONFIG.ux.TokenManager = new TokenManager();
|
||||
CONFIG.debug.triggers = false;
|
||||
|
||||
Hooks.once('init', () => {
|
||||
game.system.api = {
|
||||
|
|
@ -91,7 +92,7 @@ Hooks.once('init', () => {
|
|||
fields
|
||||
};
|
||||
|
||||
game.system.registeredTriggers = new RegisteredTriggers();
|
||||
game.system.registeredTriggers = new game.system.api.data.RegisteredTriggers();
|
||||
|
||||
const { DocumentSheetConfig } = foundry.applications.apps;
|
||||
DocumentSheetConfig.unregisterSheet(TokenDocument, 'core', foundry.applications.sheets.TokenConfig);
|
||||
|
|
@ -422,49 +423,12 @@ Hooks.on('refreshToken', (_, options) => {
|
|||
Hooks.on('renderCompendiumDirectory', (app, html) => applications.ui.ItemBrowser.injectSidebarButton(html));
|
||||
Hooks.on('renderDocumentDirectory', (app, html) => applications.ui.ItemBrowser.injectSidebarButton(html));
|
||||
|
||||
class RegisteredTriggers extends Map {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
/* Non actor-linked Actors should unregister the triggers of their tokens if a scene's token layer is torn down */
|
||||
Hooks.on('canvasTearDown', canvas => {
|
||||
game.system.registeredTriggers.unregisterSceneTriggers(canvas.scene);
|
||||
});
|
||||
|
||||
async registerTriggers(trigger, actor, triggeringActorType, uuid, commands) {
|
||||
const existingTrigger = this.get(trigger);
|
||||
if (!existingTrigger) this.set(trigger, new Map());
|
||||
|
||||
this.get(trigger).set(uuid, { actor, triggeringActorType, commands });
|
||||
}
|
||||
|
||||
async runTrigger(trigger, currentActor, ...args) {
|
||||
const updates = [];
|
||||
const triggerSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).triggers;
|
||||
if (!triggerSettings.enabled) return updates;
|
||||
|
||||
const dualityTrigger = this.get(trigger);
|
||||
if (dualityTrigger) {
|
||||
for (let { actor, triggeringActorType, commands } of dualityTrigger.values()) {
|
||||
const triggerData = CONFIG.DH.TRIGGER.triggers[trigger];
|
||||
if (triggerData.usesActor && triggeringActorType !== 'any') {
|
||||
if (triggeringActorType === 'self' && currentActor?.uuid !== actor) continue;
|
||||
else if (triggeringActorType === 'other' && currentActor?.uuid === actor) continue;
|
||||
}
|
||||
|
||||
for (let command of commands) {
|
||||
try {
|
||||
const result = await command(...args);
|
||||
if (result?.updates?.length) updates.push(...result.updates);
|
||||
} catch (_) {
|
||||
const triggerName = game.i18n.localize(triggerData.label);
|
||||
ui.notifications.error(
|
||||
game.i18n.format('DAGGERHEART.CONFIG.Triggers.triggerError', {
|
||||
trigger: triggerName,
|
||||
actor: currentActor?.name
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return updates;
|
||||
}
|
||||
}
|
||||
/* Non actor-linked Actors should register the triggers of their tokens on a readied scene */
|
||||
Hooks.on('canvasReady', canas => {
|
||||
game.system.registeredTriggers.registerSceneTriggers(canvas.scene);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue