From fc60305a44aebf7379cd2255917cdd6e8161d31a Mon Sep 17 00:00:00 2001 From: WBHarry <89362246+WBHarry@users.noreply.github.com> Date: Wed, 15 Apr 2026 17:38:32 +0200 Subject: [PATCH 1/3] Update module/applications/sidebar/tabs/actorDirectory.mjs Co-authored-by: Carlos Fernandez --- module/applications/sidebar/tabs/actorDirectory.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/module/applications/sidebar/tabs/actorDirectory.mjs b/module/applications/sidebar/tabs/actorDirectory.mjs index a3c37acc..16e490c4 100644 --- a/module/applications/sidebar/tabs/actorDirectory.mjs +++ b/module/applications/sidebar/tabs/actorDirectory.mjs @@ -103,9 +103,7 @@ export default class DhActorDirectory extends foundry.applications.sidebar.tabs. if (!actor) throw new Error('Unexpected missing actor'); const currentActiveParty = game.actors.find(x => x.type === 'party' && x.system.active); - if (currentActiveParty) - await currentActiveParty.update({ 'system.active': false }); - + await currentActiveParty?.update({ 'system.active': false }); await actor.update({ 'system.active': true }); ui.actors.render(); } From 104616bc3d2d749deb8342866f78dc9947d0d589 Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 15 Apr 2026 18:15:23 +0200 Subject: [PATCH 2/3] Changed to use a world setting to store the active party id --- .../applications/sidebar/tabs/actorDirectory.mjs | 4 +--- module/config/settingsConfig.mjs | 3 ++- module/data/actor/party.mjs | 16 +++++++++++++--- module/systemRegistration/settings.mjs | 7 +++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/module/applications/sidebar/tabs/actorDirectory.mjs b/module/applications/sidebar/tabs/actorDirectory.mjs index 16e490c4..1306de61 100644 --- a/module/applications/sidebar/tabs/actorDirectory.mjs +++ b/module/applications/sidebar/tabs/actorDirectory.mjs @@ -102,9 +102,7 @@ export default class DhActorDirectory extends foundry.applications.sidebar.tabs. const actor = game.actors.get(li.dataset.entryId); if (!actor) throw new Error('Unexpected missing actor'); - const currentActiveParty = game.actors.find(x => x.type === 'party' && x.system.active); - await currentActiveParty?.update({ 'system.active': false }); - await actor.update({ 'system.active': true }); + await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, actor.id); ui.actors.render(); } } diff --git a/module/config/settingsConfig.mjs b/module/config/settingsConfig.mjs index 74315a8b..12e8536e 100644 --- a/module/config/settingsConfig.mjs +++ b/module/config/settingsConfig.mjs @@ -40,7 +40,8 @@ export const gameSettings = { LastMigrationVersion: 'LastMigrationVersion', SpotlightRequestQueue: 'SpotlightRequestQueue', CompendiumBrowserSettings: 'CompendiumBrowserSettings', - SpotlightTracker: 'SpotlightTracker' + SpotlightTracker: 'SpotlightTracker', + ActiveParty: 'ActiveParty', }; export const actionAutomationChoices = { diff --git a/module/data/actor/party.mjs b/module/data/actor/party.mjs index d35261fc..4fa295ef 100644 --- a/module/data/actor/party.mjs +++ b/module/data/actor/party.mjs @@ -9,7 +9,6 @@ export default class DhParty extends BaseDataActor { const fields = foundry.data.fields; return { ...super.defineSchema(), - active: new fields.BooleanField(), partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }, { prune: true }), notes: new fields.HTMLField(), gold: new fields.SchemaField({ @@ -23,6 +22,10 @@ export default class DhParty extends BaseDataActor { }; } + get active() { + return game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty) === this.parent.id; + } + /* -------------------------------------------- */ /**@inheritdoc */ @@ -50,8 +53,15 @@ export default class DhParty extends BaseDataActor { const allowed = await super._preCreate(data, options, user); if (allowed === false) return; - if (!game.actors.some(x => x.type === 'party' && x.active)) - await this.updateSource({ active: true }); + if (!game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty)) + game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, this.parent.id); + } + + async _preDelete() { + super._preDelete(); + + if (this.active) + game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, null); } _onDelete(options, userId) { diff --git a/module/systemRegistration/settings.mjs b/module/systemRegistration/settings.mjs index 63611cda..ae78e23b 100644 --- a/module/systemRegistration/settings.mjs +++ b/module/systemRegistration/settings.mjs @@ -189,4 +189,11 @@ const registerNonConfigSettings = () => { config: false, type: SpotlightTracker }); + + game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, { + scope: 'world', + config: false, + type: String, + default: null, + }); }; From b08b8b93b655027ea7f597e55cb8e7202febe91c Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 15 Apr 2026 18:25:36 +0200 Subject: [PATCH 3/3] Fixed onCreate and preDelete --- module/data/actor/party.mjs | 13 +++++++------ module/documents/actor.mjs | 2 ++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/module/data/actor/party.mjs b/module/data/actor/party.mjs index 4fa295ef..ba39b7e5 100644 --- a/module/data/actor/party.mjs +++ b/module/data/actor/party.mjs @@ -48,13 +48,14 @@ export default class DhParty extends BaseDataActor { } } - /**@inheritdoc */ - async _preCreate(data, options, user) { - const allowed = await super._preCreate(data, options, user); - if (allowed === false) return; + _onCreate(data, options, userId) { + super._onCreate(data, options, userId); - if (!game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty)) - game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, this.parent.id); + if (game.user.isActiveGM && !game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty)) { + game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, this.parent.id).then(_ => { + ui.actors.render(); + }); + } } async _preDelete() { diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 48f2f171..d578a481 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -125,6 +125,8 @@ export default class DhpActor extends Actor { game.system.registeredTriggers.unregisterItemTriggers(token.actor.items); } } + + if(this.system._preDelete() === false) return false; } _onDelete(options, userId) {