mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +02:00
Change to uuid approach
This commit is contained in:
parent
20f42e8a0d
commit
a5db9371c6
8 changed files with 44 additions and 73 deletions
|
|
@ -3164,7 +3164,6 @@
|
||||||
"noSelectionsLeft": "Nothing more to select!",
|
"noSelectionsLeft": "Nothing more to select!",
|
||||||
"alreadySelectedClass": "You already have that class!",
|
"alreadySelectedClass": "You already have that class!",
|
||||||
"classAlreadySelected": "The character already has a class",
|
"classAlreadySelected": "The character already has a class",
|
||||||
"classMissingIdentifier": "The class hasn't set up an identifier",
|
|
||||||
"subclassAlreadySelected": "The character already has a subclass for that class.",
|
"subclassAlreadySelected": "The character already has a subclass for that class.",
|
||||||
"noClassSelected": "Your character has no class selected!",
|
"noClassSelected": "Your character has no class selected!",
|
||||||
"lacksDomain": "Your character doesn't have the domain of the card!",
|
"lacksDomain": "Your character doesn't have the domain of the card!",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { sortBy } from '../../../helpers/utils.mjs';
|
||||||
import DHBaseItemSheet from '../api/base-item.mjs';
|
import DHBaseItemSheet from '../api/base-item.mjs';
|
||||||
|
|
||||||
const { TextEditor } = foundry.applications.ux;
|
const { TextEditor } = foundry.applications.ux;
|
||||||
|
|
@ -9,8 +10,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
position: { width: 700 },
|
position: { width: 700 },
|
||||||
actions: {
|
actions: {
|
||||||
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
|
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
|
||||||
removeSuggestedItem: ClassSheet.#removeSuggestedItem,
|
removeSuggestedItem: ClassSheet.#removeSuggestedItem
|
||||||
resetIdentifier: ClassSheet.#resetIdentifier
|
|
||||||
},
|
},
|
||||||
tagifyConfigs: [
|
tagifyConfigs: [
|
||||||
{
|
{
|
||||||
|
|
@ -105,10 +105,10 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
async _prepareContext(_options) {
|
async _prepareContext(options) {
|
||||||
const context = await super._prepareContext(_options);
|
const context = await super._prepareContext(options);
|
||||||
context.domains = this.document.system.domains;
|
context.domains = this.document.system.domains;
|
||||||
context.subclasses = await this.document.system.getSubclasses();
|
context.subclasses = await this.document.system.fetchSubclasses();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -190,12 +190,6 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
static async #removeItemFromCollection(_event, element) {
|
static async #removeItemFromCollection(_event, element) {
|
||||||
const { uuid, target } = element.dataset;
|
const { uuid, target } = element.dataset;
|
||||||
const prop = foundry.utils.getProperty(this.document.system, target);
|
const prop = foundry.utils.getProperty(this.document.system, target);
|
||||||
|
|
||||||
if (target === 'subclasses') {
|
|
||||||
const subclass = await foundry.utils.fromUuid(uuid);
|
|
||||||
await subclass?.update({ 'system.linkedClass': null });
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.document.update({ [`system.${target}`]: prop.filter(i => i && i.uuid !== uuid).map(x => x.uuid) });
|
await this.document.update({ [`system.${target}`]: prop.filter(i => i && i.uuid !== uuid).map(x => x.uuid) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,10 +202,4 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
const { target } = element.dataset;
|
const { target } = element.dataset;
|
||||||
await this.document.update({ [`system.characterGuide.${target}`]: null });
|
await this.document.update({ [`system.characterGuide.${target}`]: null });
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #resetIdentifier() {
|
|
||||||
const document = this.document;
|
|
||||||
const initial = document.system.schema.fields.identifier.getInitialValue(document._source);
|
|
||||||
document.update({ 'system.identifier': initial });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,22 +41,27 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
||||||
return this.document.system.features.map(x => x.item);
|
return this.document.system.features.map(x => x.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _prepareContext(options) {
|
||||||
|
const context = await super._prepareContext(options);
|
||||||
|
if (this.document.system.linkedClass) {
|
||||||
|
context.class = (await fromUuid(this.document.system.linkedClass)) ?? {
|
||||||
|
name: 'Missing Class',
|
||||||
|
img: 'systems/daggerheart/assets/icons/documents/items/laurel-crown.svg',
|
||||||
|
missing: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
}
|
||||||
|
|
||||||
async _onDrop(event) {
|
async _onDrop(event) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const data = TextEditor.getDragEventData(event);
|
const data = TextEditor.getDragEventData(event);
|
||||||
const item = await fromUuid(data.uuid);
|
const item = await fromUuid(data.uuid);
|
||||||
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
||||||
if (itemType === 'class') {
|
if (itemType === 'class') {
|
||||||
const identifier = item.system.identifier;
|
const uuid = item._stats.compendiumSource ?? item.uuid;
|
||||||
if (!identifier) {
|
if (this.document.system.linkedClass !== uuid) {
|
||||||
return ui.notifications.error(
|
await this.document.update({ 'system.linkedClass': uuid });
|
||||||
game.i18n.localize('DAGGERHEART.UI.Notifications.classMissingIdentifier')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.document.system.classLink.identifier !== identifier) {
|
|
||||||
const { img, name } = item;
|
|
||||||
await this.document.update({ 'system.classLink': { identifier, img, name } });
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import BaseDataItem from './base.mjs';
|
||||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||||
import ItemLinkFields from '../fields/itemLinkFields.mjs';
|
import ItemLinkFields from '../fields/itemLinkFields.mjs';
|
||||||
import { addLinkedItemsDiff, camelize, getFeaturesHTMLData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
import { addLinkedItemsDiff, getFeaturesHTMLData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
export default class DHClass extends BaseDataItem {
|
export default class DHClass extends BaseDataItem {
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
|
@ -50,10 +50,7 @@ export default class DHClass extends BaseDataItem {
|
||||||
}),
|
}),
|
||||||
backgroundQuestions: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
backgroundQuestions: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
||||||
connections: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
connections: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
||||||
isMulticlass: new fields.BooleanField({ initial: false }),
|
isMulticlass: new fields.BooleanField({ initial: false })
|
||||||
identifier: new fields.StringField({ blank: false, initial: obj => camelize(obj?.name ?? '') }),
|
|
||||||
/* Subclasses is legacy. If we can safetely migrate it away at some point we could remove it*/
|
|
||||||
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false })
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,18 +69,14 @@ export default class DHClass extends BaseDataItem {
|
||||||
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.class).map(x => x.item);
|
return this.features.filter(x => x.type === CONFIG.DH.ITEM.featureSubTypes.class).map(x => x.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSubclasses() {
|
async fetchSubclasses() {
|
||||||
const oldLinkedSubclasses = this.subclasses;
|
const uuids = [this.parent.uuid, this.parent._stats?.compendiumSource].filter(u => !!u);
|
||||||
if (oldLinkedSubclasses.length) return oldLinkedSubclasses;
|
const subclasses = game.items.filter(x => x.type === 'subclass' && uuids.includes(x.system.linkedClass));
|
||||||
|
|
||||||
const subclasses = game.items.filter(
|
|
||||||
x => x.type === 'subclass' && x.system.classLink.identifier === this.identifier
|
|
||||||
);
|
|
||||||
for (const pack of game.packs) {
|
for (const pack of game.packs) {
|
||||||
const indexes = await pack.getIndex({ fields: ['system.classLink.identifier'] });
|
const indexes = await pack.getIndex({ fields: ['system.linkedClass'] });
|
||||||
for (const index of indexes) {
|
for (const index of indexes) {
|
||||||
if (index.type !== 'subclass') continue;
|
if (index.type !== 'subclass') continue;
|
||||||
if (index.system?.classLink?.identifier !== this.identifier) continue;
|
if (!uuids.includes(index.system?.linkedClass)) continue;
|
||||||
if (subclasses.find(x => x.uuid === index.uuid)) continue;
|
if (subclasses.find(x => x.uuid === index.uuid)) continue;
|
||||||
|
|
||||||
const subclass = await foundry.utils.fromUuid(index.uuid);
|
const subclass = await foundry.utils.fromUuid(index.uuid);
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,7 @@ export default class DHSubclass extends BaseDataItem {
|
||||||
features: new ItemLinkFields(),
|
features: new ItemLinkFields(),
|
||||||
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
|
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
|
||||||
isMulticlass: new fields.BooleanField({ initial: false }),
|
isMulticlass: new fields.BooleanField({ initial: false }),
|
||||||
classLink: new fields.SchemaField({
|
linkedClass: new fields.DocumentUUIDField({ type: 'Item', nullable: true, initial: null })
|
||||||
identifier: new fields.StringField({ nullable: true, initial: null }),
|
|
||||||
name: new fields.StringField(),
|
|
||||||
img: new fields.StringField()
|
|
||||||
}),
|
|
||||||
/* Linked class is legacy. If we can safetely migrate it away at some point we could remove it */
|
|
||||||
linkedClass: new ForeignDocumentUUIDField({ type: 'Item', nullable: true, initial: null })
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,19 +41,8 @@
|
||||||
data-item-uuid={{subclass.uuid}}
|
data-item-uuid={{subclass.uuid}}
|
||||||
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
||||||
>
|
>
|
||||||
<i class="fa-solid fa-globe"></i>
|
<i class="fa-solid fa-globe" inert></i>
|
||||||
</a>
|
</a>
|
||||||
{{#if document.system.subclasses}}
|
|
||||||
<a
|
|
||||||
class='effect-control'
|
|
||||||
data-action='removeItemFromCollection'
|
|
||||||
data-target="subclasses"
|
|
||||||
data-uuid="{{subclass.uuid}}"
|
|
||||||
data-tooltip='{{localize "CONTROLS.CommonDelete"}}'
|
|
||||||
>
|
|
||||||
<i class='fas fa-trash'></i>
|
|
||||||
</a>
|
|
||||||
{{/if}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,6 @@
|
||||||
data-tab='{{tabs.settings.id}}'
|
data-tab='{{tabs.settings.id}}'
|
||||||
data-group='{{tabs.settings.group}}'
|
data-group='{{tabs.settings.group}}'
|
||||||
>
|
>
|
||||||
<fieldset class="two-columns">
|
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.general"}}</legend>
|
|
||||||
<span>{{localize "DAGGERHEART.ITEMS.FIELDS.identifier.label"}}</span>
|
|
||||||
<div class="flexrow">
|
|
||||||
{{formInput systemFields.identifier value=source.system.identifier}}
|
|
||||||
<button class="plain inline-control icon fa-solid fa-rotate-right" data-action="resetIdentifier"></button>
|
|
||||||
</div>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<fieldset class="two-columns even">
|
<fieldset class="two-columns even">
|
||||||
<legend>{{localize tabs.settings.label}}</legend>
|
<legend>{{localize tabs.settings.label}}</legend>
|
||||||
{{formGroup systemFields.hitPoints value=source.system.hitPoints localize=true}}
|
{{formGroup systemFields.hitPoints value=source.system.hitPoints localize=true}}
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,23 @@
|
||||||
>
|
>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{{localize "TYPES.Item.class"}}</legend>
|
<legend>{{localize "TYPES.Item.class"}}</legend>
|
||||||
{{#if document.system.classLink.identifier}}
|
{{#if class}}
|
||||||
<div class="feature-list">
|
<div class="feature-list">
|
||||||
<li class="feature-line">
|
<li class="feature-line">
|
||||||
<img class="image" src="{{document.system.classLink.img}}" />
|
<img class="image" src="{{class.img}}" />
|
||||||
<span>{{document.system.classLink.name}}</span>
|
<span>{{class.name}} {{#if class.missing}}<i class="fa-solid fa-link-slash" inert></i>{{/if}}</span>
|
||||||
|
{{#unless class.missing}}
|
||||||
|
<div class='controls'>
|
||||||
|
<a
|
||||||
|
class='effect-control'
|
||||||
|
data-action='editDoc'
|
||||||
|
data-item-uuid={{class.uuid}}
|
||||||
|
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-globe" inert></i>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
{{/unless}}
|
||||||
</li>
|
</li>
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
{{else}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue