Just a simple, and painful to use calculator for the game Factorio written in Python
Révision | 0114c5c1cd039864e071fd5ca628335d8a13bded (tree) |
---|---|
l'heure | 2019-03-30 11:06:38 |
Auteur | Eric Hopper <hopper@omni...> |
Commiter | Eric Hopper |
Update to preferentially read items.xml as the item database.
@@ -199,18 +199,28 @@ | ||
199 | 199 | ProductionItem(name, time, tuple(ingredients), produced)) |
200 | 200 | |
201 | 201 | _mod_dir = _osp.dirname(__file__) |
202 | -db_fname = _osp.join(_mod_dir, 'item-db.pickle') | |
202 | +xml_fname = _osp.join(_mod_dir, 'items.xml') | |
203 | +pickle_fname = _osp.join(_mod_dir, 'item-db-0.16.pickle') | |
203 | 204 | |
204 | -if _osp.exists(db_fname): | |
205 | - with open(db_fname, 'rb') as _item_f: | |
205 | +if _osp.exists(xml_fname): | |
206 | + with open(xml_fname, 'r') as _item_f: | |
207 | + item_db = ItemSet.createFromXML(_item_f) | |
208 | + db_fname = xml_fname | |
209 | +elif _osp.exists(pickle_fname): | |
210 | + with open(pickle_fname, 'rb') as _item_f: | |
206 | 211 | item_db = pickle.load(_item_f) |
212 | + db_fname = pickle_fname | |
207 | 213 | else: |
208 | - item_db = set() | |
214 | + item_db = ItemSet() | |
209 | 215 | |
210 | 216 | def save_items(): |
211 | 217 | tmp_new = db_fname + '.new' |
212 | - with open(tmp_new, 'wb') as item_f: | |
213 | - pickle.dump(item_db, item_f, -1) | |
218 | + if db_fname.endswith('.xml'): | |
219 | + with open(tmp_new, 'w') as item_f: | |
220 | + item_f.writelines(item_db.asXML()) | |
221 | + else: | |
222 | + with open(tmp_new, 'wb') as item_f: | |
223 | + pickle.dump(item_db, item_f, -1) | |
214 | 224 | os.unlink(db_fname) |
215 | 225 | os.link(tmp_new, db_fname) |
216 | 226 | os.unlink(tmp_new) |