Skip to content

Commit

Permalink
feat: Fabricate API V2 2 (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
misterpotts authored Sep 9, 2023
1 parent e48f74e commit b84e572
Show file tree
Hide file tree
Showing 216 changed files with 18,813 additions and 9,611 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/coverage/
/dist
/.idea/watcherTasks.xml
/test/__snapshots__/
3 changes: 3 additions & 0 deletions .idea/fabricate.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 18 additions & 18 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ interface CraftingSystemDetailsJson {
}

interface PartDictionaryJson {
components: Record<string, CraftingComponentJson>;
components: Record<string, ComponentJson>;
recipes: Record<string, RecipeJson>;
essences: Record<string, EssenceJson>;
}
Expand Down Expand Up @@ -210,16 +210,16 @@ console.log(`Created crafting system with ID "${craftingSystem.id}"`); // <-- Yo

## Add a component to a crafting system

A crafting component is specified by the `CraftingComponentJson` interface.
A crafting component is specified by the `ComponentJson` interface.

<details open markdown="block">
<summary>
CraftingComponentJson Interface
ComponentJson Interface
</summary>

```typescript
interface CraftingComponentJson {

interface ComponentJson {
/**
* The UUID of the Item document for this component
* */
Expand Down Expand Up @@ -326,18 +326,18 @@ CraftingSystem#mutateComponent

```typescript
/**
* Modifies an existing component by applying the mutations defined in the supplied `CraftingComponentJson`
*
* @param id The ID of the component to modify
* @param the complete target state of the component to apply. Anything you omit is deleted
* @return a Promise that resolves to the updated crafting component
*
* @throws an Error if the ID is not for an existing component
* @throws an Error if the the component dictionary has not been loaded
* @throws an Error if the mutation contains an invalid item UUID
* @throws an Error if the mutation references essences or components that do not exist
* */
mutateComponent(id: string, mutation: CraftingComponentJson): Promise<CraftingComponent>;
* Modifies an existing component by applying the mutations defined in the supplied `ComponentJson`
*
* @param id The ID of the component to modify
* @param the complete target state of the component to apply. Anything you omit is deleted
* @return a Promise that resolves to the updated crafting component
*
* @throws an Error if the ID is not for an existing component
* @throws an Error if the the component dictionary has not been loaded
* @throws an Error if the mutation contains an invalid item UUID
* @throws an Error if the mutation references essences or components that do not exist
* */
mutateComponent(id: string, mutation: ComponentJson): Promise<Component>;
```

</details>
Expand All @@ -354,7 +354,7 @@ console.log(`Before modification: ${myComponent}`);
const componentData = myComponent.toJson();
componentData.salvageOptions["My new Salvage Option"] = { "rLP3cTCTnQsxddDt": 1 } // Adds a new salvage option
componentData.essences["bGfx37pYjqlf812"] = 3; // Adds an essence with a quantity of 3
// perform any other modifications you want here. You can alter any of the fields in the `CraftingComponentJson`,
// perform any other modifications you want here. You can alter any of the fields in the `ComponentJson`,
// including the item UUID. The new values meet the requirements specified in the interface.
const updatedComponent = await craftingSystem.mutateComponent(myComponent.id, componentData);
await game.fabricate.SystemRegistry.saveCraftingSystem(craftingSystem);
Expand Down
Loading

0 comments on commit b84e572

Please sign in to comment.