get tree json outpout working
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -10,7 +10,7 @@
|
||||
"request": "launch",
|
||||
"program": "${file}",
|
||||
"console": "integratedTerminal",
|
||||
"args": ["tree", "hydrogen"]
|
||||
"args": ["tree", "gear"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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": {}
|
||||
36
dsp_calc.py
36
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)
|
||||
|
||||
Reference in New Issue
Block a user