mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-13 20:21:06 +01:00
Moved methods into TypedModelData
This commit is contained in:
parent
a5aa2e914d
commit
d4754e511f
7 changed files with 83 additions and 91 deletions
|
|
@ -27,7 +27,7 @@ export default function DhpApplicationMixin(Base) {
|
||||||
|
|
||||||
async _prepareContext(_options, objectPath = 'document') {
|
async _prepareContext(_options, objectPath = 'document') {
|
||||||
const context = await super._prepareContext(_options);
|
const context = await super._prepareContext(_options);
|
||||||
context.source = this[objectPath].toObject();
|
context.source = this[objectPath];
|
||||||
context.fields = this[objectPath].schema.fields;
|
context.fields = this[objectPath].schema.fields;
|
||||||
context.systemFields = this[objectPath].system ? this[objectPath].system.schema.fields : {};
|
context.systemFields = this[objectPath].system ? this[objectPath].system.schema.fields : {};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ export default class ClassSheet extends DaggerheartSheet(ItemSheetV2) {
|
||||||
actions: {
|
actions: {
|
||||||
removeSubclass: this.removeSubclass,
|
removeSubclass: this.removeSubclass,
|
||||||
viewSubclass: this.viewSubclass,
|
viewSubclass: this.viewSubclass,
|
||||||
removeFeature: this.removeFeature,
|
deleteFeature: this.deleteFeature,
|
||||||
viewFeature: this.viewFeature,
|
editFeature: this.editFeature,
|
||||||
removeItem: this.removeItem,
|
removeItem: this.removeItem,
|
||||||
viewItem: this.viewItem,
|
viewItem: this.viewItem,
|
||||||
removePrimaryWeapon: this.removePrimaryWeapon,
|
removePrimaryWeapon: this.removePrimaryWeapon,
|
||||||
|
|
@ -153,13 +153,13 @@ export default class ClassSheet extends DaggerheartSheet(ItemSheetV2) {
|
||||||
subclass.sheet.render(true);
|
subclass.sheet.render(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async removeFeature(_, button) {
|
static async deleteFeature(_, button) {
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
'system.features': this.document.system.features.filter(x => x.uuid !== button.dataset.feature)
|
'system.features': this.document.system.features.map(x => x.uuid).filter(x => x !== button.dataset.feature)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static async viewFeature(_, button) {
|
static async editFeature(_, button) {
|
||||||
const feature = await fromUuid(button.dataset.feature);
|
const feature = await fromUuid(button.dataset.feature);
|
||||||
feature.sheet.render(true);
|
feature.sheet.render(true);
|
||||||
}
|
}
|
||||||
|
|
@ -198,11 +198,11 @@ export default class ClassSheet extends DaggerheartSheet(ItemSheetV2) {
|
||||||
const item = await fromUuid(data.uuid);
|
const item = await fromUuid(data.uuid);
|
||||||
if (item.type === 'subclass') {
|
if (item.type === 'subclass') {
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
'system.subclasses': item.uuid
|
'system.subclasses': [...this.document.system.subclasses.map(x => x.uuid), item.uuid]
|
||||||
});
|
});
|
||||||
} else if (item.type === 'feature') {
|
} else if (item.type === 'feature') {
|
||||||
await this.document.update({
|
await this.document.update({
|
||||||
'system.features': [...this.document.system.features, item.uuid]
|
'system.features': [...this.document.system.features.map(x => x.uuid), item.uuid]
|
||||||
});
|
});
|
||||||
} else if (item.type === 'weapon') {
|
} else if (item.type === 'weapon') {
|
||||||
if (event.currentTarget.classList.contains('primary-weapon-section')) {
|
if (event.currentTarget.classList.contains('primary-weapon-section')) {
|
||||||
|
|
|
||||||
|
|
@ -361,7 +361,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mapAdvancementFeatures(actor, config) {
|
mapAdvancementFeatures(actor, config) {
|
||||||
if (!actor.system.subclass) return { foundation: null, advancements: [] };
|
if (!actor.system.class.value || !actor.system.class.subclass) return { foundation: null, advancements: [] };
|
||||||
|
|
||||||
const { subclass, multiclassSubclass } = actor.system.subclassFeatures;
|
const { subclass, multiclassSubclass } = actor.system.subclassFeatures;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { getTier } from '../../helpers/utils.mjs';
|
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||||
|
|
||||||
|
|
@ -52,4 +51,38 @@ export default class DHClass extends BaseDataItem {
|
||||||
isMulticlass: new fields.BooleanField({ initial: false })
|
isMulticlass: new fields.BooleanField({ initial: false })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _preCreate(data, options, user) {
|
||||||
|
const allowed = await super._preCreate(data, options, user);
|
||||||
|
if (allowed === false) return;
|
||||||
|
|
||||||
|
if (this.actor?.type === 'pc') {
|
||||||
|
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
|
||||||
|
if (foundry.utils.getProperty(this.actor, path)) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.ClassAlreadySelected'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onCreate(data, options, userId) {
|
||||||
|
super._onCreate(data, options, userId);
|
||||||
|
if (options.parent?.type === 'pc') {
|
||||||
|
const path = `system.${data.system.isMulticlass ? 'multiclass.value' : 'class.value'}`;
|
||||||
|
options.parent.update({ [path]: `${options.parent.uuid}.Item.${data._id}` });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDelete(options, userId) {
|
||||||
|
super._onDelete(options, userId);
|
||||||
|
|
||||||
|
if (options.parent?.type === 'pc') {
|
||||||
|
const path = `system.${this.isMulticlass ? 'multiclass' : 'class'}`;
|
||||||
|
options.parent.update({
|
||||||
|
[`${path}.value`]: null
|
||||||
|
});
|
||||||
|
|
||||||
|
foundry.utils.getProperty(options.parent, `${path}.subclass`)?.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import { getTier } from '../../helpers/utils.mjs';
|
|
||||||
import BaseDataItem from './base.mjs';
|
import BaseDataItem from './base.mjs';
|
||||||
|
|
||||||
export default class DHSubclass extends BaseDataItem {
|
export default class DHSubclass extends BaseDataItem {
|
||||||
|
|
@ -59,4 +58,42 @@ export default class DHSubclass extends BaseDataItem {
|
||||||
isMulticlass: new fields.BooleanField({ initial: false })
|
isMulticlass: new fields.BooleanField({ initial: false })
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _preCreate(data, options, user) {
|
||||||
|
const allowed = await super._preCreate(data, options, user);
|
||||||
|
if (allowed === false) return;
|
||||||
|
|
||||||
|
if (this.actor?.type === 'pc') {
|
||||||
|
const path = data.system.isMulticlass ? 'system.multiclass' : 'system.class';
|
||||||
|
const classData = foundry.utils.getProperty(this.actor, path);
|
||||||
|
if (!classData.value) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.MissingClass'));
|
||||||
|
return false;
|
||||||
|
} else if (classData.subclass) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.SubclassAlreadySelected'));
|
||||||
|
return false;
|
||||||
|
} else if (classData.value.system.subclasses.every(x => x.uuid !== `Item.${data._id}`)) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.SubclassNotInClass'));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onCreate(data, options, userId) {
|
||||||
|
super._onCreate(data, options, userId);
|
||||||
|
|
||||||
|
if (options.parent?.type === 'pc') {
|
||||||
|
const path = `system.${data.system.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`;
|
||||||
|
options.parent.update({ [path]: `${options.parent.uuid}.Item.${data._id}` });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_onDelete(options, userId) {
|
||||||
|
super._onDelete(options, userId);
|
||||||
|
|
||||||
|
if (options.parent?.type === 'pc') {
|
||||||
|
const path = `system.${this.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`;
|
||||||
|
options.parent.update({ [path]: null });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,84 +1,6 @@
|
||||||
export default class DhpItem extends Item {
|
export default class DhpItem extends Item {
|
||||||
async _preCreate(data, changes, user) {
|
|
||||||
const allowed = await super._preCreate(data, changes, user);
|
|
||||||
if (allowed === false) return;
|
|
||||||
|
|
||||||
if (data.type === 'class') {
|
|
||||||
if (this.parent?.type === 'pc') {
|
|
||||||
const path = data.system.isMulticlass ? 'system.multiclass.value' : 'system.class.value';
|
|
||||||
if (foundry.utils.getProperty(this.parent, path)) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.ClassAlreadySelected'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (data.type === 'subclass') {
|
|
||||||
if (this.parent?.type === 'pc') {
|
|
||||||
const path = data.system.isMulticlass ? 'system.multiclass' : 'system.class';
|
|
||||||
const classData = foundry.utils.getProperty(this.parent, path);
|
|
||||||
if (!classData.value) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.MissingClass'));
|
|
||||||
return false;
|
|
||||||
} else if (classData.subclass) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.SubclassAlreadySelected'));
|
|
||||||
return false;
|
|
||||||
} else if (
|
|
||||||
classData.value.system.subclasses.every(x => `${this.parent.uuid}.${x.uuid}` !== this.uuid)
|
|
||||||
) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.Item.Errors.SubclassNotInClass'));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async _onCreateOperation(documents, operation, user) {
|
|
||||||
await super._onCreateOperation(documents, operation, user);
|
|
||||||
for (var document of documents) {
|
|
||||||
if (document.type === 'class') {
|
|
||||||
if (operation.parent?.type === 'pc') {
|
|
||||||
const path = `system.${document.system.isMulticlass ? 'multiclass.value' : 'class.value'}`;
|
|
||||||
await operation.parent.update({ [path]: document.uuid });
|
|
||||||
}
|
|
||||||
} else if (document.type === 'subclass') {
|
|
||||||
if (operation.parent?.type === 'pc') {
|
|
||||||
const path = `system.${document.system.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`;
|
|
||||||
await operation.parent.update({ [path]: document.uuid });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async _onDeleteOperation(documents, operation, user) {
|
|
||||||
await super._onDeleteOperation(documents, operation, user);
|
|
||||||
for (var document of documents) {
|
|
||||||
if (document.type === 'class') {
|
|
||||||
if (operation.parent?.type === 'pc') {
|
|
||||||
const path = `system.${document.system.isMulticlass ? 'multiclass' : 'class'}`;
|
|
||||||
await operation.parent.update({
|
|
||||||
[path]: {
|
|
||||||
class: null,
|
|
||||||
subclass: null
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} else if (document.type === 'subclass') {
|
|
||||||
if (operation.parent?.type === 'pc') {
|
|
||||||
const path = `system.${document.system.isMulticlass ? 'multiclass.subclass' : 'class.subclass'}`;
|
|
||||||
await operation.parent.update({ [path]: null });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
prepareData() {
|
prepareData() {
|
||||||
super.prepareData();
|
super.prepareData();
|
||||||
|
|
||||||
if (this.type === 'class') {
|
|
||||||
// Bad. Make this better.
|
|
||||||
// this.system.domains = CONFIG.daggerheart.DOMAIN.classDomainMap[Object.keys(CONFIG.daggerheart.DOMAIN.classDomainMap).find(x => x === this.name.toLowerCase())];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<a
|
<a
|
||||||
class='effect-control'
|
class='effect-control'
|
||||||
data-action='editFeature'
|
data-action='editFeature'
|
||||||
data-feature={{feature.uuid}}
|
data-feature='{{feature.uuid}}'
|
||||||
data-tooltip='{{localize "DAGGERHEART.Tooltip.openItemWorld"}}'
|
data-tooltip='{{localize "DAGGERHEART.Tooltip.openItemWorld"}}'
|
||||||
>
|
>
|
||||||
<i class="fa-solid fa-globe"></i>
|
<i class="fa-solid fa-globe"></i>
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
<a
|
<a
|
||||||
class='effect-control'
|
class='effect-control'
|
||||||
data-action='deleteFeature'
|
data-action='deleteFeature'
|
||||||
data-feature={{feature.uuid}}
|
data-feature='{{feature.uuid}}'
|
||||||
data-tooltip='{{localize "DAGGERHEART.Tooltip.delete"}}'
|
data-tooltip='{{localize "DAGGERHEART.Tooltip.delete"}}'
|
||||||
>
|
>
|
||||||
<i class='fas fa-trash'></i>
|
<i class='fas fa-trash'></i>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue