forked from public/foundryvtt-reve-de-dragon
		
	Cleanup init & start
- classe SystemReveDeDragon pour l'init/start - déplacement de la migration 1.5.34 dans les migrations
This commit is contained in:
		| @@ -29,6 +29,39 @@ class Migration { | ||||
|  | ||||
| } | ||||
|  | ||||
| class _1_5_34_migrationPngWebp { | ||||
|   get code() { return "migrationPngWebp"; } | ||||
|   get version() { return "1.5.34"; } | ||||
|   async migrate() { | ||||
|  | ||||
|     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 && 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.token?.img && actor.token.img.match(regexOldPngJpg)) { | ||||
|         actor.update({ "token.img": convertImgToWebp(actor.token.img) }); | ||||
|       } | ||||
|       const actorItemsToUpdate = prepareDocumentsImgUpdate(actor.items); | ||||
|       actor.updateEmbeddedDocuments('Item', actorItemsToUpdate); | ||||
|     }); | ||||
|   } | ||||
| } | ||||
|  | ||||
|  | ||||
| class _10_0_16_MigrationSortsReserve extends Migration { | ||||
|   get code() { return "creation-item-sort-reserve"; } | ||||
|   get version() { return "10.0.16"; } | ||||
| @@ -296,6 +329,7 @@ class _10_3_17_Monnaies extends Migration { | ||||
| export class Migrations { | ||||
|   static getMigrations() { | ||||
|     return [ | ||||
|       new _1_5_34_migrationPngWebp(), | ||||
|       new _10_0_16_MigrationSortsReserve(), | ||||
|       new _10_0_17_MigrationCompetenceCreature(), | ||||
|       new _10_0_21_VehiculeStructureResistanceMax(), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user