2022-09-17 16:07:38 +02:00
|
|
|
import { LOG_HEAD, SYSTEM_RDD } from "./constants.js";
|
2022-09-20 00:12:25 +02:00
|
|
|
import { Grammar } from "./grammar.js";
|
2022-11-01 00:48:46 +01:00
|
|
|
import { Misc } from "./misc.js";
|
2022-09-17 16:07:38 +02:00
|
|
|
|
|
|
|
class Migration {
|
|
|
|
get code() { return "sample"; }
|
|
|
|
get version() { return "0.0.0"; }
|
|
|
|
async migrate() { }
|
2022-09-20 00:12:25 +02:00
|
|
|
|
|
|
|
async applyItemsUpdates(computeUpdates) {
|
|
|
|
await game.actors.forEach(async (actor) => {
|
|
|
|
const actorItemUpdates = computeUpdates(actor.items);
|
|
|
|
if (actorItemUpdates.length > 0) {
|
|
|
|
console.log(
|
|
|
|
this.code,
|
|
|
|
`Applying updates on actor ${actor.name} items`,
|
|
|
|
actorItemUpdates
|
|
|
|
);
|
|
|
|
await actor.updateEmbeddedDocuments("Item", actorItemUpdates);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const itemUpdates = computeUpdates(game.items);
|
|
|
|
if (itemUpdates.length > 0) {
|
|
|
|
console.log(this.code, "Applying updates on items", itemUpdates);
|
|
|
|
await Item.updateDocuments(itemUpdates);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 16:07:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class _10_0_16_MigrationSortsReserve extends Migration {
|
|
|
|
get code() { return "creation-item-sort-reserve"; }
|
|
|
|
get version() { return "10.0.16"; }
|
|
|
|
|
|
|
|
async migrate() {
|
|
|
|
await game.actors
|
|
|
|
.filter((actor) => actor.type == "personnage")
|
|
|
|
.filter((actor) => actor.system.reve?.reserve?.list?.length ?? 0 > 0)
|
|
|
|
.forEach(async (actor) => {
|
|
|
|
const sortsReserve = actor.system.reve.reserve.list.map(this.conversionSortReserve);
|
2022-09-19 20:15:37 +02:00
|
|
|
console.log(`${LOG_HEAD} Migration des sorts en réserve de ${actor.name}`, sortsReserve);
|
2022-09-17 16:07:38 +02:00
|
|
|
await actor.createEmbeddedDocuments("Item", sortsReserve, {
|
|
|
|
renderSheet: false,
|
|
|
|
});
|
2022-09-20 00:12:25 +02:00
|
|
|
await actor.update({ 'system.reve.reserve.list': [] })
|
2022-09-17 16:07:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
conversionSortReserve(it) {
|
|
|
|
return {
|
|
|
|
type: 'sortreserve',
|
|
|
|
name: it.sort.name,
|
|
|
|
img: it.sort.img,
|
|
|
|
system: {
|
|
|
|
// ATTENTION, utilisation de data / _id possibles, encore présents pour les anciens sorts en réserve
|
|
|
|
sortid: it.sort._id,
|
|
|
|
draconic: it.sort.draconic,
|
|
|
|
ptreve: (it.sort.system ?? it.sort.data).ptreve_reel,
|
|
|
|
coord: it.coord,
|
|
|
|
heurecible: 'Vaisseau',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-20 00:12:25 +02:00
|
|
|
class _10_0_17_MigrationCompetenceCreature extends Migration {
|
|
|
|
get code() { return "competences-creature-parade"; }
|
|
|
|
get version() { return "10.0.17"; }
|
|
|
|
|
|
|
|
async migrate() {
|
|
|
|
await this.applyItemsUpdates(items => items
|
|
|
|
.filter(it => it.type == "competencecreature" && it.system.isparade && it.system.categorie_parade == "")
|
|
|
|
.map(it => { return { _id: it.id, "system.categorie_parade": "armes-naturelles" } }));
|
|
|
|
|
|
|
|
await this.applyItemsUpdates(items => items
|
|
|
|
.filter(it => it.type == "competencecreature" && it.system.iscombat)
|
|
|
|
.map(it => { return { _id: it.id, "system.categorie": (Grammar.includesLowerCaseNoAccent(it.name, "lancee") ? "lancer" : "melee") } })
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 00:15:34 +02:00
|
|
|
class _10_0_21_VehiculeStructureResistanceMax extends Migration {
|
|
|
|
get code() { return "vehicule-structure-resistance-max"; }
|
|
|
|
get version() { return "10.0.21"; }
|
|
|
|
|
|
|
|
async migrate() {
|
|
|
|
await game.actors
|
|
|
|
.filter((actor) => actor.type == "vehicule")
|
|
|
|
.forEach(async (actor) => {
|
|
|
|
await actor.update({
|
|
|
|
'system.etat.resistance.value': actor.system.resistance,
|
|
|
|
'system.etat.resistance.max': actor.system.resistance,
|
|
|
|
'system.etat.structure.value': actor.system.structure,
|
|
|
|
'system.etat.structure.max': actor.system.structure
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-01 00:48:46 +01:00
|
|
|
class _10_0_33_MigrationNomsDraconic extends Migration {
|
|
|
|
get code() { return "competences-creature-parade"; }
|
|
|
|
get version() { return "10.0.33"; }
|
|
|
|
|
|
|
|
migrationNomDraconic(ancien) {
|
|
|
|
if (typeof ancien == 'string'){
|
|
|
|
switch (ancien) {
|
|
|
|
case 'oniros': case "Voie d'Oniros": return "Voie d'Oniros";
|
|
|
|
case 'hypnos': case "Voie d'Hypnos": return "Voie d'Hypnos";
|
|
|
|
case 'narcos': case "Voie de Narcos": return "Voie de Narcos";
|
|
|
|
case 'thanatos': case "Voie de Thanatos": return "Voie de Thanatos";
|
|
|
|
}
|
|
|
|
return ancien;
|
|
|
|
}
|
|
|
|
else if (typeof ancien.name == 'string') {
|
|
|
|
return this.migrationNomDraconic(ancien.name)
|
|
|
|
}
|
|
|
|
return ancien;
|
|
|
|
}
|
|
|
|
async migrate() {
|
|
|
|
|
|
|
|
await this.applyItemsUpdates(items => items
|
|
|
|
.filter(it => ["sort", "sortreserve"].includes(it.type)
|
|
|
|
&& (typeof it.system.draconic == 'string') || (typeof it.system.draconic?.name == 'string'))
|
|
|
|
.map(it => { return { _id: it.id, "system.draconic": this.migrationNomDraconic(it.system.draconic)} }));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-17 16:07:38 +02:00
|
|
|
export class Migrations {
|
|
|
|
static getMigrations() {
|
|
|
|
return [
|
2022-09-20 00:12:25 +02:00
|
|
|
new _10_0_16_MigrationSortsReserve(),
|
2022-09-27 00:15:34 +02:00
|
|
|
new _10_0_17_MigrationCompetenceCreature(),
|
|
|
|
new _10_0_21_VehiculeStructureResistanceMax(),
|
2022-11-01 00:48:46 +01:00
|
|
|
new _10_0_33_MigrationNomsDraconic(),
|
2022-09-17 16:07:38 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
game.settings.register(SYSTEM_RDD, "systemMigrationVersion", {
|
|
|
|
name: "System Migration Version",
|
|
|
|
scope: "world",
|
|
|
|
config: false,
|
|
|
|
type: String,
|
|
|
|
default: "0.0.0",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
migrate() {
|
|
|
|
const currentVersion = game.settings.get(
|
|
|
|
SYSTEM_RDD,
|
|
|
|
"systemMigrationVersion"
|
|
|
|
);
|
|
|
|
if (isNewerVersion(game.system.version, currentVersion)) {
|
|
|
|
const migrations = Migrations.getMigrations().filter(m => isNewerVersion(m.version, currentVersion));
|
|
|
|
if (migrations.length > 0) {
|
|
|
|
migrations.sort((a, b) =>
|
|
|
|
isNewerVersion(a.version, b.version)
|
|
|
|
? 1
|
|
|
|
: isNewerVersion(b.version, a.version)
|
2022-09-20 00:12:25 +02:00
|
|
|
? -1
|
|
|
|
: 0
|
2022-09-17 16:07:38 +02:00
|
|
|
);
|
|
|
|
migrations.forEach(async (m) => {
|
|
|
|
ui.notifications.info(
|
|
|
|
`Executing migration ${m.code}: version ${currentVersion} is lower than ${m.version}`
|
|
|
|
);
|
|
|
|
await m.migrate();
|
|
|
|
});
|
|
|
|
ui.notifications.info(
|
|
|
|
`Migrations done, version will change to ${game.system.version}`
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
LOG_HEAD +
|
2022-09-20 00:12:25 +02:00
|
|
|
`No migration needeed, version will change to ${game.system.version}`
|
2022-09-17 16:07:38 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
game.settings.set(
|
|
|
|
SYSTEM_RDD,
|
|
|
|
"systemMigrationVersion",
|
|
|
|
game.system.version
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
console.log(LOG_HEAD + `No system version changed`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|