Skip to content

Commit

Permalink
start showing the output goods
Browse files Browse the repository at this point in the history
  • Loading branch information
IanGrainger committed Mar 29, 2024
1 parent 82287a9 commit c91a43d
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { OptionsProvider } from './providers/OptionsProvider';
import { ResourcesSelect } from './components/ResourcesSelect';
import { BiomeSelect } from './components/BiomeSelect';
import biomes from './data/biomes.json';
import { GoodsList } from './components/GoodsList';

export const App: Component = () => {
const selectedBuildingsSignal = createSignal([] as string[]);
Expand All @@ -27,7 +28,12 @@ export const App: Component = () => {
<BiomeSelect signal={selectedBiomeSignal} />
<ResourcesSelect signal={selectedResourcesSignal} />
<BuildingSelect signal={selectedBuildingsSignal} />
{/* don't actually need this now we are showing outputs? */}
<BuildingList showNamesAccr={selectedBuildingsSignal[0]} />
<GoodsList
buildingsAccr={selectedBuildingsSignal[0]}
resourcesAccr={selectedResourcesSignal[0]}
/>
</OptionsProvider>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/BiomeSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const BiomeSelect: Component<{ signal: Signal<string> }> = (props) => {
return (
<div class="flex flex-row">
<Select
placeholder="Reset resources to biome..."
placeholder="Set resources to biome..."
class="biomeSelect"
onChange={onChange}
initialValue={initialValue()}
Expand Down
15 changes: 4 additions & 11 deletions src/components/BuildingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { Accessor, Component } from 'solid-js';
import { For, Show } from 'solid-js';
import recipesByBuilding from 'src/data/recipesByBuilding.json';
import { useOptionsContext } from 'src/providers/OptionsProvider';
import {
makeBuildingIconPart,
makeResourceIconPart,
} from '../functions/IconNameUtils';

export const BuildingList: Component<{ showNamesAccr: Accessor<string[]> }> = (
props
Expand Down Expand Up @@ -78,14 +82,3 @@ export const BuildingList: Component<{ showNamesAccr: Accessor<string[]> }> = (
</div>
);
};

function makeBuildingIconPart(buildingName: string) {
return buildingName
.replace(/^Flawless /, '')
.replace(/'/g, '')
.replace(/ /g, '_');
}

function makeResourceIconPart(resourceName: string) {
return resourceName.replace(/ /g, '');
}
74 changes: 74 additions & 0 deletions src/components/GoodsList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Component, Accessor, Show } from 'solid-js';
import recipesByBuilding from 'src/data/recipesByBuilding.json';
import { makeResourceIconPart } from 'src/functions/IconNameUtils';
import { useOptionsContext } from 'src/providers/OptionsProvider';

export const GoodsList: Component<{
buildingsAccr: Accessor<string[]>;
resourcesAccr: Accessor<string[]>;
}> = (props) => {
const getGoods = () =>
// for each building, if one or more of each ingredient is in the resources list, add the output to the list
// todo: also include outputs from other buildings that are inputs to the current building
Object.keys(recipesByBuilding)
.filter((building) => props.buildingsAccr().includes(building))
.flatMap((building) =>
recipesByBuilding[building].filter((recipe) => {
const ingredients = [
recipe.Ingredient_1,
recipe.Ingredient_2 || null,
recipe.Ingredient_3 || null,
].filter((x) => x);
console.log(
'recipe',
Object.keys(recipe.Product),
'ingredients',
ingredients
);
return ingredients.every((ingredient) =>
props
.resourcesAccr()
.some((resource) => Object.keys(ingredient).includes(resource))
);
})
)
.flatMap((recipe) => Object.keys(recipe.Product));
const [options] = useOptionsContext();

return (
<div class="p-2">
<h2 class="text-lg">Goods from resources</h2>
<ul class="flex">
{getGoods().map((productName) => (
<li>
<div class="flex space-x-1 mr-1">
<div>
<Show when={options.showRecipeIcons}>
<img
src={`./icons/resources/60px-Icon_Resource_${makeResourceIconPart(
productName
)}.png`}
alt={productName}
height={20}
width={20}
class="rounded-sm shadow-lg"
/>
</Show>
</div>
<div>
<Show when={options.showRecipeNames}>{productName}</Show>{' '}
{/* todo: get the recipe so i have more info to display */}
{/* <Show when={options.showRecipeEfficiency}>
{recipe.Efficiency}
</Show>{' '}
<Show when={options.showRecipeNumber}>
{amount}
</Show> */}
</div>
</div>
</li>
))}
</ul>
</div>
);
};
9 changes: 9 additions & 0 deletions src/functions/IconNameUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function makeBuildingIconPart(buildingName: string) {
return buildingName
.replace(/^Flawless /, '')
.replace(/'/g, '')
.replace(/ /g, '_');
}
export function makeResourceIconPart(resourceName: string) {
return resourceName.replace(/ /g, '');
}

0 comments on commit c91a43d

Please sign in to comment.