Just a simple, and painful to use calculator for the game Factorio written in Python
Revision | 67b3fb9439f19b873bb5c0a2224d8911252948f6 (tree) |
---|---|
Time | 2017-08-07 23:53:24 |
Author | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Allow ingredient specification by name in constructor.
@@ -13,7 +13,17 @@ | ||
13 | 13 | self._produced = produced |
14 | 14 | self._name = name |
15 | 15 | self._time = time |
16 | - self._ingredients = ingredients | |
16 | + def lookup_ingredients(ingredients): | |
17 | + for ct, item in ingredients: | |
18 | + print(f"Lookup up ({ct}, {item!s})", file=sys.stderr) | |
19 | + if not isinstance(item, ProductionItem): | |
20 | + item = item_db[item] | |
21 | + print(f"Wasn't already an item, found {item!s}", | |
22 | + file=sys.stderr) | |
23 | + yield (ct, item) | |
24 | + oldlen = len(ingredients) | |
25 | + self._ingredients = tuple(item for item in lookup_ingredients(ingredients)) | |
26 | + assert(len(self._ingredients) == oldlen) | |
17 | 27 | |
18 | 28 | def __hash__(self): |
19 | 29 | return hash(self._name) |