Commits

larry committed 91032ba

Changed savegame format to a single dict with all fields inside.

  • Participants
  • Parent commits d2f9ca2

Comments (0)

Files changed (1)

 		print()
 		print("Saving game.")
 		pickler = pickle.Pickler(f)
-		dump = pickler.dump
-
-		dump("savegame_revision")
-		dump(savegame_revision)
-
-		dump("random.getstate()")
-		dump(random.getstate())
-
-		dump("series")
-		dump(series)
-
-		dump("game")
-		dump(game)
-
-		dump("hand")
-		dump(hand)
-
-		dump("[end]")
+
+		pickler.dump({
+			"savegame_revision": savegame_revision,
+			"random.state": random.getstate(),
+			"series": series,
+			"game": game,
+			"hand": hand,
+			})
 
 def load():
 	try:
 			print()
 			print("Loading game.")
 			unpickler = pickle.Unpickler(f)
-			load = unpickler.load
+			d = unpickler.load()
 
 			global series
 			global game
 			global hand
 
-			found_savegame_revision = False
-			while True:
-				s = load()
-				assert isinstance(s, str)
-				if s == "[end]":
-					break
-
-				value = load()
-
-				if s == "savegame_revision":
-					assert value == savegame_revision
-				elif s == "random.getstate()":
-					random.setstate(value)
-				elif s == "series":
-					series = value
-				elif s == "game":
-					game = value
-				elif s == "hand":
-					hand = value
-				else:
-					print("warning: unrecognized savegame attribute", repr(s))
+			assert d["savegame_revision"] == savegame_revision
+			random.setstate(d["random.state"])
+			series = d["series"]
+			game = d["game"]
+			hand = d["hand"]
 	except EOFError:
 		pass