|
@@ -54,6 +54,12 @@ class GameData(object):
|
|
|
def reset_warps(self):
|
|
|
self.warps = {}
|
|
|
|
|
|
+ def special_ports(self):
|
|
|
+ """ Save the special class ports 0, 9 """
|
|
|
+ return {
|
|
|
+ p: self.ports[p] for p in self.ports if self.ports[p]["class"] in (0, 9)
|
|
|
+ }
|
|
|
+
|
|
|
def display(self):
|
|
|
pprint(self.warps)
|
|
|
pprint(self.ports)
|
|
@@ -88,7 +94,7 @@ class GameData(object):
|
|
|
# writer.write(w)
|
|
|
# yield
|
|
|
|
|
|
- if len(w["warp"]) > 1:
|
|
|
+ if len(w["warp"]) > 0:
|
|
|
writer.write(w)
|
|
|
|
|
|
# for sector, port in self.ports.items():
|
|
@@ -101,7 +107,57 @@ class GameData(object):
|
|
|
writer.write(p)
|
|
|
p = {"port": {}}
|
|
|
yield
|
|
|
- if len(p["port"]) > 1:
|
|
|
+ if len(p["port"]) > 0:
|
|
|
+ writer.write(p)
|
|
|
+
|
|
|
+ log.info(
|
|
|
+ "Saved {0} {1}/{2}/{3}".format(
|
|
|
+ filename, len(self.ports), len(self.warps), len(self.config)
|
|
|
+ )
|
|
|
+ )
|
|
|
+
|
|
|
+ def untwisted_save(self, *_):
|
|
|
+ """ save gamedata as jsonlines.
|
|
|
+
|
|
|
+ Enable sort_keys=True to provide stable json data output.
|
|
|
+ We also sorted(.keys()) to keep records in order.
|
|
|
+ Note: There's a "bug" when serializing to json, keys must be strings!
|
|
|
+ """
|
|
|
+ filename = self.storage_filename()
|
|
|
+
|
|
|
+ with jsonlines.open(filename, mode="w", sort_keys=True) as writer:
|
|
|
+ # for warp, sectors in self.warps.items():
|
|
|
+ c = {"config": self.config}
|
|
|
+ writer.write(c)
|
|
|
+
|
|
|
+ w = {"warp": {}}
|
|
|
+
|
|
|
+ for warp in sorted(self.warps.keys()):
|
|
|
+ sectors = self.warps[warp]
|
|
|
+ # log.debug("save:", warp, sectors)
|
|
|
+ sects = sorted(list(sectors)) # make a list
|
|
|
+ w["warp"][warp] = sects
|
|
|
+ if len(w["warp"]) >= self.warp_groups:
|
|
|
+ writer.write(w)
|
|
|
+ w = {"warp": {}}
|
|
|
+
|
|
|
+ # log.debug(w)
|
|
|
+ # writer.write(w)
|
|
|
+ # yield
|
|
|
+
|
|
|
+ if len(w["warp"]) > 0:
|
|
|
+ writer.write(w)
|
|
|
+
|
|
|
+ # for sector, port in self.ports.items():
|
|
|
+ p = {"port": {}}
|
|
|
+
|
|
|
+ for sector in sorted(self.ports.keys()):
|
|
|
+ port = self.ports[sector]
|
|
|
+ p["port"][sector] = port
|
|
|
+ if len(p["port"]) >= self.port_groups:
|
|
|
+ writer.write(p)
|
|
|
+ p = {"port": {}}
|
|
|
+ if len(p["port"]) > 0:
|
|
|
writer.write(p)
|
|
|
|
|
|
log.info(
|