Compare commits

..

No commits in common. "b08b8b93b655027ea7f597e55cb8e7202febe91c" and "22f38d796bce75dec8b8095a469f7d9ef26a9ea7" have entirely different histories.

5 changed files with 13 additions and 30 deletions

View file

@ -102,7 +102,11 @@ 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');
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, actor.id); const currentActiveParty = game.actors.find(x => x.type === 'party' && x.system.active);
if (currentActiveParty)
await currentActiveParty.update({ 'system.active': false });
await actor.update({ 'system.active': true });
ui.actors.render(); ui.actors.render();
} }
} }

View file

@ -40,8 +40,7 @@ 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,6 +9,7 @@ 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({
@ -22,10 +23,6 @@ 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 */
@ -48,21 +45,13 @@ export default class DhParty extends BaseDataActor {
} }
} }
_onCreate(data, options, userId) { /**@inheritdoc */
super._onCreate(data, options, userId); async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (game.user.isActiveGM && !game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty)) { if (!game.actors.some(x => x.type === 'party' && x.active))
game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.ActiveParty, this.parent.id).then(_ => { await this.updateSource({ active: true });
ui.actors.render();
});
}
}
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

@ -125,8 +125,6 @@ export default class DhpActor extends Actor {
game.system.registeredTriggers.unregisterItemTriggers(token.actor.items); game.system.registeredTriggers.unregisterItemTriggers(token.actor.items);
} }
} }
if(this.system._preDelete() === false) return false;
} }
_onDelete(options, userId) { _onDelete(options, userId) {

View file

@ -189,11 +189,4 @@ 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,
});
}; };