mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +02:00
Update file organization a bit
This commit is contained in:
parent
12119bfbfc
commit
13a9ddba46
2 changed files with 77 additions and 89 deletions
|
|
@ -18,75 +18,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
return `${game.i18n.localize('DAGGERHEART.GENERAL.Tabs.settings')}: ${this.action.name}`;
|
return `${game.i18n.localize('DAGGERHEART.GENERAL.Tabs.settings')}: ${this.action.name}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Needs to consider effect altOutcomes aswell */
|
|
||||||
static getOutcomeTabs(action) {
|
|
||||||
const outcomeKeys = [
|
|
||||||
'default',
|
|
||||||
...Object.keys(action.damage?.altOutcomes ?? {}).filter(key => action.damage.altOutcomes[key])
|
|
||||||
];
|
|
||||||
return outcomeKeys.reduce((acc, key, index) => {
|
|
||||||
acc[key] = {
|
|
||||||
active: index === 0,
|
|
||||||
cssClass: '',
|
|
||||||
group: 'outcomes',
|
|
||||||
id: key,
|
|
||||||
icon: null,
|
|
||||||
label: game.i18n.localize(CONFIG.DH.ACTIONS.outcomeTypes[key].label)
|
|
||||||
};
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Needs to consider effect altOutcomes aswell */
|
|
||||||
static selectOutcome(action, callback) {
|
|
||||||
const choices = Object.entries(CONFIG.DH.ACTIONS.outcomeTypes).reduce((acc, [key, value]) => {
|
|
||||||
if (action.damage.altOutcomes[key] === null) acc.push({ id: key, label: game.i18n.localize(value.label) });
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
}, []);
|
|
||||||
const content = new foundry.data.fields.StringField({
|
|
||||||
label: game.i18n.localize('Outcome'),
|
|
||||||
choices,
|
|
||||||
required: true
|
|
||||||
}).toFormGroup(
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
name: 'outcome',
|
|
||||||
localize: true,
|
|
||||||
nameAttr: 'value',
|
|
||||||
labelAttr: 'label'
|
|
||||||
}
|
|
||||||
).outerHTML;
|
|
||||||
|
|
||||||
const callbackWrapper = (_, button) => {
|
|
||||||
const choiceIndex = button.form.elements.outcome.value;
|
|
||||||
callback(choices[choiceIndex]?.id);
|
|
||||||
};
|
|
||||||
|
|
||||||
const typeDialog = new foundry.applications.api.DialogV2({
|
|
||||||
buttons: [
|
|
||||||
foundry.utils.mergeObject(
|
|
||||||
{
|
|
||||||
action: 'ok',
|
|
||||||
label: 'Confirm',
|
|
||||||
icon: 'fas fa-check',
|
|
||||||
default: true
|
|
||||||
},
|
|
||||||
{ callback: callbackWrapper }
|
|
||||||
)
|
|
||||||
],
|
|
||||||
content: content,
|
|
||||||
rejectClose: false,
|
|
||||||
modal: false,
|
|
||||||
window: {
|
|
||||||
title: game.i18n.localize('Add Outcome')
|
|
||||||
},
|
|
||||||
position: { width: 300 }
|
|
||||||
});
|
|
||||||
|
|
||||||
typeDialog.render(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
tag: 'form',
|
tag: 'form',
|
||||||
classes: ['daggerheart', 'dh-style', 'action-config', 'dialog', 'max-800'],
|
classes: ['daggerheart', 'dh-style', 'action-config', 'dialog', 'max-800'],
|
||||||
|
|
@ -97,16 +28,11 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
position: { width: 600, height: 'auto' },
|
position: { width: 600, height: 'auto' },
|
||||||
actions: {
|
actions: {
|
||||||
toggleSection: this.toggleSection,
|
toggleSection: this.toggleSection,
|
||||||
addEffect: this.addEffect,
|
|
||||||
removeEffect: this.removeEffect,
|
|
||||||
addElement: this.addElement,
|
addElement: this.addElement,
|
||||||
removeElement: this.removeElement,
|
removeElement: this.removeElement,
|
||||||
removeTransformActor: this.removeTransformActor,
|
removeTransformActor: this.removeTransformActor,
|
||||||
addOutcome: this.addOutcome,
|
addDamage: this.onAddDamage,
|
||||||
removeOutcome: this.removeOutcome,
|
removeDamage: this.onRemoveDamage,
|
||||||
editEffect: this.editEffect,
|
|
||||||
addDamage: this.addDamage,
|
|
||||||
removeDamage: this.removeDamage,
|
|
||||||
editDoc: this.editDoc,
|
editDoc: this.editDoc,
|
||||||
addTrigger: this.addTrigger,
|
addTrigger: this.addTrigger,
|
||||||
removeTrigger: this.removeTrigger,
|
removeTrigger: this.removeTrigger,
|
||||||
|
|
@ -195,6 +121,75 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
|
|
||||||
static CLEAN_ARRAYS = ['cost', 'effects', 'summon'];
|
static CLEAN_ARRAYS = ['cost', 'effects', 'summon'];
|
||||||
|
|
||||||
|
/* Needs to consider effect altOutcomes aswell */
|
||||||
|
static getOutcomeTabs(action) {
|
||||||
|
const outcomeKeys = [
|
||||||
|
'default',
|
||||||
|
...Object.keys(action.damage?.altOutcomes ?? {}).filter(key => action.damage.altOutcomes[key])
|
||||||
|
];
|
||||||
|
return outcomeKeys.reduce((acc, key, index) => {
|
||||||
|
acc[key] = {
|
||||||
|
active: index === 0,
|
||||||
|
cssClass: '',
|
||||||
|
group: 'outcomes',
|
||||||
|
id: key,
|
||||||
|
icon: null,
|
||||||
|
label: game.i18n.localize(CONFIG.DH.ACTIONS.outcomeTypes[key].label)
|
||||||
|
};
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Needs to consider effect altOutcomes aswell */
|
||||||
|
static selectOutcome(action, callback) {
|
||||||
|
const choices = Object.entries(CONFIG.DH.ACTIONS.outcomeTypes).reduce((acc, [key, value]) => {
|
||||||
|
if (action.damage.altOutcomes[key] === null) acc.push({ id: key, label: game.i18n.localize(value.label) });
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
const content = new foundry.data.fields.StringField({
|
||||||
|
label: game.i18n.localize('Outcome'),
|
||||||
|
choices,
|
||||||
|
required: true
|
||||||
|
}).toFormGroup(
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
name: 'outcome',
|
||||||
|
localize: true,
|
||||||
|
nameAttr: 'value',
|
||||||
|
labelAttr: 'label'
|
||||||
|
}
|
||||||
|
).outerHTML;
|
||||||
|
|
||||||
|
const callbackWrapper = (_, button) => {
|
||||||
|
const choiceIndex = button.form.elements.outcome.value;
|
||||||
|
callback(choices[choiceIndex]?.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
const typeDialog = new foundry.applications.api.DialogV2({
|
||||||
|
buttons: [
|
||||||
|
foundry.utils.mergeObject(
|
||||||
|
{
|
||||||
|
action: 'ok',
|
||||||
|
label: 'Confirm',
|
||||||
|
icon: 'fas fa-check',
|
||||||
|
default: true
|
||||||
|
},
|
||||||
|
{ callback: callbackWrapper }
|
||||||
|
)
|
||||||
|
],
|
||||||
|
content: content,
|
||||||
|
rejectClose: false,
|
||||||
|
modal: false,
|
||||||
|
window: {
|
||||||
|
title: game.i18n.localize('Add Outcome')
|
||||||
|
},
|
||||||
|
position: { width: 300 }
|
||||||
|
});
|
||||||
|
|
||||||
|
typeDialog.render(true);
|
||||||
|
}
|
||||||
|
|
||||||
_getTabs(tabs) {
|
_getTabs(tabs) {
|
||||||
for (const v of Object.values(tabs)) {
|
for (const v of Object.values(tabs)) {
|
||||||
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
v.active = this.tabGroups[v.group] ? this.tabGroups[v.group] === v.id : v.active;
|
||||||
|
|
@ -389,7 +384,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||||
}
|
}
|
||||||
|
|
||||||
static addDamage(_event, button) {
|
static onAddDamage(_event, button) {
|
||||||
if (!this.action.damage.parts) return;
|
if (!this.action.damage.parts) return;
|
||||||
|
|
||||||
const outcome = button.dataset.outcome;
|
const outcome = button.dataset.outcome;
|
||||||
|
|
@ -456,7 +451,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
typeDialog.render(true);
|
typeDialog.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeDamage(_event, button) {
|
static onRemoveDamage(_event, button) {
|
||||||
if (!this.action.damage.parts) return;
|
if (!this.action.damage.parts) return;
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
const { key, outcome } = button.dataset;
|
const { key, outcome } = button.dataset;
|
||||||
|
|
@ -557,13 +552,6 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
||||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Specific implementation in extending classes **/
|
|
||||||
static addOutcome(_event) {}
|
|
||||||
static removeOutcome(_event) {}
|
|
||||||
static async addEffect(_event) {}
|
|
||||||
static removeEffect(_event, _button) {}
|
|
||||||
static editEffect(_event) {}
|
|
||||||
|
|
||||||
async close(options) {
|
async close(options) {
|
||||||
this.tabGroups.primary = 'base';
|
this.tabGroups.primary = 'base';
|
||||||
await super.close(options);
|
await super.close(options);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ export default class DHActionConfig extends DHActionBaseConfig {
|
||||||
...DHActionBaseConfig.DEFAULT_OPTIONS,
|
...DHActionBaseConfig.DEFAULT_OPTIONS,
|
||||||
actions: {
|
actions: {
|
||||||
...DHActionBaseConfig.DEFAULT_OPTIONS.actions,
|
...DHActionBaseConfig.DEFAULT_OPTIONS.actions,
|
||||||
addOutcome: this.addOutcome,
|
addOutcome: this.onAddOutcome,
|
||||||
removeOutcome: this.removeOutcome,
|
removeOutcome: this.onRemoveOutcome,
|
||||||
addEffect: this.addEffect,
|
addEffect: this.addEffect,
|
||||||
removeEffect: this.removeEffect,
|
removeEffect: this.removeEffect,
|
||||||
editEffect: this.editEffect
|
editEffect: this.editEffect
|
||||||
|
|
@ -22,7 +22,7 @@ export default class DHActionConfig extends DHActionBaseConfig {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
static addOutcome() {
|
static onAddOutcome() {
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
|
|
||||||
DHActionBaseConfig.selectOutcome(this.action, key => {
|
DHActionBaseConfig.selectOutcome(this.action, key => {
|
||||||
|
|
@ -34,7 +34,7 @@ export default class DHActionConfig extends DHActionBaseConfig {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static removeOutcome(_event, button) {
|
static onRemoveOutcome(_event, button) {
|
||||||
const { outcome } = button.dataset;
|
const { outcome } = button.dataset;
|
||||||
const data = this.action.toObject();
|
const data = this.action.toObject();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue