Passe de vérification mergeObject

Quand mergeObject est utilisé pour retourner une valeur, faire très
attention à ne pas passer un Item/Actor, ou une de ses sous parties
en premier paramètre sans préciser l'option { inplace: false }

Sinon, le premier paramètre subit une mutation!
This commit is contained in:
Vincent Vandemeulebrouck 2024-06-01 01:53:14 +02:00
parent 0b1c5d0a3d
commit a103239288
23 changed files with 57 additions and 65 deletions

View File

@ -32,21 +32,20 @@ export class RdDActorSheet extends RdDBaseActorSangSheet {
width: 550, width: 550,
showCompNiveauBase: false, showCompNiveauBase: false,
vueArchetype: false, vueArchetype: false,
}); }, { inplace: false });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async getData() { async getData() {
let formData = await super.getData(); let formData = await super.getData();
foundry.utils.mergeObject(formData, foundry.utils.mergeObject(formData, {
{ editable: this.isEditable,
editable: this.isEditable, cssClass: this.isEditable ? "editable" : "locked",
cssClass: this.isEditable ? "editable" : "locked", limited: this.actor.limited,
limited: this.actor.limited, owner: this.actor.isOwner,
owner: this.actor.isOwner, biographie: await TextEditor.enrichHTML(this.actor.system.biographie, { async: true }),
biographie: await TextEditor.enrichHTML(this.actor.system.biographie, { async: true }), notes: await TextEditor.enrichHTML(this.actor.system.notes, { async: true }),
notes: await TextEditor.enrichHTML(this.actor.system.notes, { async: true }), });
});
foundry.utils.mergeObject(formData.calc, { foundry.utils.mergeObject(formData.calc, {
surenc: this.actor.computeMalusSurEncombrement(), surenc: this.actor.computeMalusSurEncombrement(),
surprise: RdDBonus.find(this.actor.getSurprise(false)).descr, surprise: RdDBonus.find(this.actor.getSurprise(false)).descr,
@ -211,7 +210,7 @@ export class RdDActorSheet extends RdDBaseActorSangSheet {
const key = Number(li.data("key") ?? -1); const key = Number(li.data("key") ?? -1);
await this.actor.deleteExperienceLog(0, key + 1); await this.actor.deleteExperienceLog(0, key + 1);
}); });
// Boutons spéciaux MJs // Boutons spéciaux MJs
this.html.find('.forcer-tmr-aleatoire').click(async event => this.actor.reinsertionAleatoire("Action MJ")) this.html.find('.forcer-tmr-aleatoire').click(async event => this.actor.reinsertionAleatoire("Action MJ"))
this.html.find('.afficher-tmr').click(async event => this.actor.changeTMRVisible()) this.html.find('.afficher-tmr').click(async event => this.actor.changeTMRVisible())
} }

View File

@ -2346,7 +2346,7 @@ export class RdDActor extends RdDBaseActorSang {
async _xpCaracDerivee(xpData) { async _xpCaracDerivee(xpData) {
const caracs = RdDActor._getComposantsCaracDerivee(xpData.caracName) const caracs = RdDActor._getComposantsCaracDerivee(xpData.caracName)
.map(c => foundry.utils.mergeObject(this.system.carac[c], { isMax: this.isCaracMax(c) })) .map(c => foundry.utils.mergeObject(this.system.carac[c], { isMax: this.isCaracMax(c) }, { inplace: false }))
switch (caracs.filter(it => !it.isMax).length) { switch (caracs.filter(it => !it.isMax).length) {
case 0: case 0:
xpData.caracRepartitionManuelle = true; xpData.caracRepartitionManuelle = true;

View File

@ -286,12 +286,12 @@ export class RdDBaseActorReve extends RdDBaseActor {
getCarac() { getCarac() {
// TODO: le niveau d'une entité de cauchemar devrait être exclu... // TODO: le niveau d'une entité de cauchemar devrait être exclu...
const carac = foundry.utils.mergeObject(foundry.utils.duplicate(this.system.carac), return foundry.utils.mergeObject(this.system.carac,
{ {
'reve-actuel': this.getCaracReveActuel(), 'reve-actuel': this.getCaracReveActuel(),
'chance-actuelle': this.getCaracChanceActuelle() 'chance-actuelle': this.getCaracChanceActuelle()
}); },
return carac; { inplace: false })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -20,7 +20,7 @@ export class RdDBaseActorSheet extends ActorSheet {
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }], tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }],
dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }], dragDrop: [{ dragSelector: ".item-list .item", dropSelector: undefined }],
vueDetaillee: false vueDetaillee: false
}); }, { inplace: false })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -15,7 +15,7 @@ export class RdDCommerceSheet extends RdDBaseActorSheet {
template: "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-actor-sheet.html", template: "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-actor-sheet.html",
width: 600, height: 720, width: 600, height: 720,
tabs: [] tabs: []
}); }, { inplace: false })
} }
get title() { get title() {
if (this.actor.token && this.actor.token != this.actor.prototypeToken) { if (this.actor.token && this.actor.token != this.actor.prototypeToken) {

View File

@ -25,8 +25,7 @@ export class RdDCommerce extends RdDBaseActor {
} }
await super.depenserSols(cout) await super.depenserSols(cout)
} }
async consommerNourritureboisson(itemId, choix, userId) {
async consommerNourritureAchetee(achat, vente, createdItemId) {
// ne pas consommer pour un commerce // ne pas consommer pour un commerce
} }

View File

@ -12,7 +12,7 @@ export class RdDCreatureSheet extends RdDBaseActorSangSheet {
return foundry.utils.mergeObject(RdDBaseActorSangSheet.defaultOptions, { return foundry.utils.mergeObject(RdDBaseActorSangSheet.defaultOptions, {
template: "systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html", template: "systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html",
width: 640, height: 720 width: 640, height: 720
}); }, { inplace: false })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -9,7 +9,7 @@ export class RdDActorEntiteSheet extends RdDBaseActorReveSheet {
return foundry.utils.mergeObject(RdDBaseActorReveSheet.defaultOptions, { return foundry.utils.mergeObject(RdDBaseActorReveSheet.defaultOptions, {
template: "systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html", template: "systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html",
width: 640, height: 720, width: 640, height: 720,
}); }, { inplace: false })
} }
async getData() { async getData() {

View File

@ -9,7 +9,7 @@ export class RdDActorVehiculeSheet extends RdDBaseActorSheet {
return foundry.utils.mergeObject(RdDBaseActorSheet.defaultOptions, { return foundry.utils.mergeObject(RdDBaseActorSheet.defaultOptions, {
template: "systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html", template: "systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html",
width: 640, height: 720, width: 640, height: 720,
}); }, { inplace: false })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -199,7 +199,7 @@ export class RdDItemCompetence extends Item {
if (idOrName == undefined || idOrName == "") { if (idOrName == undefined || idOrName == "") {
return RdDItemCompetence.sansCompetence(); return RdDItemCompetence.sansCompetence();
} }
options = foundry.utils.mergeObject(options, { preFilter: it => it.isCompetence(), description: 'compétence' }, { overwrite: false }); options = foundry.utils.mergeObject(options, { preFilter: it => it.isCompetence(), description: 'compétence' }, { overwrite: false, inplace: false });
return RdDItemCompetence.findFirstItem(list, idOrName, options); return RdDItemCompetence.findFirstItem(list, idOrName, options);
} }

View File

@ -33,8 +33,7 @@ export class RdDItemCompetenceCreature extends Item {
if (categorieAttaque != undefined) { if (categorieAttaque != undefined) {
// si c'est un Item compétence: cloner pour ne pas modifier la compétence // si c'est un Item compétence: cloner pour ne pas modifier la compétence
let arme = item.clone(); let arme = item.clone();
foundry.utils.mergeObject(arme, return foundry.utils.mergeObject(arme, {
{
action: item.isCompetencePossession() ? 'possession' : 'attaque', action: item.isCompetencePossession() ? 'possession' : 'attaque',
system: { system: {
competence: arme.name, competence: arme.name,
@ -48,8 +47,7 @@ export class RdDItemCompetenceCreature extends Item {
force: 0, force: 0,
rapide: true, rapide: true,
} }
}); }, { inplace: false });
return arme;
} }
return undefined; return undefined;
} }

View File

@ -44,7 +44,7 @@ export class RdDItemSheet extends ItemSheet {
template: RdDItemSheet.defaultTemplate(RdDItemSheet.ITEM_TYPE), template: RdDItemSheet.defaultTemplate(RdDItemSheet.ITEM_TYPE),
width: 550, width: 550,
height: 550 height: 550
}); }, { inplace: false });
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -39,7 +39,7 @@ export class RdDItemBlessure extends RdDItem {
ui.notifications.warn(`Pas de tâche de soins pour une blessure ${gravite}`) ui.notifications.warn(`Pas de tâche de soins pour une blessure ${gravite}`)
return undefined; return undefined;
} }
return foundry.utils.mergeObject(foundry.utils.duplicate(BASE_TACHE_SOIN_BLESSURE), tache) return foundry.utils.mergeObject(BASE_TACHE_SOIN_BLESSURE, tache, { inplace: false })
} }
static async applyFullBlessure(actor, gravite) { static async applyFullBlessure(actor, gravite) {
@ -106,12 +106,12 @@ export class RdDItemBlessure extends RdDItem {
} }
async setSoinsBlessure(systemUpdate = {}) { async setSoinsBlessure(systemUpdate = {}) {
systemUpdate = foundry.utils.mergeObject(systemUpdate, this.system, { overwrite: false }), systemUpdate = foundry.utils.mergeObject(systemUpdate, this.system, { overwrite: false })
systemUpdate.soinscomplets.done = systemUpdate.premierssoins.done && systemUpdate.soinscomplets.done systemUpdate.soinscomplets.done = systemUpdate.premierssoins.done && systemUpdate.soinscomplets.done
await this.update({ await this.update({
img: this.getImgSoins(systemUpdate.gravite, systemUpdate.soinscomplets.done), img: this.getImgSoins(systemUpdate.gravite, systemUpdate.soinscomplets.done),
system: systemUpdate system: systemUpdate
}); })
} }
async recuperationBlessure({ actor, timestamp, message, isMaladeEmpoisonne, blessures }) { async recuperationBlessure({ actor, timestamp, message, isMaladeEmpoisonne, blessures }) {

View File

@ -10,7 +10,7 @@ export class RdDItemInventaireSheet extends RdDItemSheet {
static get defaultOptions() { static get defaultOptions() {
return foundry.utils.mergeObject(RdDItemSheet.defaultOptions, { return foundry.utils.mergeObject(RdDItemSheet.defaultOptions, {
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "informations" }] tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "informations" }]
}); }, { inplace: false })
} }
setPosition(options = {}) { setPosition(options = {}) {
@ -23,9 +23,10 @@ export class RdDItemInventaireSheet extends RdDItemSheet {
async getData() { async getData() {
const formData = await super.getData(); const formData = await super.getData();
return foundry.utils.mergeObject(formData, { foundry.utils.mergeObject(formData, {
milieux: await game.system.rdd.environnement.autresMilieux(this.item) milieux: await game.system.rdd.environnement.autresMilieux(this.item)
}); })
return formData
} }
activateListeners(html) { activateListeners(html) {

View File

@ -8,7 +8,7 @@ export class RdDRencontreItemSheet extends RdDItemSheet {
static get defaultOptions() { static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, { return foundry.utils.mergeObject(super.defaultOptions, {
tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }] tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "carac" }]
}); }, { inplace: false })
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -35,7 +35,7 @@ export class RdDRencontreItemSheet extends RdDItemSheet {
select: RdDRencontre.mapEffets(this.item.system.echec.effets) select: RdDRencontre.mapEffets(this.item.system.echec.effets)
} }
} }
}); })
return formData; return formData;
} }

View File

@ -128,21 +128,17 @@ export class RdDCombatManager extends Combat {
// Send a chat message // Send a chat message
let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode"); let rollMode = messageOptions.rollMode || game.settings.get("core", "rollMode");
let messageData = foundry.utils.mergeObject( let messageData = foundry.utils.mergeObject({
{ speaker: {
speaker: { scene: canvas.scene._id,
scene: canvas.scene._id, actor: combatant.actor?._id,
actor: combatant.actor?._id, token: combatant.token._id,
token: combatant.token._id, alias: combatant.token.name,
alias: combatant.token.name, sound: CONFIG.sounds.dice,
sound: CONFIG.sounds.dice,
},
flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.initInfo})
<br>
`,
}, },
messageOptions flavor: `${combatant.token.name} a fait son jet d'Initiative (${messageOptions.initInfo})<br>`,
); },
messageOptions);
roll.toMessage(messageData, { rollMode, create: true }); roll.toMessage(messageData, { rollMode, create: true });
RdDCombatManager.processPremierRoundInit(); RdDCombatManager.processPremierRoundInit();

View File

@ -12,7 +12,7 @@ export class RdDConfirm {
buttons = foundry.utils.mergeObject(RdDConfirm._createButtonActionSave(options), buttons); buttons = foundry.utils.mergeObject(RdDConfirm._createButtonActionSave(options), buttons);
} }
if (autresActions) { if (autresActions) {
buttons = foundry.utils.mergeObject(autresActions, buttons); buttons = foundry.utils.mergeObject(autresActions, buttons, { inplace: false });
} }
const dialogDetails = { const dialogDetails = {
title: options.title, title: options.title,

View File

@ -71,8 +71,7 @@ export class ReglesOptionnelles extends FormApplication {
} }
static get defaultOptions() { static get defaultOptions() {
const options = super.defaultOptions; return foundry.utils.mergeObject(super.defaultOptions, {
foundry.utils.mergeObject(options, {
id: "regles-optionnelles", id: "regles-optionnelles",
template: "systems/foundryvtt-reve-de-dragon/templates/settings/regles-optionnelles.html", template: "systems/foundryvtt-reve-de-dragon/templates/settings/regles-optionnelles.html",
height: 650, height: 650,
@ -80,8 +79,7 @@ export class ReglesOptionnelles extends FormApplication {
minimizable: false, minimizable: false,
closeOnSubmit: true, closeOnSubmit: true,
title: "Règles optionnelles" title: "Règles optionnelles"
}); }, { inplace: false })
return options;
} }
getData() { getData() {

View File

@ -152,7 +152,7 @@ export class SystemCompendiums extends FormApplication {
getData() { getData() {
const systemCompendiums = Object.values(CONFIGURABLE_COMPENDIUMS) const systemCompendiums = Object.values(CONFIGURABLE_COMPENDIUMS)
.map(it => foundry.utils.mergeObject(it, { value: SystemCompendiums.getCompendium(it.compendium) })); .map(it => foundry.utils.mergeObject(it, { value: SystemCompendiums.getCompendium(it.compendium) }, { inplace: false }))
const availableCompendiums = game.packs.map(pack => { const availableCompendiums = game.packs.map(pack => {
return { return {
name: pack.collection, name: pack.collection,
@ -163,7 +163,7 @@ export class SystemCompendiums extends FormApplication {
return foundry.utils.mergeObject(super.getData(), { return foundry.utils.mergeObject(super.getData(), {
systemCompendiums: systemCompendiums, systemCompendiums: systemCompendiums,
availableCompendiums: availableCompendiums availableCompendiums: availableCompendiums
}); }, { inplace: false })
} }
activateListeners(html) { activateListeners(html) {

View File

@ -25,7 +25,7 @@ export class AppAstrologie extends Application {
classes: ['calendar-astrologie'], classes: ['calendar-astrologie'],
popOut: true, popOut: true,
resizable: false resizable: false
}); }, { inplace: false })
} }
constructor(actor, options = {}) { constructor(actor, options = {}) {
@ -49,7 +49,7 @@ export class AppAstrologie extends Application {
signeNaissance: RdDTimestamp.definition(0) signeNaissance: RdDTimestamp.definition(0)
} }
}) })
return this.appData; return this.appData
} }
getActorAstrologie() { getActorAstrologie() {

View File

@ -43,7 +43,7 @@ export class RdDCalendrier extends Application {
resizable: false, resizable: false,
width: 'fit-content', width: 'fit-content',
height: 'fit-content', height: 'fit-content',
}); }, { inplace: false })
} }
constructor() { constructor() {

View File

@ -125,7 +125,7 @@ export class FenetreRechercheTirage extends Application {
popOut: true, popOut: true,
dragDrop: [{ dragSelector: "a.content-link" }], dragDrop: [{ dragSelector: "a.content-link" }],
resizable: true resizable: true
}); }, { inplace: false })
} }
static async create() { static async create() {

View File

@ -142,18 +142,19 @@ export class DialogFatigueVoyage extends Dialog {
it => this.$extractActor(this.html.find(it)) it => this.$extractActor(this.html.find(it))
) )
actors.filter(it => it.selected) actors.filter(it => it.selected)
.forEach(async it => { .forEach(async it => {
const perteFatigue = fatigueBase + it.ajustement const perteFatigue = fatigueBase + it.ajustement
ChatMessage.create({ ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(it.actor.name), whisper: ChatUtility.getWhisperRecipientsAndGMs(it.actor.name),
content: await renderTemplate( content: await renderTemplate(
'systems/foundryvtt-reve-de-dragon/templates/voyage/chat-fatigue_voyage.hbs', foundry.utils.mergeObject(it, 'systems/foundryvtt-reve-de-dragon/templates/voyage/chat-fatigue_voyage.hbs',
foundry.utils.mergeObject(it,
{ {
parameters: this.parameters, parameters: this.parameters,
fatigueBase: fatigueBase, fatigueBase: fatigueBase,
perteFatigue: perteFatigue, perteFatigue: perteFatigue,
isVoyage: fatigueBase == this.parameters.nombreHeures * this.parameters.fatigueHoraire isVoyage: fatigueBase == this.parameters.nombreHeures * this.parameters.fatigueHoraire
}) }, { inplace: false })
), ),
}) })
await it.actor.santeIncDec("fatigue", perteFatigue) await it.actor.santeIncDec("fatigue", perteFatigue)