changeset 516:577c3a88fb67

Merge the lists Game.texts and Game.native_texts into the Game.texts dict.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 11 May 2014 20:25:07 +0200
parents b3193b43a86c
children dec43940f092
files pytouhou/game/game.pxd pytouhou/game/game.pyx pytouhou/games/eosd.py pytouhou/ui/opengl/gamerenderer.pxd pytouhou/ui/opengl/gamerenderer.pyx pytouhou/ui/sdl/gamerenderer.py pytouhou/vm/msgrunner.py
diffstat 7 files changed, 38 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/game/game.pxd
+++ b/pytouhou/game/game.pxd
@@ -5,8 +5,9 @@ from pytouhou.utils.random cimport Rando
 
 cdef class Game:
     cdef public long width, height, nb_bullets_max, stage, rank, difficulty, difficulty_min, difficulty_max, frame
-    cdef public list bullet_types, laser_types, item_types, players, enemies, effects, bullets, lasers, cancelled_bullets, players_bullets, players_lasers, items, labels, faces, texts, hints, bonus_list
+    cdef public list bullet_types, laser_types, item_types, players, enemies, effects, bullets, lasers, cancelled_bullets, players_bullets, players_lasers, items, labels, faces, hints, bonus_list
     cdef public object interface, boss, msg_runner, sfx_player
+    cdef public dict texts
     cdef public Random prng
     cdef public double continues
     cdef public Effect spellcard_effect
--- a/pytouhou/game/game.pyx
+++ b/pytouhou/game/game.pyx
@@ -46,7 +46,7 @@ cdef class Game:
         self.items = []
         self.labels = []
         self.faces = [None, None]
-        self.texts = [None, None, None, None, None, None]
+        self.texts = {}
         self.interface = interface
         self.hints = hints
 
@@ -110,23 +110,24 @@ cdef class Game:
         face.sprite.anm, face.sprite.texcoords = self.msg_anm[1][self.spellcard[2]]
         self.effects.append(face)
 
-        self.texts[5] = self.new_native_text((384-24, 24), self.spellcard[1], align='right')
+        self.texts['enemy_spellcard'] = self.new_native_text((384-24, 24), self.spellcard[1], align='right')
 
 
     cpdef disable_spellcard_effect(self):
         self.spellcard_effect = None
-        self.texts[5] = None
+        if 'enemy_spellcard' in self.texts:
+            del self.texts['enemy_spellcard']
 
 
     cdef void set_player_bomb(self):
         face = Effect((-32, -16), 1, self.msg_anm[0][0][0])
         face.sprite.allow_dest_offset = True
         self.effects.append(face)
-        self.texts[4] = self.new_native_text((24, 24), u'Player Spellcard')
+        self.texts['player_spellcard'] = self.new_native_text((24, 24), u'Player Spellcard')
 
 
     cdef void unset_player_bomb(self):
-        self.texts[4] = None
+        del self.texts['player_spellcard']
 
 
     cpdef drop_bonus(self, double x, double y, long _type, end_pos=None, player=None):
@@ -307,10 +308,7 @@ cdef class Game:
             self.update_hints() # Not from this game, so unknown.
         for label in self.labels: #TODO: what priority is it?
             label.update()
-        for text in self.texts: #TODO: what priority is it?
-            if text is not None:
-                text.update()
-        for text in self.native_texts: #TODO: what priority is it?
+        for text in self.texts.itervalues(): #TODO: what priority is it?
             if text is not None:
                 text.update()
         self.update_faces() # Pri XXX
@@ -575,11 +573,10 @@ cdef class Game:
 
         self.effects = filter_removed(self.effects)
         self.labels = filter_removed(self.labels)
-        #self.native_texts = filter_removed(self.native_texts)
 
-        for i, text in enumerate(self.texts):
-            if text is not None and text.removed:
-                self.texts[i] = None
+        for key, text in self.texts.items():
+            if text.removed:
+                del self.texts[key]
 
         # Disable boss mode if it is dead/it has timeout
         if self.boss and self.boss._enemy.removed:
--- a/pytouhou/games/eosd.py
+++ b/pytouhou/games/eosd.py
@@ -136,7 +136,6 @@ class EoSDGame(Game):
         self.background = Background(self.std, background_anm)
 
         common.interface.start_stage(self, stage)
-        self.native_texts = [common.interface.stage_name, common.interface.song_name]
 
         Game.__init__(self, common.players, stage, rank, difficulty,
                       common.bullet_types, common.laser_types,
@@ -144,6 +143,9 @@ class EoSDGame(Game):
                       common.height, prng, common.interface, hints,
                       friendly_fire)
 
+        self.texts['stage_name'] = common.interface.stage_name
+        self.texts['song_name'] = common.interface.song_name
+
 
 
 class EoSDInterface(object):
--- a/pytouhou/ui/opengl/gamerenderer.pxd
+++ b/pytouhou/ui/opengl/gamerenderer.pxd
@@ -11,5 +11,5 @@ cdef class GameRenderer(Renderer):
     cdef BackgroundRenderer background_renderer
 
     cdef void render_game(self, Game game) except *
-    cdef void render_text(self, texts) except *
+    cdef void render_text(self, dict texts) except *
     cdef void render_interface(self, interface, game_boss) except *
--- a/pytouhou/ui/opengl/gamerenderer.pyx
+++ b/pytouhou/ui/opengl/gamerenderer.pyx
@@ -78,7 +78,7 @@ cdef class GameRenderer(Renderer):
             self.framebuffer.bind()
 
         self.render_game(game)
-        self.render_text(game.texts + game.native_texts)
+        self.render_text(game.texts)
         self.render_interface(game.interface, game.boss)
 
         if not self.use_fixed_pipeline:
@@ -189,13 +189,13 @@ cdef class GameRenderer(Renderer):
         glDisable(GL_SCISSOR_TEST)
 
 
-    cdef void render_text(self, texts):
+    cdef void render_text(self, dict texts):
         cdef NativeText label
 
         if self.font_manager is None:
             return
 
-        labels = [label for label in texts if label is not None]
+        labels = [label for label in texts.itervalues() if label is not None]
         self.font_manager.load(labels)
 
         black = Color(0, 0, 0, 255)
--- a/pytouhou/ui/sdl/gamerenderer.py
+++ b/pytouhou/ui/sdl/gamerenderer.py
@@ -42,7 +42,7 @@ class GameRenderer(object):
 
     def render(self, game):
         self.render_game(game)
-        self.render_text(game.texts + game.native_texts)
+        self.render_text(game.texts)
         self.render_interface(game.interface, game.boss)
 
 
--- a/pytouhou/vm/msgrunner.py
+++ b/pytouhou/vm/msgrunner.py
@@ -85,7 +85,15 @@ class MSGRunner(object):
         self._game.msg_runner = None
         self._game.msg_wait = False
         self.ended = True
-        self._game.texts = [None] * 4 + self._game.texts[4:]
+        texts = self._game.texts
+        if 'boss_name' in texts:
+            del texts['boss_name']
+        if 'boss_title' in texts:
+            del texts['boss_title']
+        if 'dialog_0' in texts:
+            del texts['dialog_0']
+        if 'dialog_1' in texts:
+            del texts['dialog_1']
 
 
     @instruction(0)
@@ -109,11 +117,14 @@ class MSGRunner(object):
 
     @instruction(3)
     def display_text(self, side, index, text):
+        texts = self._game.texts
         if index == 0:
-            self._game.texts[0] = None
-            self._game.texts[1] = None
-        self._game.texts[index] = self._game.new_native_text((64, 372 + index * 24), text)
-        self._game.texts[index].set_timeout(0, effect='fadeout', duration=15)
+            if 'dialog_0' in texts:
+                del texts['dialog_0']
+            if 'dialog_1' in texts:
+                del texts['dialog_1']
+        texts['dialog_%d' % index] = self._game.new_native_text((64, 372 + index * 24), text)
+        texts['dialog_%d' % index].set_timeout(0, effect='fadeout', duration=15)
 
 
     @instruction(4)
@@ -142,7 +153,8 @@ class MSGRunner(object):
     @instruction(8)
     def display_description(self, side, index, text):
         assert side == 1  # It shouldn’t crash when it’s something else.
-        self._game.texts[2 + index] = self._game.new_native_text((336, 320 + index * 18), text, align='right')
+        key = 'boss_name' if index == 0 else 'boss_title'
+        self._game.texts[key] = self._game.new_native_text((336, 320 + index * 18), text, align='right')
 
 
     @instruction(10)