changeset 549:56bca8ce4b68

Add a very simple sample interface.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 08 Nov 2013 18:48:30 +0100
parents 1e9ea6519f3c
children f1be00de4b3f
files pytouhou/interfaces/sample.py pytouhou/ui/gamerunner.pyx pytouhou/ui/sdl/gamerenderer.py scripts/pytouhou
diffstat 4 files changed, 60 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/pytouhou/interfaces/sample.py
@@ -0,0 +1,48 @@
+# -*- encoding: utf-8 -*-
+##
+## Copyright (C) 2014 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published
+## by the Free Software Foundation; version 3 only.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+
+class SampleInterface(object):
+    def __init__(self, resource_loader, player_state):
+        self.game = None
+        self.player_state = player_state
+        self.ascii_anm = resource_loader.get_single_anm('ascii.anm') #XXX
+
+        self.width = 384
+        self.height = 448
+        self.game_pos = (0, 32)
+
+        self.items = []
+        self.level_start = []
+        self.labels = {}
+        self.boss_items = []
+
+
+    def start_stage(self, game, stage):
+        self.game = game
+
+
+    def set_song_name(self, name):
+        pass
+
+
+    def set_boss_life(self):
+        pass
+
+
+    def set_spell_life(self):
+        pass
+
+
+    def update(self):
+        pass
--- a/pytouhou/ui/gamerunner.pyx
+++ b/pytouhou/ui/gamerunner.pyx
@@ -165,8 +165,11 @@ cdef class GameRunner(Runner):
         else:
             self.game.run_iter([keystate])
 
-        if self.window is not None:
-            self.game.interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
+        labels = self.game.interface.labels
+        if self.window is not None and 'framerate' in labels:
+            labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
+
         if not self.skip and self.renderer is not None:
             self.renderer.render(self.game)
+
         return True
--- a/pytouhou/ui/sdl/gamerenderer.py
+++ b/pytouhou/ui/sdl/gamerenderer.py
@@ -75,13 +75,15 @@ class GameRenderer(object):
 
 
     def render_interface(self, interface, boss):
-        interface.labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
+        interface_labels = interface.labels
+        if 'framerate' in interface_labels:
+            interface_labels['framerate'].set_text('%.2ffps' % self.window.get_fps())
 
         self.window.win.render_set_viewport(Rect(0, 0, interface.width, interface.height))
         self.window.win.render_set_clip_rect(Rect(0, 0, interface.width, interface.height))
 
         items = [item for item in interface.items if item.anmrunner and item.anmrunner.running]
-        labels = interface.labels.values()
+        labels = interface_labels.values()
 
         if items:
             # Redraw all the interface
--- a/scripts/pytouhou
+++ b/scripts/pytouhou
@@ -38,7 +38,7 @@ game_group.add_argument('-r', '--rank', 
 game_group.add_argument('-c', '--character', metavar='CHARACTER', type=int, default=0, help='Select the character to use, from 0 (ReimuA, default) to 3 (MarisaB).')
 game_group.add_argument('-b', '--boss-rush', action='store_true', help='Fight only bosses.')
 game_group.add_argument('--game', metavar='GAME', choices=['EoSD'], default='EoSD', help='Select the game engine to use.')
-game_group.add_argument('--interface', metavar='INTERFACE', choices=['EoSD'], default='EoSD', help='Select the interface to use.')
+game_group.add_argument('--interface', metavar='INTERFACE', choices=['EoSD', 'Sample'], default='EoSD', help='Select the interface to use.')
 game_group.add_argument('--hints', metavar='HINTS', default=None, help='Hints file, to display text while playing.')
 
 replay_group = parser.add_argument_group('Replay options')
@@ -72,6 +72,8 @@ if args.game == 'EoSD':
 
 if args.interface == 'EoSD':
     from pytouhou.interfaces.eosd import EoSDInterface as Interface
+elif args.interface == 'Sample':
+    from pytouhou.interfaces.sample import SampleInterface as Interface
 
 
 from pytouhou.lib.sdl import SDL, show_simple_message_box