|
@@ -33,6 +33,7 @@ class GameData(object):
|
|
|
self.usergame = usergame
|
|
|
self.warps = {}
|
|
|
self.ports = {}
|
|
|
+ self.config = {}
|
|
|
# 10 = 300 bytes
|
|
|
self.warp_groups = 10
|
|
|
# 3 = 560 bytes
|
|
@@ -68,6 +69,9 @@ class GameData(object):
|
|
|
|
|
|
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()):
|
|
@@ -100,17 +104,24 @@ class GameData(object):
|
|
|
if len(p["port"]) > 1:
|
|
|
writer.write(p)
|
|
|
|
|
|
- log.info("Saved {0} {1}/{2}".format(filename, len(self.ports), len(self.warps)))
|
|
|
+ log.info(
|
|
|
+ "Saved {0} {1}/{2}/{3}".format(
|
|
|
+ filename, len(self.ports), len(self.warps), len(self.config)
|
|
|
+ )
|
|
|
+ )
|
|
|
|
|
|
def load(self):
|
|
|
filename = self.storage_filename()
|
|
|
|
|
|
self.warps = {}
|
|
|
self.ports = {}
|
|
|
+ self.config = {}
|
|
|
if os.path.exists(filename):
|
|
|
# Load it
|
|
|
with jsonlines.open(filename) as reader:
|
|
|
for obj in reader:
|
|
|
+ if "config" in obj:
|
|
|
+ self.config.update(obj["config"])
|
|
|
if "warp" in obj:
|
|
|
for s, w in obj["warp"].items():
|
|
|
# log.debug(s, w)
|
|
@@ -122,7 +133,9 @@ class GameData(object):
|
|
|
# self.ports.update(obj["port"])
|
|
|
yield
|
|
|
log.info(
|
|
|
- "Loaded {0} {1}/{2}".format(filename, len(self.ports), len(self.warps))
|
|
|
+ "Loaded {0} {1}/{2}/{3}".format(
|
|
|
+ filename, len(self.ports), len(self.warps), len(self.config)
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
def untwisted_load(self):
|
|
@@ -134,10 +147,13 @@ class GameData(object):
|
|
|
|
|
|
self.warps = {}
|
|
|
self.ports = {}
|
|
|
+ self.config = {}
|
|
|
if os.path.exists(filename):
|
|
|
# Load it
|
|
|
with jsonlines.open(filename) as reader:
|
|
|
for obj in reader:
|
|
|
+ if "config" in obj:
|
|
|
+ self.config.update(obj["config"])
|
|
|
if "warp" in obj:
|
|
|
for s, w in obj["warp"].items():
|
|
|
# log.debug(s, w)
|
|
@@ -148,7 +164,9 @@ class GameData(object):
|
|
|
self.ports[int(s)] = p
|
|
|
# self.ports.update(obj["port"])
|
|
|
log.info(
|
|
|
- "Loaded {0} {1}/{2}".format(filename, len(self.ports), len(self.warps))
|
|
|
+ "Loaded {0} {1}/{2}/{3}".format(
|
|
|
+ filename, len(self.ports), len(self.warps), len(self.config)
|
|
|
+ )
|
|
|
)
|
|
|
|
|
|
def get_warps(self, sector: int):
|
|
@@ -167,6 +185,14 @@ class GameData(object):
|
|
|
if d not in self.warps[source]:
|
|
|
self.warps[source].add(d)
|
|
|
|
|
|
+ def get_config(self, key, default=None):
|
|
|
+ if key in self.config:
|
|
|
+ return self.config[key]
|
|
|
+ return default
|
|
|
+
|
|
|
+ def set_config(self, key, value):
|
|
|
+ self.config.update({key: value})
|
|
|
+
|
|
|
def set_port(self, sector: int, data: dict):
|
|
|
log.debug("Port {0} : {1}".format(sector, data))
|
|
|
if sector not in self.ports:
|