/
ActiveEffectConfig.js
124 lines (104 loc) · 3.24 KB
/
ActiveEffectConfig.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { localize } from '#runtime/svelte/helper';
import { TJSDocument } from '#runtime/svelte/store/fvtt/document';
import { SvelteApplication } from '#runtime/svelte/application';
import ActiveEffectConfigSheet from './sheets/ActiveEffectConfig.svelte';
export default class ActiveEffectConfigA5e extends SvelteApplication {
/**
* @inheritDoc
*/
constructor(activeEffect, options = {}) {
options.svelte ??= {};
super(foundry.utils.mergeObject(
options,
{
baseApplication: 'ActiveEffectConfig',
id: activeEffect.parent
? `effect-${activeEffect.parent.id}-${activeEffect.id}`
: `effect-${activeEffect.id}`,
title: `Configure Active Effect: ${activeEffect.name}`,
svelte: {
class: ActiveEffectConfigSheet,
props: {
document: null
}
},
resizable: true,
focusAuto: false,
width: 555,
height: 500
}
));
this.activeEffect = activeEffect;
this.options.svelte.props.document = new TJSDocument(
activeEffect,
{ delete: this.close.bind(this) }
);
this.options.svelte.props.sheet = this;
// Add Status Effects
this.statusEffectList = {};
const effectList = CONFIG.statusEffects
.filter((effect) => effect.id)
.map((effect) => ({ id: effect.id, label: localize(effect.label) }))
.sort((a, b) => (a.label < b.label ? -1 : 1));
effectList.forEach((effect) => {
this.statusEffectList[effect.id] = effect.label;
});
const usableOptions = activeEffect.parent?.documentName === 'Actor'
? game.a5e.activeEffects.options[this.activeEffect.parent.type]
: game.a5e.activeEffects.options.all;
this.optionsList = usableOptions.allOptions;
}
/**
* Default Application options
*
* @returns {object} options - Application options.
* @see https://foundryvtt.com/api/Application.html#options
*/
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
baseApplication: 'ActiveEffectConfig',
classes: ['a5e-sheet', 'a5e-sheet--active-effect'],
minimizable: true,
resizable: true,
svelte: {
target: document.body
}
});
}
get object() {
return this.activeEffect;
}
get title() {
return `${game.i18n.localize('EFFECT.ConfigTitle')}: ${this.activeEffect.name}`;
}
get isActorEffect() {
return this.activeEffect?.parent.documentName === 'Actor';
}
get isActionEffect() {
return this.activeEffect?.parent.documentName === 'Action';
}
get isItemEffect() {
return this.activeEffect?.parent.documentName === 'Item';
}
_getHeaderButtons() {
const buttons = super._getHeaderButtons();
if (!this.activeEffect.pack) {
buttons.unshift({
label: 'Sheet Configuration',
class: 'configure-sheet',
icon: 'fas fa-cog fa-fw',
title: 'Configure Sheet',
onclick: (event) => this._onConfigureSheet(event)
});
}
return buttons;
}
_onConfigureSheet(event) {
if (event) event.preventDefault();
const sheetConfigDialog = new DocumentSheetConfig(
this.activeEffect,
{ top: this.position.top + 40 }
);
sheetConfigDialog.render(true);
}
}