mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-05 20:34:15 +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!",
|
||||
"alreadySelectedClass": "You already have that 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.",
|
||||
"noClassSelected": "Your character has no class selected!",
|
||||
"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';
|
||||
|
||||
const { TextEditor } = foundry.applications.ux;
|
||||
|
|
@ -9,8 +10,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
position: { width: 700 },
|
||||
actions: {
|
||||
removeItemFromCollection: ClassSheet.#removeItemFromCollection,
|
||||
removeSuggestedItem: ClassSheet.#removeSuggestedItem,
|
||||
resetIdentifier: ClassSheet.#resetIdentifier
|
||||
removeSuggestedItem: ClassSheet.#removeSuggestedItem
|
||||
},
|
||||
tagifyConfigs: [
|
||||
{
|
||||
|
|
@ -105,10 +105,10 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
}
|
||||
|
||||
/**@inheritdoc */
|
||||
async _prepareContext(_options) {
|
||||
const context = await super._prepareContext(_options);
|
||||
async _prepareContext(options) {
|
||||
const context = await super._prepareContext(options);
|
||||
context.domains = this.document.system.domains;
|
||||
context.subclasses = await this.document.system.getSubclasses();
|
||||
context.subclasses = await this.document.system.fetchSubclasses();
|
||||
return context;
|
||||
}
|
||||
|
||||
|
|
@ -190,12 +190,6 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
static async #removeItemFromCollection(_event, element) {
|
||||
const { uuid, target } = element.dataset;
|
||||
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) });
|
||||
}
|
||||
|
||||
|
|
@ -208,10 +202,4 @@ export default class ClassSheet extends DHBaseItemSheet {
|
|||
const { target } = element.dataset;
|
||||
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);
|
||||
}
|
||||
|
||||
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) {
|
||||
event.stopPropagation();
|
||||
const data = TextEditor.getDragEventData(event);
|
||||
const item = await fromUuid(data.uuid);
|
||||
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
||||
if (itemType === 'class') {
|
||||
const identifier = item.system.identifier;
|
||||
if (!identifier) {
|
||||
return ui.notifications.error(
|
||||
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 } });
|
||||
const uuid = item._stats.compendiumSource ?? item.uuid;
|
||||
if (this.document.system.linkedClass !== uuid) {
|
||||
await this.document.update({ 'system.linkedClass': uuid });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import BaseDataItem from './base.mjs';
|
|||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.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 {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -50,10 +50,7 @@ export default class DHClass extends BaseDataItem {
|
|||
}),
|
||||
backgroundQuestions: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
||||
connections: new fields.ArrayField(new fields.StringField(), { initial: ['', '', ''] }),
|
||||
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 })
|
||||
isMulticlass: new fields.BooleanField({ initial: 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);
|
||||
}
|
||||
|
||||
async getSubclasses() {
|
||||
const oldLinkedSubclasses = this.subclasses;
|
||||
if (oldLinkedSubclasses.length) return oldLinkedSubclasses;
|
||||
|
||||
const subclasses = game.items.filter(
|
||||
x => x.type === 'subclass' && x.system.classLink.identifier === this.identifier
|
||||
);
|
||||
async fetchSubclasses() {
|
||||
const uuids = [this.parent.uuid, this.parent._stats?.compendiumSource].filter(u => !!u);
|
||||
const subclasses = game.items.filter(x => x.type === 'subclass' && uuids.includes(x.system.linkedClass));
|
||||
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) {
|
||||
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;
|
||||
|
||||
const subclass = await foundry.utils.fromUuid(index.uuid);
|
||||
|
|
|
|||
|
|
@ -28,13 +28,7 @@ export default class DHSubclass extends BaseDataItem {
|
|||
features: new ItemLinkFields(),
|
||||
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
|
||||
isMulticlass: new fields.BooleanField({ initial: false }),
|
||||
classLink: new fields.SchemaField({
|
||||
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 })
|
||||
linkedClass: new fields.DocumentUUIDField({ type: 'Item', nullable: true, initial: null })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,19 +41,8 @@
|
|||
data-item-uuid={{subclass.uuid}}
|
||||
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
||||
>
|
||||
<i class="fa-solid fa-globe"></i>
|
||||
<i class="fa-solid fa-globe" inert></i>
|
||||
</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>
|
||||
</li>
|
||||
|
|
|
|||
|
|
@ -3,15 +3,6 @@
|
|||
data-tab='{{tabs.settings.id}}'
|
||||
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">
|
||||
<legend>{{localize tabs.settings.label}}</legend>
|
||||
{{formGroup systemFields.hitPoints value=source.system.hitPoints localize=true}}
|
||||
|
|
|
|||
|
|
@ -5,11 +5,23 @@
|
|||
>
|
||||
<fieldset>
|
||||
<legend>{{localize "TYPES.Item.class"}}</legend>
|
||||
{{#if document.system.classLink.identifier}}
|
||||
{{#if class}}
|
||||
<div class="feature-list">
|
||||
<li class="feature-line">
|
||||
<img class="image" src="{{document.system.classLink.img}}" />
|
||||
<span>{{document.system.classLink.name}}</span>
|
||||
<img class="image" src="{{class.img}}" />
|
||||
<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>
|
||||
</div>
|
||||
{{else}}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue