From 8e99f04d9cbc420176e6c28cbff30374dba7e03c Mon Sep 17 00:00:00 2001 From: twells46 Date: Sun, 25 Jan 2026 11:14:07 -0600 Subject: Initial commit --- src/deconstruct.ts | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/deconstruct.ts (limited to 'src/deconstruct.ts') 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; + +export type Recipe = { + in: Array<[string, number]>, + out: number +}; + +const ITEMS: Array = [ + { + 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 | 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]]; + } +} -- cgit v1.2.3