Skip to content

Commit

Permalink
Defect: Source actor should only change components (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
misterpotts authored Oct 18, 2023
1 parent ce3df2c commit 5f6cfb5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 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.6
title: Fabricate 0.10.7
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.6",
"version": "0.10.7",
"description": "A system-agnostic, flexible crafting module for FoundryVT",
"main": "index.js",
"type": "module",
Expand Down
6 changes: 4 additions & 2 deletions src/applications/actorCraftingApp/ActorCraftingApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import type {RecipeSummary} from "./RecipeSummary";
import truncate from "../common/Truncate";
import Properties from "../../scripts/Properties";
import ClickEvent = JQuery.ClickEvent;
/*
* ===========================================================================
Expand Down Expand Up @@ -98,7 +97,10 @@
}
async function prepareRecipes() {
summarisedRecipes = await fabricateAPI.crafting.summariseRecipes({ sourceActorId: sourceActorDetails.id });
summarisedRecipes = await fabricateAPI.crafting.summariseRecipes({
targetActorId: targetActorDetails.id,
sourceActorId: sourceActorDetails.id ? sourceActorDetails.id : undefined
});
}
function handleRecipeSummaryClicked(event: PointerEvent, recipeSummary: RecipeSummary) {
Expand Down
23 changes: 15 additions & 8 deletions src/scripts/api/CraftingAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,15 @@ interface CraftingAPI {
* crafted, if at all.
*
* @param options - The options to use when summarising recipes.
* @param options.sourceActorId - The ID of the actor to summarise recipes for.
* @param options.sourceActorId - The optional ID of the actor to use as a source for components. Defaults to the
* targetActorId.
* @param options.targetActorId - The ID of the actor to use as a source for recipes
* @param options.craftingSystemId - The ID of the crafting system to limit the summary to. If not specified, all
* recipes for all crafting systems will be summarised.
* @param options.craftableOnly - If true, only recipes that can be crafted will be included in the summary.
* @returns A Promise that resolves with an array of recipe summaries.
*/
summariseRecipes(options: { sourceActorId: string, craftingSystemId?: string, craftableOnly?: boolean }): Promise<RecipeSummary[]>;
summariseRecipes(options: { sourceActorId?: string, targetActorId: string, craftingSystemId?: string, craftableOnly?: boolean }): Promise<RecipeSummary[]>;

}

Expand Down Expand Up @@ -286,11 +288,13 @@ class DefaultCraftingAPI implements CraftingAPI {
}

async summariseRecipes({
sourceActorId,
targetActorId,
sourceActorId = targetActorId,
craftingSystemId,
craftableOnly = false
}: {
sourceActorId: string;
sourceActorId?: string;
targetActorId: string;
craftingSystemId?: string;
craftableOnly?: boolean;
}): Promise<RecipeSummary[]> {
Expand All @@ -305,16 +309,19 @@ class DefaultCraftingAPI implements CraftingAPI {
.filter(component => craftingSystems.has(component.craftingSystemId));

const gameSystemId = this.gameProvider.getGameSystemId();
const actor = await this.gameProvider.loadActor(sourceActorId);
const inventory = this.inventoryFactory.make(gameSystemId, actor, includedComponents, includedRecipes);
const ownedRecipes = inventory.getOwnedRecipes();
const targetActor = await this.gameProvider.loadActor(targetActorId);
const targetActorOnly = sourceActorId === targetActorId;
const sourceActor = targetActorOnly ? targetActor : await this.gameProvider.loadActor(sourceActorId);
const targetInventory = this.inventoryFactory.make(gameSystemId, targetActor, includedComponents, includedRecipes);
const sourceInventory = targetActorOnly ? targetInventory : this.inventoryFactory.make(gameSystemId, sourceActor, includedComponents, includedRecipes);
const ownedRecipes = targetInventory.getOwnedRecipes();

const includedComponentsById = new Map(includedComponents.map(component => [component.id, component]));
const allEssencesById = await this.essenceAPI.getAll();
const summarisedRecipes = await Promise.all(includedRecipes
.filter(recipe => ownedRecipes.has(recipe))
.map(recipe => {
return this.summariseRecipe(recipe, inventory, includedComponentsById, allEssencesById);
return this.summariseRecipe(recipe, sourceInventory, includedComponentsById, allEssencesById);
}));

if (craftableOnly) {
Expand Down

0 comments on commit 5f6cfb5

Please sign in to comment.