// SPDX-FileCopyrightText: 2021 Johannes Loher // // SPDX-License-Identifier: MIT /** * An application that provides functionality to configure darkness dependent * vision for a {@link TokenDocument}. * @extends {FormApplication} * @remarks Most of the code of this class is heavily inspired by the * implementation of {@link TokenConfig}. */ export class DarknessDependentVisionConfig extends FormApplication { constructor(object, options) { super(object, options); this.token = this.object; if (this.isPrototype) this.token = new PrototypeTokenDocument(this.object.data.token, { actor: this.object }); } static get defaultOptions() { return foundry.utils.mergeObject(super.defaultOptions, { classes: ['darkness-dependent-vision-config'], template: `modules/darkness-dependent-vision/templates/darkness-dependent-vision-config.hbs`, width: 520, height: 'auto', }); } get id() { return `darkness-dependent-vision-config-${this.object.id}`; } /** * A convenience accessor to test whether we are configuring the prototype Token for an Actor. * @type {boolean} */ get isPrototype() { return this.object instanceof Actor; } /** * Convenience access to the Actor document that this Token represents * @type {Actor} */ get actor() { return this.isPrototype ? this.object : this.token.actor; } get title() { const name = this.isPrototype ? `[${game.i18n.localize('TOKEN.TitlePrototype')}] ${this.actor.name}` : this.token.name; return `${name}: ${game.i18n.localize('DarknessDependentVision.Title')}`; } async getData() { const data = this.isPrototype ? this.actor.data.token : this.token.data; return { object: data, }; } async render(force, options) { const canConfigure = game.user.isGM || this.actor?.isOwner; if (!game.user.can('TOKEN_CONFIGURE') || !canConfigure) { ui.notifications?.warn(game.i18n.localize('DarknessDependentVision.WarningLackingPermissionToConfigure')); return this; } return super.render(force, options); } async _updateObject(event, formData) { // Configure the Prototype Token data of an Actor if (this.isPrototype) return this.actor.update({ token: formData }); // Update an embedded Token document else return this.token.update(formData); } }