Changed to use a world setting to store the active party id

This commit is contained in:
WBHarry 2026-04-15 18:15:23 +02:00
parent fc60305a44
commit 104616bc3d
4 changed files with 23 additions and 7 deletions

View file

@ -102,9 +102,7 @@ export default class DhActorDirectory extends foundry.applications.sidebar.tabs.
const actor = game.actors.get(li.dataset.entryId); const actor = game.actors.get(li.dataset.entryId);
if (!actor) throw new Error('Unexpected missing actor'); if (!actor) throw new Error('Unexpected missing actor');
const currentActiveParty = game.actors.find(x => x.type === 'party' && x.system.active); await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, actor.id);
await currentActiveParty?.update({ 'system.active': false });
await actor.update({ 'system.active': true });
ui.actors.render(); ui.actors.render();
} }
} }

View file

@ -40,7 +40,8 @@ export const gameSettings = {
LastMigrationVersion: 'LastMigrationVersion', LastMigrationVersion: 'LastMigrationVersion',
SpotlightRequestQueue: 'SpotlightRequestQueue', SpotlightRequestQueue: 'SpotlightRequestQueue',
CompendiumBrowserSettings: 'CompendiumBrowserSettings', CompendiumBrowserSettings: 'CompendiumBrowserSettings',
SpotlightTracker: 'SpotlightTracker' SpotlightTracker: 'SpotlightTracker',
ActiveParty: 'ActiveParty',
}; };
export const actionAutomationChoices = { export const actionAutomationChoices = {

View file

@ -9,7 +9,6 @@ export default class DhParty extends BaseDataActor {
const fields = foundry.data.fields; const fields = foundry.data.fields;
return { return {
...super.defineSchema(), ...super.defineSchema(),
active: new fields.BooleanField(),
partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }, { prune: true }), partyMembers: new ForeignDocumentUUIDArrayField({ type: 'Actor' }, { prune: true }),
notes: new fields.HTMLField(), notes: new fields.HTMLField(),
gold: new fields.SchemaField({ 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 */ /**@inheritdoc */
@ -50,8 +53,15 @@ export default class DhParty extends BaseDataActor {
const allowed = await super._preCreate(data, options, user); const allowed = await super._preCreate(data, options, user);
if (allowed === false) return; if (allowed === false) return;
if (!game.actors.some(x => x.type === 'party' && x.active)) if (!game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty))
await this.updateSource({ active: true }); 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) { _onDelete(options, userId) {

View file

@ -189,4 +189,11 @@ const registerNonConfigSettings = () => {
config: false, config: false,
type: SpotlightTracker type: SpotlightTracker
}); });
game.settings.register(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, {
scope: 'world',
config: false,
type: String,
default: null,
});
}; };