mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-06-06 04:44:16 +02:00
Continue work on updating identifier
This commit is contained in:
parent
d2ec5283a0
commit
20f42e8a0d
12 changed files with 122 additions and 69 deletions
|
|
@ -2532,6 +2532,9 @@
|
||||||
"recovery": { "label": "Recovery" },
|
"recovery": { "label": "Recovery" },
|
||||||
"type": { "label": "Type" },
|
"type": { "label": "Type" },
|
||||||
"value": { "label": "Value" }
|
"value": { "label": "Value" }
|
||||||
|
},
|
||||||
|
"identifier": {
|
||||||
|
"label": "Identifier"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Ancestry": {
|
"Ancestry": {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ 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: [
|
||||||
{
|
{
|
||||||
|
|
@ -107,6 +108,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
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();
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,19 +131,7 @@ export default class ClassSheet extends DHBaseItemSheet {
|
||||||
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
const itemType = data.type === 'ActiveEffect' ? data.type : item.type;
|
||||||
const target = event.target.closest('fieldset.drop-section');
|
const target = event.target.closest('fieldset.drop-section');
|
||||||
|
|
||||||
if (itemType === 'subclass') {
|
if (['feature', 'ActiveEffect'].includes(itemType)) {
|
||||||
if (!this.document.system.identifier) {
|
|
||||||
return ui.notifications.error(
|
|
||||||
game.i18n.localize('DAGGERHEART.UI.Notifications.classMissingIdentifier')
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.system.classIdentifiers.includes(this.document.system.identifier)) return;
|
|
||||||
|
|
||||||
await item.update({
|
|
||||||
'system.classIdentifiers': [...item.system.classIdentifiers, this.document.system.identifier]
|
|
||||||
});
|
|
||||||
} else if (['feature', 'ActiveEffect'].includes(itemType)) {
|
|
||||||
super._onDrop(event);
|
super._onDrop(event);
|
||||||
} else if (this.document.parent?.type !== 'character') {
|
} else if (this.document.parent?.type !== 'character') {
|
||||||
if (itemType === 'weapon') {
|
if (itemType === 'weapon') {
|
||||||
|
|
@ -218,4 +208,10 @@ 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 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,4 +40,27 @@ export default class SubclassSheet extends DHBaseItemSheet {
|
||||||
get relatedDocs() {
|
get relatedDocs() {
|
||||||
return this.document.system.features.map(x => x.item);
|
return this.document.system.features.map(x => x.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 } });
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return super._onDrop(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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, getFeaturesHTMLData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
import { addLinkedItemsDiff, camelize, getFeaturesHTMLData, updateLinkedItemApps } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
export default class DHClass extends BaseDataItem {
|
export default class DHClass extends BaseDataItem {
|
||||||
/** @inheritDoc */
|
/** @inheritDoc */
|
||||||
|
|
@ -51,7 +51,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(),
|
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 is legacy. If we can safetely migrate it away at some point we could remove it*/
|
||||||
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false })
|
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false })
|
||||||
};
|
};
|
||||||
|
|
@ -73,26 +73,23 @@ export default class DHClass extends BaseDataItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSubclasses() {
|
async getSubclasses() {
|
||||||
const oldLinkedSubclasses = this.subclasses.filter(x => x);
|
const oldLinkedSubclasses = this.subclasses;
|
||||||
if (!this.identifier) return oldLinkedSubclasses;
|
if (oldLinkedSubclasses.length) return oldLinkedSubclasses;
|
||||||
|
|
||||||
const subclasses = game.items.filter(
|
const subclasses = game.items.filter(
|
||||||
x => x.type === 'subclass' && x.system.classIdentifiers.includes(this.identifier)
|
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.classIdentifiers'] });
|
const indexes = await pack.getIndex({ fields: ['system.classLink.identifier'] });
|
||||||
for (const index of indexes) {
|
for (const index of indexes) {
|
||||||
if (
|
if (index.type !== 'subclass') continue;
|
||||||
index.type === 'subclass' &&
|
if (index.system?.classLink?.identifier !== this.identifier) continue;
|
||||||
(index.system.classIdentifiers ?? []).includes(
|
if (subclasses.find(x => x.uuid === index.uuid)) continue;
|
||||||
this.identifier && !subclasses.find(x => x.uuid === index.uuid)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
const subclass = await foundry.utils.fromUuid(index.uuid);
|
const subclass = await foundry.utils.fromUuid(index.uuid);
|
||||||
subclasses.push(subclass);
|
subclasses.push(subclass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return subclasses;
|
return subclasses;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,11 @@ 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 }),
|
||||||
classIdentifiers: new fields.ArrayField(new fields.StringField({ nullable: 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 */
|
/* 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 ForeignDocumentUUIDField({ type: 'Item', nullable: true, initial: null })
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -841,3 +841,11 @@ export function createShallowProxy(obj) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function camelize(str) {
|
||||||
|
return str
|
||||||
|
.replace(/(?:^\w|[A-Z]|\b\w)/g, (part, index) => {
|
||||||
|
return index === 0 ? part.toLowerCase() : part.toUpperCase();
|
||||||
|
})
|
||||||
|
.replace(/\s+/g, '');
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
&:last-child {
|
&:last-child {
|
||||||
margin-bottom: 0px;
|
margin-bottom: 0px;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
.feature-line {
|
.feature-line {
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
@ -45,5 +46,4 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,8 @@
|
||||||
font-family: @font-body;
|
font-family: @font-body;
|
||||||
color: light-dark(@chat-blue-bg, @beige-50);
|
color: light-dark(@chat-blue-bg, @beige-50);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button.plain.inline-control {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,7 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>{{localize "TYPES.Item.subclass"}}</legend>
|
<legend>{{localize "TYPES.Item.subclass"}}</legend>
|
||||||
<div class="feature-list">
|
<div class="feature-list">
|
||||||
{{#unless source.system.subclasses}}
|
{{#each subclasses as |subclass index|}}
|
||||||
<div class="drag-area">{{localize "DAGGERHEART.GENERAL.missingDragDropThing" thing=(localize "DAGGERHEART.GENERAL.subclasses")}}</div>
|
|
||||||
{{/unless}}
|
|
||||||
{{#each source.system.subclasses as |subclass index|}}
|
|
||||||
<li class='feature-item'>
|
<li class='feature-item'>
|
||||||
<div class='feature-line'>
|
<div class='feature-line'>
|
||||||
<img class='image' src='{{subclass.img}}' />
|
<img class='image' src='{{subclass.img}}' />
|
||||||
|
|
@ -46,6 +43,7 @@
|
||||||
>
|
>
|
||||||
<i class="fa-solid fa-globe"></i>
|
<i class="fa-solid fa-globe"></i>
|
||||||
</a>
|
</a>
|
||||||
|
{{#if document.system.subclasses}}
|
||||||
<a
|
<a
|
||||||
class='effect-control'
|
class='effect-control'
|
||||||
data-action='removeItemFromCollection'
|
data-action='removeItemFromCollection'
|
||||||
|
|
@ -55,6 +53,7 @@
|
||||||
>
|
>
|
||||||
<i class='fas fa-trash'></i>
|
<i class='fas fa-trash'></i>
|
||||||
</a>
|
</a>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,6 @@
|
||||||
<div class='item-info'>
|
<div class='item-info'>
|
||||||
<h1 class='item-name'><input type='text' name='name' value='{{source.name}}' /></h1>
|
<h1 class='item-name'><input type='text' name='name' value='{{source.name}}' /></h1>
|
||||||
<div class='item-description'>
|
<div class='item-description'>
|
||||||
<h3 class="flexrow">
|
|
||||||
{{localize 'TYPES.Item.class'}}
|
|
||||||
{{formInput systemFields.identifier value=source.system.identifier}}
|
|
||||||
</h3>
|
|
||||||
<h3 class="form-fields domain-section">
|
<h3 class="form-fields domain-section">
|
||||||
<span>{{localize "DAGGERHEART.GENERAL.Domain.plural"}}</span>
|
<span>{{localize "DAGGERHEART.GENERAL.Domain.plural"}}</span>
|
||||||
<input class="domain-input" value="{{domains}}" />
|
<input class="domain-input" value="{{domains}}" />
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,15 @@
|
||||||
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}}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,20 @@
|
||||||
data-tab='{{tabs.features.id}}'
|
data-tab='{{tabs.features.id}}'
|
||||||
data-group='{{tabs.features.group}}'
|
data-group='{{tabs.features.group}}'
|
||||||
>
|
>
|
||||||
|
<fieldset>
|
||||||
|
<legend>{{localize "TYPES.Item.class"}}</legend>
|
||||||
|
{{#if document.system.classLink.identifier}}
|
||||||
|
<div class="feature-list">
|
||||||
|
<li class="feature-line">
|
||||||
|
<img class="image" src="{{document.system.classLink.img}}" />
|
||||||
|
<span>{{document.system.classLink.name}}</span>
|
||||||
|
</li>
|
||||||
|
</div>
|
||||||
|
{{else}}
|
||||||
|
<div class="drag-area">{{localize "DAGGERHEART.GENERAL.missingDragDropThing" thing=(localize "TYPES.Item.class")}}</div>
|
||||||
|
{{/if}}
|
||||||
|
</fieldset>
|
||||||
|
|
||||||
<fieldset class="drop-section" data-type="foundation">
|
<fieldset class="drop-section" data-type="foundation">
|
||||||
<legend>
|
<legend>
|
||||||
{{localize "DAGGERHEART.GENERAL.Tabs.foundation"}}
|
{{localize "DAGGERHEART.GENERAL.Tabs.foundation"}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue