diff --git a/starter.json b/starter.json new file mode 100644 index 0000000..5cb8050 --- /dev/null +++ b/starter.json @@ -0,0 +1,256 @@ +[ + { + "name": "small azurite sliver", + "type": "raw_material" + }, + { + "name": "medium azurite fragment", + "type": "complex_item", + "sub_components": + { + "small azurite sliver": 3 + }, + "naive_complexity": true + }, + { + "name": "large azurite shard", + "type": "complex_item", + "sub_components": + { + "medium azurite fragment": 3 + }, + "naive_complexity": true + }, + { + "name": "small amethyst sliver", + "type": "raw_material" + }, + { + "name": "medium amethyst fragment", + "type": "complex_item", + "sub_components": + { + "small amethyst sliver": 3 + }, + "naive_complexity": true + }, + { + "name": "large amethyst shard", + "type": "complex_item", + "sub_components": + { + "medium amethyst fragment": 3 + }, + "naive_complexity": true + }, + { + "name": "small emerald sliver", + "type": "raw_material" + }, + { + "name": "medium emerald fragment", + "type": "complex_item", + "sub_components": + { + "small emerald sliver": 3 + }, + "naive_complexity": true + }, + { + "name": "large emerald shard", + "type": "complex_item", + "sub_components": + { + "medium emerald fragment": 3 + }, + "naive_complexity": true + }, + { + "name": "small ruby sliver", + "type": "raw_material" + }, + { + "name": "medium ruby fragment", + "type": "complex_item", + "sub_components": + { + "small ruby sliver": 3 + }, + "naive_complexity": true + }, + { + "name": "large ruby shard", + "type": "complex_item", + "sub_components": + { + "medium ruby fragment": 3 + }, + "naive_complexity": true + }, + { + "name": "diluted vespene gas", + "type": "raw_material" + }, + { + "name": "refined vespene gas", + "type": "complex_item", + "sub_components": + { + "diluted vespene gas": 3 + }, + "naive_complexity": true + }, + { + "name": "concentrated vespene gas", + "type": "complex_item", + "sub_components": + { + "refined vespene gas": 3 + }, + "naive_complexity": true + }, + { + "name": "diluted amaranthine gas", + "type": "raw_material" + }, + { + "name": "refined amaranthine gas", + "type": "complex_item", + "sub_components": + { + "diluted amaranthine gas": 3 + }, + "naive_complexity": true + }, + { + "name": "concentrated amaranthine gas", + "type": "complex_item", + "sub_components": + { + "refined amaranthine gas": 3 + }, + "naive_complexity": true + }, + { + "name": "small lava globule", + "type": "raw_material" + }, + { + "name": "medium lava blob", + "type": "complex_item", + "sub_components": + { + "small lava globule": 2 + }, + "naive_complexity": true + }, + { + "name": "big lava glob", + "type": "complex_item", + "sub_components": + { + "medium lava blob": 2 + }, + "naive_complexity": true + }, + { + "name": "tiny iron nugget", + "type": "raw_material" + }, + { + "name": "ordinary iron lump", + "type": "complex_item", + "sub_components": + { + "tiny iron nugget": 3 + }, + "naive_complexity": true + }, + { + "name": "sizeable iron chunk", + "type": "complex_item", + "sub_components": + { + "ordinary iron lump": 3 + }, + "naive_complexity": true + }, + { + "name": "tiny silver nugget", + "type": "raw_material" + }, + { + "name": "ordinary silver lump", + "type": "complex_item", + "sub_components": + { + "tiny silver nugget": 3 + }, + "naive_complexity": true + }, + { + "name": "sizeable silver chunk", + "type": "complex_item", + "sub_components": + { + "ordinary silver lump": 3 + }, + "naive_complexity": true + }, + { + "name": "tiny gold nugget", + "type": "raw_material" + }, + { + "name": "ordinary gold lump", + "type": "complex_item", + "sub_components": + { + "tiny gold nugget": 3 + }, + "naive_complexity": true + }, + { + "name": "sizeable gold chunk", + "type": "complex_item", + "sub_components": + { + "ordinary gold lump": 3 + }, + "naive_complexity": true + }, + { + "name": "tiny titanium nugget", + "type": "raw_material" + }, + { + "name": "ordinary titanium lump", + "type": "complex_item", + "sub_components": + { + "tiny titanium nugget": 3 + }, + "naive_complexity": true + }, + { + "name": "sizeable titanium chunk", + "type": "complex_item", + "sub_components": + { + "ordinary titanium lump": 3 + }, + "naive_complexity": true + }, + { + "name": "obsidian", + "type": "raw_material" + }, + { + "name": "abberrant matter", + "type": "raw_material" + }, + { + "name": "strange gloop", + "type": "raw_material" + } +] diff --git a/total_cost.py b/total_cost.py index c6beb3a..df7ecbf 100644 --- a/total_cost.py +++ b/total_cost.py @@ -45,30 +45,33 @@ def from_json(): ################################################################################################################################ class user_input: def __init__(self,comp_name): - valid = ('raw','compound') - error = True - while error: - try: - type = int(input("~{}~\ntype (0. {} | 1. {}): ".format(comp_name,*valid))) - error = False - except ValueError: - pass - self.type = valid[type] - if self.type == 'compound': - self.subs = {} - i = 1 - while True: - inp = input('sub #{} ({{comp_name}} * {{count}}): '.format(i)) - if inp == 'end': - break - sr = re.split(r' *\* *',inp) - name = sr[0] - if len(sr) == 1: - count = 1 - else: - count = int(sr[1]) - self.subs[name] = count - i += 1 + + print("~{}~".format(comp_name),) + i = 1 + while True: + inp = input('sub #{} ({{comp_name}} * {{count}}): '.format(i)) + # null data means quit + if inp == '': + break + # initialize on the first iteration + if i == 1: + self.subs = {} + # parse infix expression + sr = re.split(r' *\* *',inp) + # default count is 1 + name = sr[0] + if len(sr) == 1: + count = 1 + else: + count = int(sr[1]) + self.subs[name] = count + + i += 1 + # `i` was never incremented, so the loop terminated early implying no sub components aka raw + if i == 1: + self.type = 'raw' + else: + self.type = 'compound' def recursive_fill_in(comp_name): global ITEMS