From dfda17ced3153f3e4fa167d7a7fab8d05eb3e12b Mon Sep 17 00:00:00 2001 From: Matt Potts Date: Fri, 13 Oct 2023 21:55:41 +0100 Subject: [PATCH] Feat: Data download for debugging (#198) Co-authored-by: Matt Potts --- docs/_config.yml | 2 +- docs/api/index.md | 6 ++++++ package.json | 2 +- src/scripts/api/FabricateAPI.ts | 19 ++++++++++++++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index d10d1d4a..985ae328 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,4 +1,4 @@ -title: Fabricate 0.10.4 +title: Fabricate 0.10.5 email: matt@misterpotts.uk description: >- End user documentation for the Foundry Virtual Tabletop (VTT) Module, "Fabricate". diff --git a/docs/api/index.md b/docs/api/index.md index 5180378f..3d1339e6 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -144,6 +144,12 @@ interface FabricateAPI { */ export(craftingSystemId: string): Promise; + /** + * Downloads a copy of all Fabricate data as a JSON file. This function is used for debugging and troubleshooting. + * If you want to export data from Fabricate for use in another Foundry VTT world, use {@link FabricateAPI#export} + */ + downloadData(): void; + } ``` diff --git a/package.json b/package.json index 80a66b69..143a56f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fabricate", - "version": "0.10.4", + "version": "0.10.5", "description": "A system-agnostic, flexible crafting module for FoundryVT", "main": "index.js", "type": "module", diff --git a/src/scripts/api/FabricateAPI.ts b/src/scripts/api/FabricateAPI.ts index 5ef6c8d3..e7634a0c 100644 --- a/src/scripts/api/FabricateAPI.ts +++ b/src/scripts/api/FabricateAPI.ts @@ -211,6 +211,12 @@ interface FabricateAPI { */ export(craftingSystemId: string): Promise; + /** + * Downloads a copy of all Fabricate data as a JSON file. This function is used for debugging and troubleshooting. + * If you want to export data from Fabricate for use in another Foundry VTT world, use {@link FabricateAPI#export} + */ + downloadData(): void; + } export { FabricateAPI } @@ -259,6 +265,18 @@ class DefaultFabricateAPI implements FabricateAPI { this.settingMigrationAPI = settingMigrationAPI; } + downloadData(): void { + const allFabricateSettingValues = Array.from(game.settings.storage.get("world").values()) + .filter((setting: any) => setting.key.search(new RegExp("fabricate", "i")) >= 0); + const fileContents = JSON.stringify(allFabricateSettingValues, null, 2); + const dateTime = new Date(); + const postfix = dateTime.toISOString() + .replace(/:\s*/g, "-") + .replace(".", "-"); + const fileName = `fabricate-data-extract-${postfix}.json`; + saveDataToFile(fileContents, "application/json", fileName); + } + get documentManager(): DocumentManager { return this._documentManager; } @@ -448,7 +466,6 @@ class DefaultFabricateAPI implements FabricateAPI { async import(importData: FabricateExportModel): Promise { - importData = this.upgradeV1ImportData(importData); await this.validateImportData(importData);