Merge branch 'main' into 419-feature-add-createtagsmethods-for-documents-and-actions

This commit is contained in:
Joaquin Pereyra 2025-07-31 22:56:32 -03:00
commit 9a4d10429f
773 changed files with 72685 additions and 1139 deletions

View file

@ -71,13 +71,14 @@ export default class DHArmor extends AttachableItem {
for (var feature of added) {
const featureData = armorFeatures[feature.value];
if (featureData.effects?.length > 0) {
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
{
name: game.i18n.localize(featureData.label),
description: game.i18n.localize(featureData.description),
changes: featureData.effects.flatMap(x => x.changes)
}
]);
const embeddedItems = await this.parent.createEmbeddedDocuments(
'ActiveEffect',
featureData.effects.map(effect => ({
...effect,
name: game.i18n.localize(effect.name),
description: game.i18n.localize(effect.description)
}))
);
feature.effectIds = embeddedItems.map(x => x.id);
}
@ -93,6 +94,7 @@ export default class DHArmor extends AttachableItem {
description: game.i18n.localize(effect.description)
}))
);
feature.effectIds = [...(feature.effectIds ?? []), ...embeddedEffects.map(x => x.id)];
const cls = game.system.api.models.actions.actionsTypes[action.type];
const actionId = foundry.utils.randomID();

View file

@ -10,6 +10,7 @@
import { addLinkedItemsDiff, updateLinkedItemApps } from '../../helpers/utils.mjs';
import { ActionsField } from '../fields/actionField.mjs';
import FormulaField from '../fields/formulaField.mjs';
const fields = foundry.data.fields;
@ -48,7 +49,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
initial: CONFIG.DH.ITEM.itemResourceTypes.simple
}),
value: new fields.NumberField({ integer: true, min: 0, initial: 0 }),
max: new fields.StringField({ nullable: true, initial: null }),
max: new FormulaField({ nullable: true, initial: null, deterministic: true }),
icon: new fields.StringField(),
recovery: new fields.StringField({
choices: CONFIG.DH.GENERAL.refreshTypes,
@ -122,26 +123,21 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
this.updateSource({ actions: [action] });
}
}
_onCreate(data, _, userId) {
if (userId !== game.user.id) return;
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
this.actor.createEmbeddedDocuments(
'Item',
this.features.map(feature => ({
...(feature.item ?? feature),
system: {
...(feature.item?.system ?? feature.system),
originItemType: this.parent.type,
originId: data._id,
identifier: feature.identifier,
subType: feature.item ? feature.type : undefined
}
}))
);
if (this.actor && this.actor.type === 'character' && this.features) {
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]);
}
}
}
async _preDelete() {

View file

@ -118,13 +118,14 @@ export default class DHWeapon extends AttachableItem {
for (let weaponFeature of added) {
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
if (featureData.effects?.length > 0) {
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
{
name: game.i18n.localize(featureData.label),
description: game.i18n.localize(featureData.description),
changes: featureData.effects.flatMap(x => x.changes)
}
]);
const embeddedItems = await this.parent.createEmbeddedDocuments(
'ActiveEffect',
featureData.effects.map(effect => ({
...effect,
name: game.i18n.localize(effect.name),
description: game.i18n.localize(effect.description)
}))
);
weaponFeature.effectIds = embeddedItems.map(x => x.id);
}
@ -140,6 +141,10 @@ export default class DHWeapon extends AttachableItem {
description: game.i18n.localize(effect.description)
}))
);
weaponFeature.effectIds = [
...(weaponFeature.effectIds ?? []),
...embeddedEffects.map(x => x.id)
];
const cls = game.system.api.models.actions.actionsTypes[action.type];
const actionId = foundry.utils.randomID();