From 881fd2cd2264258c4ea3c8ce0c0cda05789ab11c Mon Sep 17 00:00:00 2001 From: Schemen Date: Wed, 27 Jan 2021 15:53:25 +0100 Subject: [PATCH] get tree json outpout working --- .vscode/launch.json | 2 +- data copy.json => data.json | 8 ++++++++ dsp_calc.py | 36 +++++++++++------------------------- 3 files changed, 20 insertions(+), 26 deletions(-) rename data copy.json => data.json (99%) diff --git a/.vscode/launch.json b/.vscode/launch.json index 87ba064..91e9ac5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "program": "${file}", "console": "integratedTerminal", - "args": ["tree", "hydrogen"] + "args": ["tree", "gear"] } ] } \ No newline at end of file diff --git a/data copy.json b/data.json similarity index 99% rename from data copy.json rename to data.json index f0fe7f4..fa788cf 100644 --- a/data copy.json +++ b/data.json @@ -12,6 +12,14 @@ "produced_with": "water_pump", "requires": {} }, + "plant_fuel":{ + "produced_with": "manual_labor", + "requires": {} + }, + "log":{ + "produced_with": "manual_labor", + "requires": {} + }, "fire_ice":{ "produced_with": "orbital_harvester", "requires": {} diff --git a/dsp_calc.py b/dsp_calc.py index 3841021..95ed36b 100755 --- a/dsp_calc.py +++ b/dsp_calc.py @@ -4,7 +4,7 @@ import json import pprint -with open('data copy.json', 'r') as DATA_JSON: +with open('data.json', 'r') as DATA_JSON: data=DATA_JSON.read() try: @@ -44,38 +44,32 @@ def tree(item): + def get_required(item_name): - print("Item_name: "+ item_name) + """Function that returns the entire requirements of an item""" dsp_data_combined = get_combined_data(dsp_data) required_items = {} item = dsp_data_combined[item_name] - print("item: " + str(item)) - if not item.get("requires") and not item.get("recipes"): - print("this is and enditem 1") + if "requires" not in item and "recipes" not in item: return {} if item.get("recipes"): - print(item["recipes"]) + required_items["recipes"] = {} for i in item["recipes"]: - if not item.get("requires") and not item.get("recipes"): - print("this is and enditem 2") - return {} - for req_name in i["requires"].items(): - sub_req_name = req_name[0] - sub_req = get_required(sub_req_name) - required_items[sub_req_name] = {**dsp_data_combined[sub_req_name], "recipes": [ sub_req ] } + for req_name, amount in i["requires"].items(): + sub_req = get_required(req_name) + required_items["recipes"][req_name] = {**dsp_data_combined[req_name], "amount": amount, "requires": sub_req } + + return required_items for req_name, amount in item["requires"].items(): sub_req = get_required(req_name) required_items[req_name] = {**dsp_data_combined[req_name], "amount": amount, "requires": sub_req} + return required_items -def get_item_requirements(item): - item["children"] = {} - return item.get("requires") - def get_combined_data(data): combined = data["components"] @@ -83,14 +77,6 @@ def get_combined_data(data): return combined -def get_item_type(item): - if dsp_data["components"].get(item): - return "components" - elif dsp_data["buildings"].get(item): - return "buildings" - else: - click.echo("Item %s not found!" % item) - def get_item(item): if dsp_data["components"].get(item): return dsp_data["components"].get(item)