Initiative et competences créatures

Fix de l'initiative des compétences de créatures
* armes naturelles en général
* lancer pour les pierres lancées des Glous et Mariols

La catégorie de parade: remplace l'utilisation de "isparade"

Migration autoimatique des items du monde
Modification des compendiums
This commit is contained in:
Vincent Vandemeulebrouck
2022-09-20 00:12:25 +02:00
parent 50980d5216
commit 28427bc7c7
8 changed files with 194 additions and 138 deletions

View File

@ -1,9 +1,31 @@
import { LOG_HEAD, SYSTEM_RDD } from "./constants.js";
import { Grammar } from "./grammar.js";
class Migration {
get code() { return "sample"; }
get version() { return "0.0.0"; }
async migrate() { }
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);
}
}
}
class _10_0_16_MigrationSortsReserve extends Migration {
@ -20,7 +42,7 @@ class _10_0_16_MigrationSortsReserve extends Migration {
await actor.createEmbeddedDocuments("Item", sortsReserve, {
renderSheet: false,
});
await actor.update({'system.reve.reserve.list':[]})
await actor.update({ 'system.reve.reserve.list': [] })
});
}
@ -41,10 +63,28 @@ class _10_0_16_MigrationSortsReserve extends Migration {
}
}
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") } })
);
}
}
export class Migrations {
static getMigrations() {
return [
new _10_0_16_MigrationSortsReserve()
new _10_0_16_MigrationSortsReserve(),
new _10_0_17_MigrationCompetenceCreature()
];
}
@ -65,15 +105,13 @@ export class Migrations {
);
if (isNewerVersion(game.system.version, currentVersion)) {
const migrations = Migrations.getMigrations().filter(m => isNewerVersion(m.version, currentVersion));
// if (true) {
// const migrations = Migrations.getMigrations();
if (migrations.length > 0) {
migrations.sort((a, b) =>
isNewerVersion(a.version, b.version)
? 1
: isNewerVersion(b.version, a.version)
? -1
: 0
? -1
: 0
);
migrations.forEach(async (m) => {
ui.notifications.info(
@ -87,7 +125,7 @@ export class Migrations {
} else {
console.log(
LOG_HEAD +
`No migration needeed, version will change to ${game.system.version}`
`No migration needeed, version will change to ${game.system.version}`
);
}