// SPDX-FileCopyrightText: 2021 Johannes Loher // // SPDX-License-Identifier: MIT 'use strict'; import notifications from './notifications'; 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('DDV.Title')}`; } async getData() { const data = this.isPrototype ? this.actor.data.token : this.token.data; return { cssClasses: [this.isPrototype ? 'prototype' : null].filter((c) => !!c).join(' '), object: data, }; } async render(force, options) { const canConfigure = game.user.isGM || this.actor?.isOwner; if (!game.user.can('TOKEN_CONFIGURE') || !canConfigure) { notifications.warn(game.i18n.localize('DDV.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); } }