Skip to content

Commit

Permalink
Feat: Search and view recipes in the new Actor Crafting App (#215)
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 Nov 8, 2023
1 parent a2f584d commit b2df256
Show file tree
Hide file tree
Showing 16 changed files with 660 additions and 107 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.7
title: Fabricate 0.10.8
email: [email protected]
description: >-
End user documentation for the Foundry Virtual Tabletop (VTT) Module, "Fabricate".
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

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.7",
"version": "0.10.8",
"description": "A system-agnostic, flexible crafting module for FoundryVT",
"main": "index.js",
"type": "module",
Expand Down
288 changes: 229 additions & 59 deletions src/applications/actorCraftingApp/ActorCraftingApp.svelte

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/applications/actorCraftingApp/ActorCraftingAppFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export { ActorCraftingAppFactory }

class DefaultActorCraftingAppFactory implements ActorCraftingAppFactory {

private static readonly DEFAULT_VIEW: ActorCraftingAppViewType = ActorCraftingAppViewType.BROWSE_RECIPES;
private static readonly DEFAULT_VIEW: ActorCraftingAppViewType = ActorCraftingAppViewType.SALVAGING;

private readonly localizationService: LocalizationService;
private readonly fabricateAPI: FabricateAPI;
Expand All @@ -51,7 +51,7 @@ class DefaultActorCraftingAppFactory implements ActorCraftingAppFactory {
const applicationOptions = {
title: this.localizationService.localize(`${Properties.module.id}.ActorCraftingApp.title`),
id: Properties.ui.apps.actorCraftingApp.id,
resizable: true,
resizable: false,
width: 1020,
height: 780
}
Expand Down
2 changes: 0 additions & 2 deletions src/applications/actorCraftingApp/ActorCraftingAppViewType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ enum ActorCraftingAppViewType {

CRAFTING = "crafting",
SALVAGING = "salvaging",
BROWSE_RECIPES = "browse-recipes",
BROWSE_COMPONENTS = "browse-components",

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ type SelectableRequirementOptionSummary = { name: string, id: string };

export { SelectableRequirementOptionSummary }

interface RecipeSummary {
interface CraftingAssessment {

isCraftable: boolean;

isDisabled: boolean;

id: string;
recipeId: string;

name: string;
recipeName: string;

imageUrl: string;

selectableOptions: SelectableRequirementOptionSummary[];

}

export { RecipeSummary }
export { CraftingAssessment }

class DisabledRecipeSummary implements RecipeSummary {
class DisabledCraftingAssessment implements CraftingAssessment {

private readonly _id: string;
private readonly _name: string;
Expand All @@ -40,11 +40,11 @@ class DisabledRecipeSummary implements RecipeSummary {
return true;
}

get id(): string {
get recipeId(): string {
return this._id;
}

get name(): string {
get recipeName(): string {
return this._name;
}

Expand All @@ -58,9 +58,9 @@ class DisabledRecipeSummary implements RecipeSummary {

}

export { DisabledRecipeSummary }
export { DisabledCraftingAssessment }

class CraftableRecipeSummary implements RecipeSummary {
class DefaultCraftingAssessment implements CraftingAssessment {

private readonly _id: string;
private readonly _name: string;
Expand Down Expand Up @@ -92,11 +92,11 @@ class CraftableRecipeSummary implements RecipeSummary {
return false;
}

get id(): string {
get recipeId(): string {
return this._id;
}

get name(): string {
get recipeName(): string {
return this._name;
}

Expand All @@ -110,9 +110,9 @@ class CraftableRecipeSummary implements RecipeSummary {

}

export { CraftableRecipeSummary }
export { DefaultCraftingAssessment }

class UncraftableRecipeSummary implements RecipeSummary {
class ImpossibleCraftingAssessment implements CraftingAssessment {

private readonly _id: string;
private readonly _name: string;
Expand All @@ -132,11 +132,11 @@ class UncraftableRecipeSummary implements RecipeSummary {
return false;
}

get id(): string {
get recipeId(): string {
return this._id;
}

get name(): string {
get recipeName(): string {
return this._name;
}

Expand All @@ -150,4 +150,4 @@ class UncraftableRecipeSummary implements RecipeSummary {

}

export { UncraftableRecipeSummary }
export { ImpossibleCraftingAssessment }
47 changes: 47 additions & 0 deletions src/applications/actorCraftingApp/CraftingProcess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
interface CraftingProcess {

readonly isReady: boolean;

readonly recipeName: string;

}

export { CraftingProcess };

class DefaultCraftingProcess implements CraftingProcess {

private readonly _recipeName: string;

constructor({
recipeName,
}: {
recipeName: string;
}) {
this._recipeName = recipeName;
}

get recipeName(): string {
return this._recipeName;
}

get isReady(): boolean {
return true;
}

}

export { DefaultCraftingProcess };

class NoCraftingProcess implements CraftingProcess {

get recipeName(): string {
return "No Recipe";
}

get isReady(): boolean {
return false;
}

}

export { NoCraftingProcess };
71 changes: 71 additions & 0 deletions src/applications/actorCraftingApp/RecipeSummarySearchStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import {writable, Writable, Readable, derived, Subscriber} from "svelte/store";
import {CraftingAssessment} from "./CraftingAssessment";

interface RecipeSummarySearchTerms {

name?: string;
craftableOnly?: boolean;

}

class RecipeSummarySearchStore {

private readonly _availableRecipes: Writable<CraftingAssessment[]>;
private readonly _searchResults: Readable<CraftingAssessment[]>;
private readonly _searchTerms: Writable<RecipeSummarySearchTerms>;

constructor({
availableRecipes = writable([]),
searchTerms = {}
}: {
availableRecipes?: Writable<CraftingAssessment[]>;
searchTerms?: RecipeSummarySearchTerms;
} = {}) {
this._availableRecipes = availableRecipes;
this._searchTerms = writable(searchTerms);
this._searchResults = derived(
[this._availableRecipes, this._searchTerms],
([$availableRecipes, $searchTerms], set) => {
set(this.searchRecipes($availableRecipes, $searchTerms));
}
);
}

set availableRecipes(value: CraftingAssessment[]) {
this._availableRecipes.set(value);
}

private searchRecipes(recipes: CraftingAssessment[], searchTerms: RecipeSummarySearchTerms) {
return recipes.filter((recipe) => {
if (searchTerms.craftableOnly && !recipe.isCraftable) {
return false;
}
if (!searchTerms.name) {
return true;
}
return recipe.recipeName.search(new RegExp(searchTerms.name, "i")) >= 0;
});
}

public subscribe(subscriber: Subscriber<RecipeSummarySearchTerms[]>) {
return this._searchResults.subscribe(subscriber);
}

get searchTerms(): Readable<RecipeSummarySearchTerms> {
return this._searchTerms;
}

set searchTerms(value: RecipeSummarySearchTerms) {
this._searchTerms.set(value);
}

clear() {
this._searchTerms.set({
name: "",
craftableOnly: false
});
}

}

export { RecipeSummarySearchStore, RecipeSummarySearchTerms }
Loading

0 comments on commit b2df256

Please sign in to comment.