diff pytouhou/vm/msgrunner.py @ 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 6be9c99a3a24
children e35a083d4208
line wrap: on
line diff
--- 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)