Migration des monnaies par nom

Vu que dans les migrations précédentes, le "cout" avait une valeur
(pas undefined), les migrations ont échoué
This commit is contained in:
Vincent Vandemeulebrouck 2022-12-17 17:26:11 +01:00
parent 4e382d405e
commit c9dc847440
6 changed files with 95 additions and 60 deletions

View File

@ -2,22 +2,22 @@ import { Misc } from "./misc.js";
import { LOG_HEAD } from "./constants.js"; import { LOG_HEAD } from "./constants.js";
const MONNAIE_ETAIN = { const MONNAIE_ETAIN = {
name: "Etain (1 denier)", type: 'monnaie', name: "Denier (étain)", type: 'monnaie',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp", img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_etain_poisson.webp",
system: { quantite: 0, cout: 0.01, encombrement: 0.001, description: "" } system: { quantite: 0, cout: 0.01, encombrement: 0.001, description: "" }
}; };
const MONNAIE_BRONZE = { const MONNAIE_BRONZE = {
name: "Bronze (10 deniers)", type: 'monnaie', name: "Sou (bronze)", type: 'monnaie',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp", img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_bronze_epees.webp",
system: { quantite: 0, cout: 0.10, encombrement: 0.002, description: "" } system: { quantite: 0, cout: 0.10, encombrement: 0.002, description: "" }
}; };
const MONNAIE_ARGENT = { const MONNAIE_ARGENT = {
name: "Argent (1 sol)", type: 'monnaie', name: "Sol (argent)", type: 'monnaie',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp", img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_argent_sol.webp",
system: { quantite: 0, cout: 1, encombrement: 0.003, description: "" } system: { quantite: 0, cout: 1, encombrement: 0.003, description: "" }
}; };
const MONNAIE_OR = { const MONNAIE_OR = {
name: "Or (10 sols)", type: 'monnaie', name: "Dreagon (or)", type: 'monnaie',
img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp", img: "systems/foundryvtt-reve-de-dragon/icons/objets/piece_or_sol.webp",
system: { quantite: 0, cout: 10, encombrement: 0.004, description: "" } system: { quantite: 0, cout: 10, encombrement: 0.004, description: "" }
}; };

View File

@ -236,7 +236,7 @@ class _10_3_0_Inventaire extends Migration {
} }
_updatesMonnaies(items) { _updatesMonnaies(items) {
return items return items
.filter(it => ['monnaie'].includes(it.type) && it.system.cout == undefined) .filter(it => ['monnaie'].includes(it.type) && it.system.valeur_deniers != undefined)
.map(it => { return { _id: it.id, 'system.cout': it.system.valeur_deniers / 100, 'system.valeur_deniers': undefined } }); .map(it => { return { _id: it.id, 'system.cout': it.system.valeur_deniers / 100, 'system.valeur_deniers': undefined } });
} }
} }
@ -259,6 +259,40 @@ class _10_3_0_FrequenceEnvironnement extends Migration {
} }
} }
class _10_3_17_Monnaies extends Migration {
constructor() {
super();
this.mapValeur = {
"Etain (1 denier)": { name: 'Denier (étain)', system: { cout: 0.01 } },
"Bronze (10 deniers)": { name: "Sou (bronze)", system: { cout: 0.1 } },
"Argent (1 sol)": { name: "Sol (argent)", system: { cout: 1 } },
"Or (10 sols)": { name: "Dragon (or)", system: { cout: 10 } }
};
}
get code() { return "migration-monnaies"; }
get version() { return "10.3.17"; }
async migrate() {
await this.applyItemsUpdates(items => this._updatesMonnaies(items));
}
_updatesMonnaies(items) {
return items
.filter(it => 'monnaie' == it.type)
.filter(it => this.mapValeur[it.name] != undefined)
.map(it => {
const correction = this.mapValeur[it.name];
return {
_id: it.id,
'name': correction.name,
'system.cout': correction.system.cout,
'system.valeur_deniers': undefined
}
});
}
}
export class Migrations { export class Migrations {
static getMigrations() { static getMigrations() {
return [ return [
@ -269,7 +303,8 @@ export class Migrations {
new _10_2_5_ArmesTirLancer(), new _10_2_5_ArmesTirLancer(),
new _10_2_10_DesirLancinant_IdeeFixe(), new _10_2_10_DesirLancinant_IdeeFixe(),
new _10_3_0_Inventaire(), new _10_3_0_Inventaire(),
new _10_3_0_FrequenceEnvironnement() new _10_3_0_FrequenceEnvironnement(),
new _10_3_17_Monnaies()
]; ];
} }
@ -284,9 +319,9 @@ export class Migrations {
} }
migrate() { migrate() {
const currentVersion = game.settings.get(SYSTEM_RDD,"systemMigrationVersion"); const currentVersion = game.settings.get(SYSTEM_RDD, "systemMigrationVersion");
//if (isNewerVersion(game.system.version, currentVersion)) { if (isNewerVersion(game.system.version, currentVersion)) {
if (true) { /* comment previous and uncomment here to test before upgrade */ //if (true) { /* comment previous and uncomment here to test before upgrade */
const migrations = Migrations.getMigrations().filter(m => isNewerVersion(m.version, currentVersion)); const migrations = Migrations.getMigrations().filter(m => isNewerVersion(m.version, currentVersion));
if (migrations.length > 0) { if (migrations.length > 0) {
migrations.sort((a, b) => migrations.sort((a, b) =>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long