Updated from special database update syntax to DataFieldOperators

This commit is contained in:
WBHarry 2026-01-31 18:31:10 +01:00
parent 9553f3387f
commit cd52aa8f9c
25 changed files with 42 additions and 45 deletions

View file

@ -554,7 +554,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
experiences: { experiences: {
...this.setup.experiences, ...this.setup.experiences,
...Object.keys(this.character.system.experiences).reduce((acc, key) => { ...Object.keys(this.character.system.experiences).reduce((acc, key) => {
acc[`-=${key}`] = null; acc[`${key}`] = _del;
return acc; return acc;
}, {}) }, {})
} }

View file

@ -77,8 +77,8 @@ export default class CharacterResetDialog extends HandlebarsApplicationMixin(App
if (!this.data.optional.portrait.keep) { if (!this.data.optional.portrait.keep) {
foundry.utils.setProperty(update, 'img', this.actor.schema.fields.img.initial(this.actor)); foundry.utils.setProperty(update, 'img', this.actor.schema.fields.img.initial(this.actor));
foundry.utils.setProperty(update, 'prototypeToken.==texture', {}); foundry.utils.setProperty(update, 'prototypeToken.texture', _replace({}));
foundry.utils.setProperty(update, 'prototypeToken.==ring', {}); foundry.utils.setProperty(update, 'prototypeToken.ring', _replace({}));
} }
if (this.data.optional.biography.keep) if (this.data.optional.biography.keep)
@ -89,7 +89,7 @@ export default class CharacterResetDialog extends HandlebarsApplicationMixin(App
const { system, ...rest } = update; const { system, ...rest } = update;
await this.actor.update({ await this.actor.update({
...rest, ...rest,
'==system': system ?? {} system: _replace(system ?? {})
}); });
const inventoryItemTypes = ['weapon', 'armor', 'consumable', 'loot']; const inventoryItemTypes = ['weapon', 'armor', 'consumable', 'loot'];

View file

@ -168,7 +168,7 @@ export default class TagTeamDialog extends HandlebarsApplicationMixin(Applicatio
} }
static async #removeMember(_, button) { static async #removeMember(_, button) {
const update = { [`members.-=${button.dataset.characterId}`]: null }; const update = { [`members.${button.dataset.characterId}`]: _del };
if (this.data.initiator.id === button.dataset.characterId) { if (this.data.initiator.id === button.dataset.characterId) {
update.iniator = { id: null }; update.iniator = { id: null };
} }

View file

@ -477,7 +477,7 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
const secondaryData = Object.keys( const secondaryData = Object.keys(
foundry.utils.getProperty(this.levelup, `${target.dataset.path}.secondaryData`) foundry.utils.getProperty(this.levelup, `${target.dataset.path}.secondaryData`)
).reduce((acc, key) => { ).reduce((acc, key) => {
acc[`-=${key}`] = null; acc[key] = _del;
return acc; return acc;
}, {}); }, {});
await this.levelup.updateSource({ await this.levelup.updateSource({
@ -511,9 +511,9 @@ export default class DhlevelUp extends HandlebarsApplicationMixin(ApplicationV2)
const current = foundry.utils.getProperty(this.levelup, `${basePath}.${button.dataset.option}`); const current = foundry.utils.getProperty(this.levelup, `${basePath}.${button.dataset.option}`);
if (Number(button.dataset.cost) > 1 || Object.keys(current).length === 1) { if (Number(button.dataset.cost) > 1 || Object.keys(current).length === 1) {
// Simple handling that doesn't cover potential Custom LevelTiers. // Simple handling that doesn't cover potential Custom LevelTiers.
update[`${basePath}.-=${button.dataset.option}`] = null; update[`${basePath}.${button.dataset.option}`] = _del;
} else { } else {
update[`${basePath}.${button.dataset.option}.-=${button.dataset.checkboxNr}`] = null; update[`${basePath}.${button.dataset.option}.${button.dataset.checkboxNr}`] = _del;
} }
} else { } else {
if (this.levelup.levels[this.levelup.currentLevel].nrSelections.available < Number(button.dataset.cost)) { if (this.levelup.levels[this.levelup.currentLevel].nrSelections.available < Number(button.dataset.cost)) {

View file

@ -118,7 +118,7 @@ export default class DhSceneConfigSettings extends foundry.applications.sheets.S
for (const key of Object.keys(this.document._source.flags.daggerheart?.sceneEnvironments ?? {})) { for (const key of Object.keys(this.document._source.flags.daggerheart?.sceneEnvironments ?? {})) {
if (!submitData.flags.daggerheart.sceneEnvironments[key]) { if (!submitData.flags.daggerheart.sceneEnvironments[key]) {
submitData.flags.daggerheart.sceneEnvironments[`-=${key}`] = null; submitData.flags.daggerheart.sceneEnvironments[key] = _del;
} }
} }

View file

@ -228,7 +228,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
const isDowntime = ['shortRest', 'longRest'].includes(type); const isDowntime = ['shortRest', 'longRest'].includes(type);
const path = isDowntime ? `restMoves.${type}.moves` : `itemFeatures.${type}`; const path = isDowntime ? `restMoves.${type}.moves` : `itemFeatures.${type}`;
await this.settings.updateSource({ await this.settings.updateSource({
[`${path}.-=${id}`]: null [`${path}.${id}`]: _del
}); });
this.render(); this.render();
} }
@ -250,7 +250,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
const fields = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).schema.fields; const fields = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).schema.fields;
const removeUpdate = Object.keys(this.settings.restMoves[target.dataset.type].moves).reduce((acc, key) => { const removeUpdate = Object.keys(this.settings.restMoves[target.dataset.type].moves).reduce((acc, key) => {
acc[`-=${key}`] = null; acc[key] = _del;
return acc; return acc;
}, {}); }, {});
@ -310,7 +310,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
[`itemFeatures.${target.dataset.type}`]: Object.keys( [`itemFeatures.${target.dataset.type}`]: Object.keys(
this.settings.itemFeatures[target.dataset.type] this.settings.itemFeatures[target.dataset.type]
).reduce((acc, key) => { ).reduce((acc, key) => {
acc[`-=${key}`] = null; acc[key] = _del;
return acc; return acc;
}, {}) }, {})
@ -383,12 +383,12 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
if (!confirmed) return; if (!confirmed) return;
await this.settings.updateSource({ await this.settings.updateSource({
[`domains.-=${this.selected.domain}`]: null [`domains.${this.selected.domain}`]: _del
}); });
const currentSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew); const currentSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew);
if (currentSettings.domains[this.selected.domain]) { if (currentSettings.domains[this.selected.domain]) {
await currentSettings.updateSource({ [`domains.-=${this.selected.domain}`]: null }); await currentSettings.updateSource({ [`domains.${this.selected.domain}`]: _del });
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew, currentSettings); await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew, currentSettings);
} }
@ -435,7 +435,7 @@ export default class DhHomebrewSettings extends HandlebarsApplicationMixin(Appli
static async deleteAdversaryType(_, target) { static async deleteAdversaryType(_, target) {
const { key } = target.dataset; const { key } = target.dataset;
await this.settings.updateSource({ [`adversaryTypes.-=${key}`]: null }); await this.settings.updateSource({ [`adversaryTypes.${key}`]: _del });
this.selected.adversaryType = this.selected.adversaryType === key ? null : this.selected.adversaryType; this.selected.adversaryType = this.selected.adversaryType === key ? null : this.selected.adversaryType;
this.render(); this.render();

View file

@ -95,7 +95,7 @@ export default class DHAdversarySettings extends DHBaseActorSettings {
}); });
if (!confirmed) return; if (!confirmed) return;
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null }); await this.actor.update({ [`system.experiences.${target.dataset.experience}`]: _del });
} }
async _onDragStart(event) { async _onDragStart(event) {

View file

@ -101,8 +101,8 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
if (relinkAchievementData.length > 0) { if (relinkAchievementData.length > 0) {
relinkAchievementData.forEach(data => { relinkAchievementData.forEach(data => {
updates[`system.levelData.levelups.${data.levelKey}.achievements.experiences.-=${data.experience}`] = updates[`system.levelData.levelups.${data.levelKey}.achievements.experiences.${data.experience}`] =
null; _del;
}); });
} else if (relinkSelectionData.length > 0) { } else if (relinkSelectionData.length > 0) {
relinkSelectionData.forEach(data => { relinkSelectionData.forEach(data => {
@ -137,7 +137,7 @@ export default class DHCharacterSettings extends DHBaseActorSettings {
await this.actor.update({ await this.actor.update({
...updates, ...updates,
[`system.experiences.-=${target.dataset.experience}`]: null [`system.experiences.${target.dataset.experience}`]: _del
}); });
} }
} }

View file

@ -117,6 +117,6 @@ export default class DHCompanionSettings extends DHBaseActorSettings {
}); });
if (!confirmed) return; if (!confirmed) return;
await this.actor.update({ [`system.experiences.-=${target.dataset.experience}`]: null }); await this.actor.update({ [`system.experiences.${target.dataset.experience}`]: _del });
} }
} }

View file

@ -79,7 +79,7 @@ export default class DHEnvironmentSettings extends DHBaseActorSettings {
* @type {ApplicationClickAction} * @type {ApplicationClickAction}
*/ */
static async #removeCategory(_, target) { static async #removeCategory(_, target) {
await this.actor.update({ [`system.potentialAdversaries.-=${target.dataset.categoryId}`]: null }); await this.actor.update({ [`system.potentialAdversaries.${target.dataset.categoryId}`]: _del });
} }
/** /**

View file

@ -206,7 +206,7 @@ export default class SettingFeatureConfig extends HandlebarsApplicationMixin(App
} }
}); });
} else { } else {
await this.settings.updateSource({ [`${this.actionsPath}.-=${target.dataset.id}`]: null }); await this.settings.updateSource({ [`${this.actionsPath}.${target.dataset.id}`]: _del });
} }
this.move = foundry.utils.getProperty(this.settings, this.movePath); this.move = foundry.utils.getProperty(this.settings, this.movePath);

View file

@ -67,7 +67,7 @@ export default function DHTokenConfigMixin(Base) {
changes.height = tokenSize; changes.height = tokenSize;
} }
const deletions = { '-=actorId': null, '-=actorLink': null }; const deletions = { actorId: _del, actorLink: _del };
const mergeOptions = { inplace: false, performDeletions: true }; const mergeOptions = { inplace: false, performDeletions: true };
this._preview.updateSource(mergeObject(changes, deletions, mergeOptions)); this._preview.updateSource(mergeObject(changes, deletions, mergeOptions));

View file

@ -102,7 +102,7 @@ export default class BeastformSheet extends DHBaseItemSheet {
async advantageOnRemove(event) { async advantageOnRemove(event) {
await this.document.update({ await this.document.update({
[`system.advantageOn.-=${event.detail.data.value}`]: null [`system.advantageOn.${event.detail.data.value}`]: _del
}); });
} }
} }

View file

@ -108,8 +108,7 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
getSystemFlagUpdate() { getSystemFlagUpdate() {
const deleteUpdate = Object.keys(this.document._source.flags.daggerheart?.altFormula ?? {}).reduce( const deleteUpdate = Object.keys(this.document._source.flags.daggerheart?.altFormula ?? {}).reduce(
(acc, formulaKey) => { (acc, formulaKey) => {
if (!this.daggerheartFlag.altFormula[formulaKey]) if (!this.daggerheartFlag.altFormula[formulaKey]) acc.altFormula[formulaKey] = _del;
acc.altFormula[formulaKey] = foundry.data.operators.ForcedDeletion.create();
return acc; return acc;
}, },
@ -129,7 +128,7 @@ export default class DhRollTableSheet extends foundry.applications.sheets.RollTa
static async #removeFormula(_event, target) { static async #removeFormula(_event, target) {
await this.daggerheartFlag.updateSource({ await this.daggerheartFlag.updateSource({
[`altFormula.${target.dataset.key}`]: foundry.data.operators.ForcedDeletion.create() [`altFormula.${target.dataset.key}`]: _del
}); });
this.render({ internalRefresh: true }); this.render({ internalRefresh: true });
} }

View file

@ -233,6 +233,6 @@ export default class CountdownEdit extends HandlebarsApplicationMixin(Applicatio
} }
if (this.editingCountdowns.has(countdownId)) this.editingCountdowns.delete(countdownId); if (this.editingCountdowns.has(countdownId)) this.editingCountdowns.delete(countdownId);
this.updateSetting({ [`countdowns.-=${countdownId}`]: null }); this.updateSetting({ [`countdowns.${countdownId}`]: _del });
} }
} }

View file

@ -100,7 +100,7 @@ export default class BeastformEffect extends BaseEffect {
token.flags.daggerheart?.beastformSubjectTexture ?? this.characterTokenData.tokenRingImg token.flags.daggerheart?.beastformSubjectTexture ?? this.characterTokenData.tokenRingImg
} }
}, },
'flags.daggerheart': { '-=beastformTokenImg': null, '-=beastformSubjectTexture': null } 'flags.daggerheart': { beastformTokenImg: _del, beastformSubjectTexture: _del }
}; };
}; };

View file

@ -169,9 +169,7 @@ export default class BaseDataActor extends foundry.abstract.TypeDataModel {
const tagTeam = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll); const tagTeam = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll);
await tagTeam.updateSource({ await tagTeam.updateSource({
initiator: this.parent.id === tagTeam.initiator ? null : tagTeam.initiator, initiator: this.parent.id === tagTeam.initiator ? null : tagTeam.initiator,
members: Object.keys(tagTeam.members).find(x => x === this.parent.id) members: Object.keys(tagTeam.members).find(x => x === this.parent.id) ? { [this.parent.id]: _del } : {}
? { [`-=${this.parent.id}`]: null }
: {}
}); });
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll, tagTeam); await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.TagTeamRoll, tagTeam);
} }

View file

@ -48,7 +48,7 @@ export default class DhParty extends BaseDataActor {
initiator: this.partyMembers.some(x => x.id === tagTeam.initiator) ? null : tagTeam.initiator, initiator: this.partyMembers.some(x => x.id === tagTeam.initiator) ? null : tagTeam.initiator,
members: Object.keys(tagTeam.members).reduce((acc, key) => { members: Object.keys(tagTeam.members).reduce((acc, key) => {
if (this.partyMembers.find(x => x.id === key)) { if (this.partyMembers.find(x => x.id === key)) {
acc[`-=${key}`] = null; acc[key] = _del;
} }
return acc; return acc;

View file

@ -243,11 +243,11 @@ export function ActionMixin(Base) {
: foundry.utils.getProperty(result, basePath); : foundry.utils.getProperty(result, basePath);
} }
delete() { async delete() {
if (!this.inCollection) return this.item; if (!this.inCollection) return this.item;
const action = foundry.utils.getProperty(this.item, `system.${this.systemPath}`)?.get(this.id); const action = foundry.utils.getProperty(this.item, `system.${this.systemPath}`)?.get(this.id);
if (!action) return this.item; if (!action) return this.item;
this.item.update({ [`system.${this.systemPath}.-=${this.id}`]: null }); await this.item.update({ [`system.${this.systemPath}.${this.id}`]: _del }); // Does not work. Unsure why. It worked in v13 <_<'
this.constructor._sheets.get(this.uuid)?.close(); this.constructor._sheets.get(this.uuid)?.close();
} }

View file

@ -87,7 +87,7 @@ export default class DHArmor extends AttachableItem {
} }
await this.parent.deleteEmbeddedDocuments('ActiveEffect', effectIds); await this.parent.deleteEmbeddedDocuments('ActiveEffect', effectIds);
changes.system.actions = actionIds.reduce((acc, id) => { changes.system.actions = actionIds.reduce((acc, id) => {
acc[`-=${id}`] = null; acc[id] = _del;
return acc; return acc;
}, {}); }, {});

View file

@ -230,9 +230,9 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
if (changed.system?.actions) { if (changed.system?.actions) {
const triggersToRemove = Object.keys(changed.system.actions).reduce((acc, key) => { const triggersToRemove = Object.keys(changed.system.actions).reduce((acc, key) => {
if (!changed.system.actions[key]) { const action = changed.system.actions[key];
const strippedKey = key.replace('-=', ''); if (action && Object.keys(action).length === 0) {
acc.push(...this.actions.get(strippedKey).triggers.map(x => x.trigger)); acc.push(...this.actions.get(key).triggers.map(x => x.trigger));
} }
return acc; return acc;

View file

@ -147,7 +147,7 @@ export default class DHWeapon extends AttachableItem {
await this.parent.deleteEmbeddedDocuments('ActiveEffect', removedEffectsUpdate); await this.parent.deleteEmbeddedDocuments('ActiveEffect', removedEffectsUpdate);
changes.system.actions = removedActionsUpdate.reduce((acc, id) => { changes.system.actions = removedActionsUpdate.reduce((acc, id) => {
acc[`-=${id}`] = null; acc[id] = _del;
return acc; return acc;
}, {}); }, {});

View file

@ -142,7 +142,7 @@ export default class DhpActor extends Actor {
} }
const updatedLevelups = Object.keys(this.system.levelData.levelups).reduce((acc, level) => { const updatedLevelups = Object.keys(this.system.levelData.levelups).reduce((acc, level) => {
if (Number(level) > usedLevel) acc[`-=${level}`] = null; if (Number(level) > usedLevel) acc[level] = _del;
return acc; return acc;
}, {}); }, {});
@ -187,7 +187,7 @@ export default class DhpActor extends Actor {
if (experiences.length > 0) { if (experiences.length > 0) {
const getUpdate = () => ({ const getUpdate = () => ({
'system.experiences': experiences.reduce((acc, key) => { 'system.experiences': experiences.reduce((acc, key) => {
acc[`-=${key}`] = null; acc[key] = _del;
return acc; return acc;
}, {}) }, {})
}); });

View file

@ -171,10 +171,10 @@ export const getDeleteKeys = (property, innerProperty, innerPropertyDefaultValue
[innerProperty]: innerPropertyDefaultValue [innerProperty]: innerPropertyDefaultValue
}; };
} else { } else {
acc[`${key}.-=${innerProperty}`] = null; acc[`${key}.${innerProperty}`] = _del;
} }
} else { } else {
acc[`-=${key}`] = null; acc[`${key}`] = _del;
} }
return acc; return acc;

View file

@ -197,7 +197,7 @@ export async function runMigrations() {
const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator); const initatorMissing = tagTeam.initiator && !game.actors.some(actor => actor.id === tagTeam.initiator);
const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => { const missingMembers = Object.keys(tagTeam.members).reduce((acc, id) => {
if (!game.actors.some(actor => actor.id === id)) { if (!game.actors.some(actor => actor.id === id)) {
acc[`-=${id}`] = null; acc[id] = _del;
} }
return acc; return acc;
}, {}); }, {});