Commits

Anonymous committed dd65077

refactoring: split char.update into visible and model version.

Comments (0)

Files changed (3)

     """
     def __init__(self, logic, *args, **kwds): 
         """Initialize the scene with a core object for basic functions."""
+        # set the background color to white
+        gl.glClearColor(255, 255, 255, 0)
         
         #: The Game logic.
         self.logic = logic
-        
         #: the core provides data persistence between scenes.
         self.core = core
-
         #: The logic tells us what should be visible
         self.visible = self.logic.model.visible
-        
         #: Overlay sprites. They are above all other sprites (included for convenience, since most games need an overlay of sorts)
         self.overlay = []
-
         #: We still need the hexmap overlay here. The logic does not have to know how an overlay looks.
         self.hexmap_overlay = {}
-        
-        # set the background color to white
-        gl.glClearColor(255, 255, 255, 0)
-        
         # the background
-        self.terrain = self.logic.model.terrain
+        self.terrain = self.logic.model.terrain        
+
+        self.possible_commands = []
         
         # a hexgrid
         for i in range(-1, 30):
     def update(self, dt=0): 
         """Update the stats of all scene objects. 
         
-Don't blit them, though. That's done by the Game itself.
+Don't blit them, though. That's done by the Presentation.
         
 To show something, add it to the self.visible list. 
 To add a collider, add it to the self.colliding list. 
 To add an overlay sprite, add it to the self.overlay list. 
 """	
+        # Update the visible representation of the char.
         for char in self.logic.model.chars:
-            char.update()
+            char.update_visible()
+        
+        # Update the model.
+        # TODO: Just execute a step action, when the model tells us
+        # that we can do so.
+        # TODO: Add an inactive state: There’s nothing we can do
+        # (action already scheduled).
+        self.logic.update()
+
         # do the computer actions. As soon as it’s the players turn, computer_turn() changes the state.
         if self.logic.model.phase["player"] == "setup":
             schedule_once(self.logic.model.setup_step, 0.01)

hexbattle_logic.py

         self.phase["player"] = "wait"
         # TODO: return the result of the action instead. Or at least a list of changed characters. Best a list of all characters who changed state and how they changed state.
         return Result("step", commands=[Command(self.switch_to_cpu_turn, "continue")])
-        
 
 class Logic:
     def __init__(self):
         self.model = Model()
         #: The scene to switch to at the next possible step.
         self.switch = False 
+
+    def update(self):
+        # Update the visible representation of the char.
+        for char in self.model.chars:
+            char.update_model()
+

hexbattle_units.py

 class Character(Hexfield, Char):
     """A character on the Hexfield. It knows the level as hexmap.
 
-    TODO: multi-step actions: action = (identifier, time (from time()))
+    TODO: 1. Split methods which mix model and GUI.
+    TODO: 2. Add GUI methods from the GUI: The selected GUI gives the chars the capabilities they need. Drawback: Can’t change the UI without reloading.
 
     >>> # Use the Character without model and with fake hexmap
     >>> # → nonfunctional ⇒ only for testing. 
             if target is not None:
                 self._action_attack(target)
                 
-    def update(self):
-        """Make sure we’re alive."""
+    def update_model(self):
+        """Update the model representation."""
         if not self.alive:
             self.hide()
             self.remove_from_hexmap()
+
+    def update_visible(self):
+        """Update the visible elements, but don’t change the model
+        representation (hexmay stuff)."""
         for action in self.timed_actions:
             if action[0] == "tumble":
                 self._action_tumble(action)
         super(Character, self).draw()
         for sprite in self.status_sprites:
             sprite.draw()
-                
-
+        
 
 if __name__ == "__main__":
     # there’s only one reason for calling this file: doctests
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.