diff options
| author | twells46 <tom@wellsth.com> | 2026-01-25 11:14:07 -0600 |
|---|---|---|
| committer | twells46 <tom@wellsth.com> | 2026-01-25 11:14:07 -0600 |
| commit | 8e99f04d9cbc420176e6c28cbff30374dba7e03c (patch) | |
| tree | 3b01ea994472e376c0684abe8e7aef778df71e29 /src/deconstruct.ts | |
Diffstat (limited to 'src/deconstruct.ts')
| -rw-r--r-- | src/deconstruct.ts | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/deconstruct.ts b/src/deconstruct.ts new file mode 100644 index 0000000..3212645 --- /dev/null +++ b/src/deconstruct.ts @@ -0,0 +1,82 @@ +export type SFItem = { + name: string, + id: string, + type: 'base' | 'derived', + recipe: Recipe, +} + +export type BaseComponent = [string, number]; +export type BaseComponents = Array<BaseComponent>; + +export type Recipe = { + in: Array<[string, number]>, + out: number +}; + +const ITEMS: Array<SFItem> = [ + { + name: 'Iron Plate', + id: 'iron_plate', + type: 'base', + recipe: { + in: [['iron_ingot', 30]], + out: 20 + } + }, + { + name: 'Iron Rod', + id: 'iron_rod', + type: 'base', + recipe: { + in: [['iron_ingot', 15]], + out: 15 + } + }, + { + name: 'Screw', + id: 'screw', + type: 'derived', + recipe: { + in: [['iron_rod', 10]], + out: 40 + } + }, +]; + +export function get(id: string, items: Array<SFItem>): SFItem | undefined { + for (const item of items) { + if(item.id === id) { + return item; + } + } + return undefined; +} + +export function add(toAdd: BaseComponent, components: BaseComponents) { + for (const [i, val] of components.entries()) { + if (toAdd[0] === val[0]) { + components[i][1] += toAdd[1]; + return components; + } + } + return components.push(toAdd); +} + +function ratio(item: SFItem) { + const +} + +export function derive(item: SFItem): BaseComponents { + switch(item.type) { + case "derived": + let total = 0; + for (const input of item.recipe.in) { + const component = get(input[0], ITEMS); + if (component) { + total += input[1] * ratio(component); + } + } + case "base": + return [item.recipe.in[0]]; + } +} |