diff --git a/docs/_config.yml b/docs/_config.yml index 26694e9b..3b452fca 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,4 +1,4 @@ -title: Fabricate 0.10.23 +title: Fabricate 0.10.24 email: matt@misterpotts.uk description: >- End user documentation for the Foundry Virtual Tabletop (VTT) Module, "Fabricate". diff --git a/package.json b/package.json index 2c8959e9..a126d178 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fabricate", - "version": "0.10.23", + "version": "0.10.24", "description": "A system-agnostic, flexible crafting module for FoundryVT", "main": "index.js", "type": "module", diff --git a/src/scripts/api/SettingMigrationAPI.ts b/src/scripts/api/SettingMigrationAPI.ts index fe5b3b4d..2737f6f2 100644 --- a/src/scripts/api/SettingMigrationAPI.ts +++ b/src/scripts/api/SettingMigrationAPI.ts @@ -46,8 +46,9 @@ interface SettingMigrationAPI { * embedded crafting systems. * * @async + * @param skipInstalled - do not restore embedded systems that are installed, only insert missing systems. Defaults to `false`. */ - restoreEmbeddedCraftingSystems(): Promise; + restoreEmbeddedCraftingSystems(skipInstalled?: boolean): Promise; /** * WARNING: This function will remove all user-defined crafting systems and restore the embedded crafting systems to @@ -128,8 +129,8 @@ class DefaultSettingMigrationAPI implements SettingMigrationAPI { } } - async restoreEmbeddedCraftingSystems(): Promise { - await this._embeddedCraftingSystemManager.restoreForGameSystem(this._gameSystemId); + async restoreEmbeddedCraftingSystems(skipInstalled: boolean = false): Promise { + await this._embeddedCraftingSystemManager.restoreForGameSystem(this._gameSystemId, skipInstalled); } async clear(): Promise { diff --git a/src/scripts/module.ts b/src/scripts/module.ts index 45966853..446fd52f 100644 --- a/src/scripts/module.ts +++ b/src/scripts/module.ts @@ -102,6 +102,8 @@ Hooks.once(`${Properties.module.id}.ready`, async (fabricateAPI: FabricateAPI) = await fabricateAPI.migration.migrateAll(); } + await fabricateAPI.migration.restoreEmbeddedCraftingSystems(true); + }); Hooks.on("deleteItem", async (item: any) => { diff --git a/src/scripts/repository/embedded_systems/EmbeddedCraftingSystemManager.ts b/src/scripts/repository/embedded_systems/EmbeddedCraftingSystemManager.ts index 252ca6c0..a4196b7f 100644 --- a/src/scripts/repository/embedded_systems/EmbeddedCraftingSystemManager.ts +++ b/src/scripts/repository/embedded_systems/EmbeddedCraftingSystemManager.ts @@ -9,7 +9,7 @@ import Properties from "../../Properties"; interface EmbeddedCraftingSystemManager { - restoreForGameSystem(gameSystemId: string): Promise; + restoreForGameSystem(gameSystemId: string, skipInstalled: boolean): Promise; } @@ -47,9 +47,13 @@ class DefaultEmbeddedCraftingSystemManager implements EmbeddedCraftingSystemMana this._embeddedCraftingSystems = embeddedCraftingSystems; } - async restoreForGameSystem(gameSystemId: string): Promise { + async restoreForGameSystem(gameSystemId: string, skipInstalled: boolean): Promise { const embeddedCraftingSystemsForGameSystem = this._embeddedCraftingSystems .filter(embeddedSystemDefinition => embeddedSystemDefinition.supportedGameSystem === gameSystemId); + if (skipInstalled) { + await Promise.all(embeddedCraftingSystemsForGameSystem.map(embeddedSystemDefinition => this._restoreEmbeddedCraftingSystemIfNotInstalled(embeddedSystemDefinition))); + return; + } await Promise.all(embeddedCraftingSystemsForGameSystem.map(embeddedSystemDefinition => this._restoreEmbeddedCraftingSystem(embeddedSystemDefinition))); } @@ -66,7 +70,22 @@ class DefaultEmbeddedCraftingSystemManager implements EmbeddedCraftingSystemMana await this._restoreRecipes(embeddedSystemDefinition.recipes); } + private async _restoreEmbeddedCraftingSystemIfNotInstalled(embeddedSystemDefinition: EmbeddedCraftingSystemDefinition): Promise { + const isInstalled = await this._craftingSystemStore.has(embeddedSystemDefinition.craftingSystem.id); + if (isInstalled) { + console.log(`Fabricate | Embedded crafting system ${embeddedSystemDefinition.craftingSystem.id} is already installed. Skipping installation.`); + return; + } + console.log(`Fabricate | Installing embedded crafting system ${embeddedSystemDefinition.craftingSystem.id}.`) + return this._restoreEmbeddedCraftingSystem(embeddedSystemDefinition); + } + private async _restoreCraftingSystem(craftingSystem: CraftingSystem): Promise { + const systemInstalled = await this._craftingSystemStore.has(craftingSystem.id); + if (systemInstalled) { + const installedSystem = await this._craftingSystemStore.getById(craftingSystem.id); + craftingSystem.isDisabled = installedSystem.isDisabled; + } await this._craftingSystemStore.insert(craftingSystem); }