Migration png webp
This commit is contained in:
@ -8,6 +8,7 @@
|
||||
|
||||
/* -------------------------------------------- */
|
||||
// Import Modules
|
||||
import { SYSTEM_RDD } from "./constants.js";
|
||||
import { RdDActor } from "./actor.js";
|
||||
import { RdDItemSheet } from "./item-sheet.js";
|
||||
import { RdDActorSheet } from "./actor-sheet.js";
|
||||
@ -77,7 +78,16 @@ Hooks.once("init", async function () {
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register("foundryvtt-reve-de-dragon", "liste-nombre-astral", {
|
||||
game.settings.register(SYSTEM_RDD, "migration-png-webp-1.5.34", {
|
||||
name: "calendrier",
|
||||
scope: "world",
|
||||
config: false,
|
||||
default: false,
|
||||
type: Boolean
|
||||
});
|
||||
|
||||
/* -------------------------------------------- */
|
||||
game.settings.register(SYSTEM_RDD, "liste-nombre-astral", {
|
||||
name: "liste-nombre-astral",
|
||||
scope: "world",
|
||||
config: false,
|
||||
@ -216,6 +226,7 @@ function messageDeBienvenue() {
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
Hooks.once("ready", async function () {
|
||||
await migrationPngWebp_1_5_34()
|
||||
|
||||
StatusEffects.onReady();
|
||||
RdDHerbes.initializeHerbes();
|
||||
@ -237,12 +248,41 @@ Hooks.once("ready", async function () {
|
||||
content: "<b>ATTENTION</b> Le joueur " + game.user.name + " n'est connecté à aucun personnage !",
|
||||
user: game.user.id
|
||||
});
|
||||
//whisper: [ ChatMessage.getWhisperRecipients("GM") ] } );
|
||||
}
|
||||
|
||||
messageDeBienvenue();
|
||||
if (game.user.isGM) {
|
||||
messageDeBienvenue();
|
||||
}
|
||||
});
|
||||
|
||||
async function migrationPngWebp_1_5_34() {
|
||||
if (!game.settings.get(SYSTEM_RDD, "migration-png-webp-1.5.34")) {
|
||||
const regexOldPngJpg = /(systems\/foundryvtt-reve-de-dragon\/icons\/.*)\.(png|jpg)/;
|
||||
const replaceWithWebp = '$1.webp';
|
||||
function convertImgToWebp(img) {
|
||||
return img.replace(regexOldPngJpg, replaceWithWebp);
|
||||
}
|
||||
function prepareDocumentsImgUpdate(documents) {
|
||||
return documents.filter(it => it.img.match(regexOldPngJpg))
|
||||
.map(it => {
|
||||
return { _id: it.id, img: convertImgToWebp(it.img) }
|
||||
});
|
||||
}
|
||||
const itemsUpdates = prepareDocumentsImgUpdate(game.items);
|
||||
const actorsUpdates = prepareDocumentsImgUpdate(game.actors);
|
||||
//Migrate system png to webp
|
||||
await Item.updateDocuments(itemsUpdates);
|
||||
await Actor.updateDocuments(actorsUpdates);
|
||||
game.actors.forEach(actor => {
|
||||
if (actor.data.token.img.match(regexOldPngJpg)){
|
||||
actor.update({ "data.token.img": convertImgToWebp(actor.data.token.img) });
|
||||
}
|
||||
const actorItemsToUpdate = prepareDocumentsImgUpdate(actor.items);
|
||||
actor.updateEmbeddedDocuments('Item', actorItemsToUpdate);
|
||||
});
|
||||
game.settings.set(SYSTEM_RDD, "migration-png-webp-1.5.34", true)
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Dice-so-nice ready */
|
||||
/* -------------------------------------------- */
|
||||
|
Reference in New Issue
Block a user