Skip to content

Commit

Permalink
Feat: Actor crafting app salvage switch source actor (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
misterpotts authored Nov 14, 2023
1 parent 306d6ad commit 23fa902
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 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.13
title: Fabricate 0.10.14
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.13",
"version": "0.10.14",
"description": "A system-agnostic, flexible crafting module for FoundryVT",
"main": "index.js",
"type": "module",
Expand Down
6 changes: 6 additions & 0 deletions src/applications/actorCraftingApp/ActorCraftingApp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
async function handleSourceActorChanged(event: CustomEvent<ActorDetails>) {
sourceActorDetails = event.detail;
await load();
if (salvageProcess.isReady) {
salvageProcess = await fabricateAPI.crafting.getSalvageProcess({
componentId: salvageProcess.componentId,
actorId: sourceActorDetails.id
});
}
}
async function salvageComponent(event: CustomEvent<SalvageProcess>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
const dispatch = createEventDispatcher();
$: displayAmount = calculateDisplayAmount(batchSize, salvageProcess.ownedQuantity);
let selectedSalvageOption: SalvageOption = salvageProcess.selectedOption;
$: {
selectedSalvageOption = salvageProcess.selectedOption;
}
$: salvageProcessProducts = selectedSalvageOption.products;
$: salvageProcessCatalysts = selectedSalvageOption.catalysts;
$: selectedOptionName = selectedSalvageOption.name;
Expand Down
14 changes: 7 additions & 7 deletions src/scripts/api/CraftingAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
} from "../../applications/actorCraftingApp/SalvageAssessment";
import {
DefaultSalvageOption,
DefaultSalvageProcess,
DefaultSalvageProcess, NoSalvageProcess,
SalvageOption,
SalvageProcess
} from "../../applications/actorCraftingApp/SalvageProcess";
Expand Down Expand Up @@ -327,6 +327,7 @@ class DefaultCraftingAPI implements CraftingAPI {
}

async getSalvageProcess({ componentId, actorId }: { componentId: string; actorId: string }): Promise<SalvageProcess> {

const componentToSalvage = await this.componentAPI.getById(componentId);
await componentToSalvage.load();
const actor = await this.gameProvider.loadActor(actorId);
Expand All @@ -336,14 +337,11 @@ class DefaultCraftingAPI implements CraftingAPI {
const knownRecipesById = await this.recipeAPI.getAllByCraftingSystemId(componentToSalvage.craftingSystemId);
const knownRecipes = Array.from(knownRecipesById.values());
const inventory = this.inventoryFactory.make(gameSystemId, actor, knownComponents, knownRecipes);

if (!inventory.getContents().has(componentToSalvage)) {
const message = this.localizationService.format(
`${DefaultCraftingAPI._LOCALIZATION_PATH}.salvage.componentNotOwned`,
{ componentName: componentToSalvage.name }
);
this.notificationService.error(message);
throw new Error(message);
return new NoSalvageProcess();
}

const salvageOptions = componentToSalvage.salvageOptions.all
.map(salvageOption => {
return new DefaultSalvageOption({
Expand All @@ -361,13 +359,15 @@ class DefaultCraftingAPI implements CraftingAPI {
name: salvageOption.name,
value: salvageOption,
}));

return new DefaultSalvageProcess({
options: new DefaultSelectableOptions<SalvageOption>({options: salvageOptions}),
componentName: componentToSalvage.name,
componentId: componentToSalvage.id,
componentImageUrl: componentToSalvage.imageUrl,
ownedQuantity: inventory.getContents().amountFor(componentToSalvage),
});

}

async assessCrafting({
Expand Down

0 comments on commit 23fa902

Please sign in to comment.