• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javaandroidc++linuxc#objective-ccocoa誰得qtrubypythonwindowsphpgamebathyscapheguic翻訳omegattwitterframeworkbtronvb.net計画中(planning stage)testdomarduinodirectxpreviewerゲームエンジン

Just a simple, and painful to use calculator for the game Factorio written in Python


Commit MetaInfo

Revision0114c5c1cd039864e071fd5ca628335d8a13bded (tree)
Zeit2019-03-30 11:06:38
AutorEric Hopper <hopper@omni...>
CommiterEric Hopper

Log Message

Update to preferentially read items.xml as the item database.

Ändern Zusammenfassung

Diff

diff -r 3d95e6a47f05 -r 0114c5c1cd03 factorio_calc.py
--- a/factorio_calc.py Tue Feb 06 08:25:29 2018 -0800
+++ b/factorio_calc.py Fri Mar 29 19:06:38 2019 -0700
@@ -199,18 +199,28 @@
199199 ProductionItem(name, time, tuple(ingredients), produced))
200200
201201 _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')
203204
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:
206211 item_db = pickle.load(_item_f)
212+ db_fname = pickle_fname
207213 else:
208- item_db = set()
214+ item_db = ItemSet()
209215
210216 def save_items():
211217 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)
214224 os.unlink(db_fname)
215225 os.link(tmp_new, db_fname)
216226 os.unlink(tmp_new)