fix: make the DDV Config work with the Default Token Config

Closes #2
This commit is contained in:
Johannes Loher 2022-08-21 23:29:26 +02:00
parent 382f6c26ca
commit 68236af6ab
3 changed files with 21 additions and 2 deletions

View file

@ -19,6 +19,7 @@ module.exports = {
plugins: [], plugins: [],
globals: { globals: {
DefaultTokenConfig: false,
PrototypeTokenDocument: false, PrototypeTokenDocument: false,
}, },

View file

@ -52,6 +52,10 @@ export class DarknessDependentVisionConfig extends FormApplication {
return `${name}: ${game.i18n.localize('DarknessDependentVision.Title')}`; return `${name}: ${game.i18n.localize('DarknessDependentVision.Title')}`;
} }
get isDefault() {
return this.options.tokenConfig instanceof DefaultTokenConfig;
}
async getData() { async getData() {
const data = this.isPrototype ? this.actor.data.token : this.token.data; const data = this.isPrototype ? this.actor.data.token : this.token.data;
return { return {
@ -69,9 +73,23 @@ export class DarknessDependentVisionConfig extends FormApplication {
} }
async _updateObject(event, formData) { async _updateObject(event, formData) {
// Configure the Default Token Configuration
if (this.isDefault) {
const current = game.settings.get('core', DefaultTokenConfig.SETTING);
const update = foundry.utils.mergeObject(current, formData, { inplace: false });
const result = await game.settings.set('core', DefaultTokenConfig.SETTING, update);
const tokenConfig = this.options.tokenConfig;
tokenConfig.data = new foundry.data.TokenData(result);
tokenConfig.object = new TokenDocument(tokenConfig.data, { actor: null });
tokenConfig.token = tokenConfig.object;
tokenConfig.render();
return result;
}
// Configure the Prototype Token data of an Actor // Configure the Prototype Token data of an Actor
if (this.isPrototype) return this.actor.update({ token: formData }); if (this.isPrototype) return this.actor.update({ token: formData });
// Update an embedded Token document // Update an embedded Token document
else return this.token.update(formData); return this.token.update(formData);
} }
} }

View file

@ -22,7 +22,7 @@ function onGetTokenConfigHeaderButtons(tokenConfig, buttons) {
class: 'configure-darkness-dependent-vision', class: 'configure-darkness-dependent-vision',
icon: 'fas fa-eye', icon: 'fas fa-eye',
onclick: async () => { onclick: async () => {
return new DarknessDependentVisionConfig(tokenConfig.object).render(true); return new DarknessDependentVisionConfig(tokenConfig.object, { tokenConfig }).render(true);
}, },
}); });
} }