Skip to content

Commit

Permalink
Feat: Data download for debugging (#198)
Browse files Browse the repository at this point in the history
Co-authored-by: Matt Potts <matt@@mrpotts.uk>
  • Loading branch information
misterpotts and Matt Potts authored Oct 13, 2023
1 parent dcf344d commit dfda17c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 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.4
title: Fabricate 0.10.5
email: [email protected]
description: >-
End user documentation for the Foundry Virtual Tabletop (VTT) Module, "Fabricate".
Expand Down
6 changes: 6 additions & 0 deletions docs/api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ interface FabricateAPI {
*/
export(craftingSystemId: string): Promise<FabricateExportModel>;

/**
* 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;

}
```

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.4",
"version": "0.10.5",
"description": "A system-agnostic, flexible crafting module for FoundryVT",
"main": "index.js",
"type": "module",
Expand Down
19 changes: 18 additions & 1 deletion src/scripts/api/FabricateAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@ interface FabricateAPI {
*/
export(craftingSystemId: string): Promise<FabricateExportModel>;

/**
* 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 }
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -448,7 +466,6 @@ class DefaultFabricateAPI implements FabricateAPI {

async import(importData: FabricateExportModel): Promise<CraftingSystemData> {


importData = this.upgradeV1ImportData(importData);
await this.validateImportData(importData);

Expand Down

0 comments on commit dfda17c

Please sign in to comment.