export default class RandomizerConfig extends FormApplication { constructor(obj) { super({}, {}); this.actor = game.actors.get(obj.actorId); } static get defaultOptions() { return mergeObject(super.defaultOptions, { id: 'token-variants-token-flags', classes: ['sheet'], template: 'modules/token-variants/templates/randomizerConfig.html', resizable: true, minimizable: false, title: 'Randomizer', width: 500, }); } async getData(options) { const data = super.getData(options); const settings = this.actor.getFlag('token-variants', 'randomizerSettings') || {}; data.randomizer = settings; data.hasSettings = !isEmpty(settings); data.nameForgeActive = game.modules.get('nameforge')?.active; if (data.randomizer.nameForge?.models && Array.isArray(data.randomizer.nameForge.models)) { data.randomizer.nameForge.models = data.randomizer.nameForge.models.join(','); } return data; } /** * @param {JQuery} html */ activateListeners(html) { super.activateListeners(html); html.find('.selectNameForgeModels').click(this._selectNameForgeModels.bind(this)); // Can't have both tokenName and actorName checkboxes checked at the same time const tokenName = html.find('input[name="randomizer.tokenName"]'); const actorName = html.find('input[name="randomizer.actorName"]'); tokenName.change(() => { if (tokenName.is(':checked')) actorName.prop('checked', false); }); actorName.change(() => { if (actorName.is(':checked')) tokenName.prop('checked', false); }); } _selectNameForgeModels(event) { const inputSelected = $(event.target).siblings('input'); const selected = inputSelected.val().split(','); const genCheckbox = function (name, value) { return `