aboutsummaryrefslogtreecommitdiff
path: root/src/deconstruct.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/deconstruct.ts')
-rw-r--r--src/deconstruct.ts82
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]];
+ }
+}