• R/O
  • SSH

Commit

Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

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


Commit MetaInfo

Révision20ee3b22eaf7b142f8281d06f63f0f8aab107afb (tree)
l'heure2018-02-03 05:31:16
AuteurEric Hopper <hopper@omni...>
CommiterEric Hopper

Message de Log

Arrange for XML to be sorted in a predictable order.

This will make the results of version controlling the resulting XML file
much saner.

Change Summary

Modification

diff -r 462d2d0e4160 -r 20ee3b22eaf7 factorio_calc.py
--- a/factorio_calc.py Fri Feb 02 10:37:30 2018 -0800
+++ b/factorio_calc.py Fri Feb 02 12:31:16 2018 -0800
@@ -108,11 +108,32 @@
108108 elif not item_idmap[item][1]:
109109 raise RuntimeError(f"Circular reference detected '{item._name}'")
110110
111+ def sortedItems(self):
112+ itemset = set(self)
113+ sortedset = set()
114+ sortedlist = []
115+ curlst = []
116+ while len(itemset) > 0:
117+ for testitem in itemset:
118+ ingredients = set((ingtuple[1] \
119+ for ingtuple in testitem._ingredients))
120+ if len(ingredients - sortedset) <= 0:
121+ curlst.append(testitem)
122+ assert(len(curlst) > 0)
123+ curset = frozenset(curlst)
124+ itemset.difference_update(curset)
125+ curlst.sort(key=lambda x: self._itemId(x))
126+ sortedlist.extend(curlst)
127+ sortedset.update(curset)
128+ curset = None
129+ curlst = []
130+ return sortedlist
131+
111132 def asXML(self):
112133 yield '<?xml version="1.0" encoding="utf-8" standalone="no" ?>\n'
113- yield '<factorio_calc_item_db>\n'
134+ yield '<factorio_calc_item_db version="1.0">\n'
114135 item_idmap = {}
115- for item in self:
136+ for item in self.sortedItems():
116137 yield from self._itemAsXML(item, item_idmap)
117138 yield '</factorio_calc_item_db>\n'
118139