mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Fixed relinking of Features from items created on Character
This commit is contained in:
parent
0cf9e1d17c
commit
3dc4daffc3
7 changed files with 96 additions and 51 deletions
|
|
@ -2221,6 +2221,7 @@
|
|||
"tooHighLevel": "You cannot raise the character level past the maximum",
|
||||
"tooLowLevel": "You cannot lower the character level below starting level",
|
||||
"subclassNotInClass": "This subclass does not belong to your selected class.",
|
||||
"subclassNotInMulticlass": "This subclass does not belong to your selected multiclass.",
|
||||
"missingClass": "You don't have a class selected yet.",
|
||||
"missingMulticlass": "Missing multiclass",
|
||||
"wrongDomain": "The card isn't from one of your class domains.",
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export default class MulticlassChoiceDialog extends HandlebarsApplicationMixin(A
|
|||
description: game.i18n.localize(domain.description),
|
||||
src: domain.src,
|
||||
selected: value === this.selectedDomain,
|
||||
disabled: this.actor.system.domains.includes(domain)
|
||||
disabled: this.actor.system.domains.includes(value)
|
||||
};
|
||||
});
|
||||
context.multiclassDisabled = !this.selectedDomain;
|
||||
|
|
|
|||
|
|
@ -407,11 +407,16 @@ export default class DhCharacter extends BaseDataActor {
|
|||
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
|
||||
if (this.class.subclass) {
|
||||
const subclassState = this.class.subclass.system.featureState;
|
||||
const subType = item.system.subType;
|
||||
const subclass =
|
||||
item.system.identifier === 'multiclass' ? this.multiclass.subclass : this.class.subclass;
|
||||
const featureType = subclass
|
||||
? (subclass.system.features.find(x => x.item?.uuid === item.uuid)?.type ?? null)
|
||||
: null;
|
||||
|
||||
if (
|
||||
subType === CONFIG.DH.ITEM.featureSubTypes.foundation ||
|
||||
(subType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) ||
|
||||
(subType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3)
|
||||
featureType === CONFIG.DH.ITEM.featureSubTypes.foundation ||
|
||||
(featureType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) ||
|
||||
(featureType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3)
|
||||
) {
|
||||
subclassFeatures.push(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -125,18 +125,36 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
}
|
||||
|
||||
if (this.actor && this.actor.type === 'character' && this.features) {
|
||||
const featureUpdates = {};
|
||||
for (let f of this.features) {
|
||||
const feature = f.item ?? f;
|
||||
const createData = foundry.utils.mergeObject(feature.toObject(), {
|
||||
system: {
|
||||
originItemType: this.parent.type,
|
||||
originId: data._id,
|
||||
identifier: feature.identifier,
|
||||
subType: feature.item ? feature.type : undefined
|
||||
}
|
||||
}, { inplace: false });
|
||||
await this.actor.createEmbeddedDocuments('Item', [createData]);
|
||||
const createData = foundry.utils.mergeObject(
|
||||
feature.toObject(),
|
||||
{
|
||||
system: {
|
||||
originItemType: this.parent.type,
|
||||
originId: data._id,
|
||||
identifier: this.isMulticlass ? 'multiclass' : null,
|
||||
subType: feature.item ? feature.type : undefined
|
||||
}
|
||||
},
|
||||
{ inplace: false }
|
||||
);
|
||||
const [doc] = await this.actor.createEmbeddedDocuments('Item', [createData]);
|
||||
|
||||
if (!featureUpdates.features)
|
||||
featureUpdates.features = this.features.map(x => (x.item ? { ...x, item: x.item.uuid } : x.uuid));
|
||||
|
||||
if (f.item) {
|
||||
const existingFeature = featureUpdates.features.find(x => x.item === f.item.uuid);
|
||||
existingFeature.item = doc.uuid;
|
||||
} else {
|
||||
const replaceIndex = featureUpdates.features.findIndex(x => x === f.uuid);
|
||||
featureUpdates.features.splice(replaceIndex, 1, doc.uuid);
|
||||
}
|
||||
}
|
||||
|
||||
await this.updateSource(featureUpdates);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -41,9 +41,6 @@ export default class DHSubclass extends BaseDataItem {
|
|||
}
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
const allowed = await super._preCreate(data, options, user);
|
||||
if (allowed === false) return;
|
||||
|
||||
if (this.actor?.type === 'character') {
|
||||
if (this.actor.system.class.subclass) {
|
||||
if (this.actor.system.multiclass.subclass) {
|
||||
|
|
@ -55,6 +52,17 @@ export default class DHSubclass extends BaseDataItem {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (
|
||||
this.actor.system.multiclass.value.system.subclasses.every(
|
||||
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
|
||||
)
|
||||
) {
|
||||
ui.notifications.error(
|
||||
game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInMulticlass')
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
await this.updateSource({ isMulticlass: true });
|
||||
}
|
||||
} else {
|
||||
|
|
@ -62,8 +70,19 @@ export default class DHSubclass extends BaseDataItem {
|
|||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.UI.Notifications.missingClass'));
|
||||
return false;
|
||||
}
|
||||
if (
|
||||
this.actor.system.class.value.system.subclasses.every(
|
||||
x => x.uuid !== (data.uuid ?? `Item.${data._id}`)
|
||||
)
|
||||
) {
|
||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.subclassNotInClass'));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const allowed = await super._preCreate(data, options, user);
|
||||
if (allowed === false) return;
|
||||
}
|
||||
|
||||
_onCreate(data, options, userId) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<div class="multiclass-domains-container">
|
||||
{{#each domainChoices as | choice |}}
|
||||
<div class="domain-choice-container">
|
||||
<button data-action="selectDomain" data-domain="{{choice.value}}" {{#if choice.selected}}class="selected"{{/if}}>
|
||||
<button data-action="selectDomain" data-domain="{{choice.value}}" {{#if choice.selected}}class="selected"{{/if}} {{disabled choice.disabled}}>
|
||||
<label>{{choice.label}}</label>
|
||||
<img src="{{choice.src}}" />
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -23,38 +23,40 @@
|
|||
</fieldset>
|
||||
</div>
|
||||
|
||||
<fieldset>
|
||||
<legend>{{localize "TYPES.Item.subclass"}}</legend>
|
||||
<div class="feature-list">
|
||||
{{#each source.system.subclasses as |subclass index|}}
|
||||
<li class='feature-item'>
|
||||
<div class='feature-line'>
|
||||
<img class='image' src='{{subclass.img}}' />
|
||||
<h4>
|
||||
{{subclass.name}}
|
||||
</h4>
|
||||
<div class='controls'>
|
||||
<a
|
||||
class='effect-control'
|
||||
data-action='editDoc'
|
||||
data-item-uuid={{subclass.uuid}}
|
||||
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
||||
>
|
||||
<i class="fa-solid fa-globe"></i>
|
||||
</a>
|
||||
<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>
|
||||
{{#unless (eq document.parent.type 'character')}}
|
||||
<fieldset>
|
||||
<legend>{{localize "TYPES.Item.subclass"}}</legend>
|
||||
<div class="feature-list">
|
||||
{{#each source.system.subclasses as |subclass index|}}
|
||||
<li class='feature-item'>
|
||||
<div class='feature-line'>
|
||||
<img class='image' src='{{subclass.img}}' />
|
||||
<h4>
|
||||
{{subclass.name}}
|
||||
</h4>
|
||||
<div class='controls'>
|
||||
<a
|
||||
class='effect-control'
|
||||
data-action='editDoc'
|
||||
data-item-uuid={{subclass.uuid}}
|
||||
data-tooltip='{{localize "DAGGERHEART.UI.Tooltip.openItemWorld"}}'
|
||||
>
|
||||
<i class="fa-solid fa-globe"></i>
|
||||
</a>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
{{/each}}
|
||||
</div>
|
||||
</fieldset>
|
||||
</li>
|
||||
{{/each}}
|
||||
</div>
|
||||
</fieldset>
|
||||
{{/unless}}
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue