Migration maladies et poisons
Séparation de l'incubation / la périodicité
This commit is contained in:
@ -4,6 +4,7 @@ import { Environnement } from "./environnement.js";
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { Monnaie } from "./item-monnaie.js";
|
||||
import { RdDItem } from "./item.js";
|
||||
import { RdDTimestamp } from "./rdd-timestamp.js";
|
||||
|
||||
class Migration {
|
||||
get code() { return "sample"; }
|
||||
@ -368,6 +369,51 @@ class _10_4_6_ServicesEnCommerces extends Migration {
|
||||
return itemToCreate;
|
||||
}
|
||||
}
|
||||
class _10_5_0_UpdatePeriodicite extends Migration {
|
||||
get code() { return "migration-periodicite-poisons-maladies"; }
|
||||
get version() { return "10.5.0"; }
|
||||
|
||||
async migrate() {
|
||||
await this.applyItemsUpdates(items => this._updatePeriodicite(items));
|
||||
}
|
||||
|
||||
_updatePeriodicite(items) {
|
||||
return items.filter(it => ['poison', 'maladie'].includes(it.type))
|
||||
.filter(it => it.system.periodicite != "")
|
||||
.map(it => {
|
||||
let [incubation, periodicite] = this.getPeriodicite(it);
|
||||
const periode = periodicite.split(' ');
|
||||
let unite = periode.length == 2
|
||||
? RdDTimestamp.formulesPeriode().find(it => Grammar.includesLowerCaseNoAccent(periode[1], it.code))?.code
|
||||
: undefined
|
||||
if (unite && Number(periode[0])) {
|
||||
return {
|
||||
_id: it.id,
|
||||
'system.periodicite': undefined,
|
||||
'system.incubation': incubation,
|
||||
'system.periode.nombre': Number.parseInt(periode[0]),
|
||||
'system.periode.unite': unite
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
_id: it.id,
|
||||
'system.periodicite': undefined,
|
||||
'system.incubation': it.system.periodicite
|
||||
};
|
||||
}
|
||||
}).filter(it => it != undefined);
|
||||
}
|
||||
|
||||
getPeriodicite(it) {
|
||||
let p = it.system.periodicite.split(/[\/\\]/);
|
||||
switch (p.length) {
|
||||
case 2: return [p[0].trim(), p[1].trim()];
|
||||
case 1: return ["", it.system.periodicite.trim()];
|
||||
default: return [it.system.periodicite.trim(), ""];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Migrations {
|
||||
static getMigrations() {
|
||||
@ -383,6 +429,7 @@ export class Migrations {
|
||||
new _10_3_0_FrequenceEnvironnement(),
|
||||
new _10_3_17_Monnaies(),
|
||||
new _10_4_6_ServicesEnCommerces(),
|
||||
new _10_5_0_UpdatePeriodicite(),
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -40,10 +40,10 @@ const FORMULES_DUREE = [
|
||||
// { code: "special", label: "Spéciale", calcul: async (t, actor) => t.addJours(100 * RDD_JOURS_PAR_AN) },
|
||||
]
|
||||
const FORMULES_PERIODE = [
|
||||
{ code: 'rounds', label: "Rounds", calcul: async (t, nombre) => t.addMinutes(nombre / 10) },
|
||||
{ code: 'minutes', label: "Minutes", calcul: async (t, nombre) => t.addMinutes(nombre) },
|
||||
{ code: 'heures', label: "Heures", calcul: async (t, nombre) => t.addHeures(nombre) },
|
||||
{ code: 'jours', label: "Jours", calcul: async (t, nombre) => t.addJours(nombre) },
|
||||
{ code: 'round', label: "Rounds", calcul: async (t, nombre) => t.addMinutes(nombre / 10) },
|
||||
{ code: 'minute', label: "Minutes", calcul: async (t, nombre) => t.addMinutes(nombre) },
|
||||
{ code: 'heure', label: "Heures", calcul: async (t, nombre) => t.addHeures(nombre) },
|
||||
{ code: 'jour', label: "Jours", calcul: async (t, nombre) => t.addJours(nombre) },
|
||||
]
|
||||
|
||||
export class RdDTimestamp {
|
||||
|
Reference in New Issue
Block a user