Skip to content

Commit

Permalink
Fix: Emdedded system not installed (#289)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Potts <[email protected]>
  • Loading branch information
misterpotts authored Feb 24, 2024
1 parent faee73f commit 90df8b1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
title: Fabricate 0.10.23
title: Fabricate 0.10.24
email: [email protected]
description: >-
End user documentation for the Foundry Virtual Tabletop (VTT) Module, "Fabricate".
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 4 additions & 3 deletions src/scripts/api/SettingMigrationAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void>;
restoreEmbeddedCraftingSystems(skipInstalled?: boolean): Promise<void>;

/**
* WARNING: This function will remove all user-defined crafting systems and restore the embedded crafting systems to
Expand Down Expand Up @@ -128,8 +129,8 @@ class DefaultSettingMigrationAPI implements SettingMigrationAPI {
}
}

async restoreEmbeddedCraftingSystems(): Promise<void> {
await this._embeddedCraftingSystemManager.restoreForGameSystem(this._gameSystemId);
async restoreEmbeddedCraftingSystems(skipInstalled: boolean = false): Promise<void> {
await this._embeddedCraftingSystemManager.restoreForGameSystem(this._gameSystemId, skipInstalled);
}

async clear(): Promise<void> {
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Properties from "../../Properties";

interface EmbeddedCraftingSystemManager {

restoreForGameSystem(gameSystemId: string): Promise<void>;
restoreForGameSystem(gameSystemId: string, skipInstalled: boolean): Promise<void>;

}

Expand Down Expand Up @@ -47,9 +47,13 @@ class DefaultEmbeddedCraftingSystemManager implements EmbeddedCraftingSystemMana
this._embeddedCraftingSystems = embeddedCraftingSystems;
}

async restoreForGameSystem(gameSystemId: string): Promise<void> {
async restoreForGameSystem(gameSystemId: string, skipInstalled: boolean): Promise<void> {
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)));
}

Expand All @@ -66,7 +70,22 @@ class DefaultEmbeddedCraftingSystemManager implements EmbeddedCraftingSystemMana
await this._restoreRecipes(embeddedSystemDefinition.recipes);
}

private async _restoreEmbeddedCraftingSystemIfNotInstalled(embeddedSystemDefinition: EmbeddedCraftingSystemDefinition): Promise<void> {
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<void> {
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);
}

Expand Down

0 comments on commit 90df8b1

Please sign in to comment.