Explorar el Código

Save portdata into game object.

Reset when we leave a game.
FUTURE:  Save/Load port data into json file user+game.json ?
Steve Thielemann hace 5 años
padre
commit
4ca89a3f70
Se han modificado 2 ficheros con 13 adiciones y 13 borrados
  1. 9 1
      flexible.py
  2. 4 12
      tcp-proxy.py

+ 9 - 1
flexible.py

@@ -213,7 +213,7 @@ class CIMPortReport(object):
                 self.game.to_player = self.to_player
                 self.observer.load(self.save)
                 self.save = None
-
+                self.game.portdata = self.portdata
                 self.queue_game.put("\b \b\r\n")
 
                 if not self.defer is None:
@@ -312,6 +312,11 @@ class ProxyMenu(object):
         self.queue_game = game.queue_game
         self.observer = game.observer
 
+        if hasattr(self.game, "portdata"):
+            self.portdata = self.game.portdata
+        else:
+            self.portdata = {}
+
         # Yes, at this point we would activate
         self.prompt = game.buffer
         self.save = self.observer.save()
@@ -384,6 +389,9 @@ class ProxyMenu(object):
             d.addCallback(self.port_report)
             d.addErrback(self.welcome_back)
             return
+        elif key == "S":
+            self.queue_game.put(self.c + key + self.r + self.nl)
+
         elif key == "D":
             self.queue_game.put(self.c + key + self.r + self.nl)
             self.queue_game.put(pformat(self.portdata).replace("\n", "\n\r") + self.nl)

+ 4 - 12
tcp-proxy.py

@@ -73,18 +73,6 @@ def cleanANSI(line):
     # return re.sub(r'\x1b\[([0-9,A-Z]{1,2}(;[0-9]{1,2})?(;[0-9]{3})?)?[m|K]?', '', line)
 
 
-PORT_CLASSES = {
-    1: "BBS",
-    2: "BSB",
-    3: "SBB",
-    4: "SSB",
-    5: "SBS",
-    6: "BSS",
-    7: "SSS",
-    8: "BBB",
-}
-CLASSES_PORT = {v: k for k, v in PORT_CLASSES.items()}
-
 from observer import Observer
 
 from flexible import PlayerInput, ProxyMenu
@@ -109,6 +97,10 @@ class Game(protocol.Protocol):
     def show_game(self, game):
         self.usergame = game
         log.msg("## User-Game:", game)
+        if game[1] is None:
+            if hasattr(self, "portdata"):
+                log.msg("Clearing out old portdata.")
+                self.portdata = {}
 
     def setPlayerReceived(self):
         """ Get deferred from client queue, callback clientDataReceived. """