mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Improved domainremoval cleanup
This commit is contained in:
parent
d01965e5b9
commit
902bfac490
6 changed files with 86 additions and 35 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { DhHomebrew } from '../../data/settings/_module.mjs';
|
||||
import { slugify } from '../../helpers/utils.mjs';
|
||||
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
|
||||
|
||||
export default class DhHomebrewSettings extends HandlebarsApplicationMixin(ApplicationV2) {
|
||||
|
|
@ -199,18 +200,50 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
this.render();
|
||||
}
|
||||
|
||||
static async addDomain() {
|
||||
const id = foundry.utils.randomID();
|
||||
this.settings.updateSource({
|
||||
[`domains.${id}`]: {
|
||||
id: id,
|
||||
label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.domains.newDomain'),
|
||||
src: 'icons/svg/portal.svg'
|
||||
}
|
||||
});
|
||||
static async addDomain(event) {
|
||||
event.preventDefault();
|
||||
const content = new foundry.data.fields.StringField({
|
||||
label: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.domains.newDomainInputLabel'),
|
||||
hint: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.domains.newDomainInputHint'),
|
||||
required: true
|
||||
}).toFormGroup({}, { name: 'domainName', localize: true }).outerHTML;
|
||||
|
||||
this.selected.domain = id;
|
||||
this.render();
|
||||
async function callback(_, button) {
|
||||
const domainName = button.form.elements.domainName.value;
|
||||
if (!domainName) return;
|
||||
|
||||
const newSlug = slugify(domainName);
|
||||
const existingDomains = [
|
||||
...Object.values(this.settings.domains),
|
||||
...Object.values(CONFIG.DH.DOMAIN.domains)
|
||||
];
|
||||
if (existingDomains.find(x => slugify(game.i18n.localize(x.label)) === newSlug)) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.domains.duplicateDomain'));
|
||||
return;
|
||||
}
|
||||
|
||||
this.settings.updateSource({
|
||||
[`domains.${newSlug}`]: {
|
||||
id: newSlug,
|
||||
label: domainName,
|
||||
src: 'icons/svg/portal.svg'
|
||||
}
|
||||
});
|
||||
|
||||
this.selected.domain = newSlug;
|
||||
this.render();
|
||||
}
|
||||
|
||||
foundry.applications.api.DialogV2.prompt({
|
||||
content: content,
|
||||
rejectClose: false,
|
||||
modal: true,
|
||||
ok: { callback: callback.bind(this) },
|
||||
window: {
|
||||
title: game.i18n.localize('DAGGERHEART.SETTINGS.Homebrew.domains.newDomainInputTitle')
|
||||
},
|
||||
position: { width: 400 }
|
||||
});
|
||||
}
|
||||
|
||||
static toggleSelectedDomain(_, target) {
|
||||
|
|
@ -230,20 +263,30 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
|
||||
if (!confirmed) return;
|
||||
|
||||
const updateClasses = game.items.filter(
|
||||
x => x.type === 'class' && x.system.domains.includes(this.selected.domain)
|
||||
);
|
||||
await this.settings.updateSource({
|
||||
[`domains.-=${this.selected.domain}`]: null
|
||||
});
|
||||
|
||||
const currentSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew);
|
||||
if (currentSettings.domains[this.selected.domain]) {
|
||||
await currentSettings.updateSource({ [`domains.-=${this.selected.domain}`]: null });
|
||||
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew, currentSettings);
|
||||
}
|
||||
|
||||
const updateClasses = game.items.filter(x => x.type === 'class');
|
||||
for (let actor of game.actors) {
|
||||
updateClasses.push(
|
||||
...actor.items.filter(x => x.type === 'class' && x.system.domains.includes(this.selected.domain))
|
||||
);
|
||||
updateClasses.push(...actor.items.filter(x => x.type === 'class'));
|
||||
}
|
||||
|
||||
for (let c of updateClasses) {
|
||||
const newDomains = c.system.domains.map(x =>
|
||||
x === this.selected.domain ? CONFIG.DH.DOMAIN.domains.arcana.id : x
|
||||
);
|
||||
await c.update({ 'system.domains': newDomains });
|
||||
if (c.system.domains.includes(this.selected.domain)) {
|
||||
const newDomains =
|
||||
c.system.domains.length === 1
|
||||
? [CONFIG.DH.DOMAIN.domains.arcana.id]
|
||||
: c.system.domains.filter(x => x !== this.selected.domain);
|
||||
await c.update({ 'system.domains': newDomains });
|
||||
}
|
||||
c.sheet.render();
|
||||
}
|
||||
|
||||
const updateDomainCards = game.items.filter(
|
||||
|
|
@ -251,12 +294,9 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
|
|||
);
|
||||
for (let d of updateDomainCards) {
|
||||
await d.update({ 'system.domain': CONFIG.DH.DOMAIN.domains.arcana.id });
|
||||
d.sheet.render();
|
||||
}
|
||||
|
||||
await this.settings.updateSource({
|
||||
[`domains.-=${this.selected.domain}`]: null
|
||||
});
|
||||
|
||||
this.selected.domain = null;
|
||||
this.render();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue