comparison pyntnclick/state.py @ 567:b84534a1bd2e pyntnclick

Lazily load Result sounds.
author Simon Cross <hodgestar+bzr@gmail.com>
date Sat, 11 Feb 2012 15:27:52 +0200
parents 28f03563f4db
children 1b1ab71535bd
comparison
equal deleted inserted replaced
566:ea9dd2b9186a 567:b84534a1bd2e
7 from widgets import BoomLabel 7 from widgets import BoomLabel
8 from pygame.rect import Rect 8 from pygame.rect import Rect
9 from pygame.color import Color 9 from pygame.color import Color
10 10
11 from pyntnclick import constants 11 from pyntnclick import constants
12 from pyntnclick.sound import get_sound
13 12
14 13
15 class Result(object): 14 class Result(object):
16 """Result of interacting with a thing""" 15 """Result of interacting with a thing"""
17 16
18 def __init__(self, message=None, soundfile=None, detail_view=None, 17 def __init__(self, message=None, soundfile=None, detail_view=None,
19 style=None, close_detail=False, end_game=False): 18 style=None, close_detail=False, end_game=False):
20 self.message = message 19 self.message = message
21 self.sound = None 20 self.soundfile = soundfile
22 if soundfile:
23 self.sound = get_sound(soundfile)
24 self.detail_view = detail_view 21 self.detail_view = detail_view
25 self.style = style 22 self.style = style
26 self.close_detail = close_detail 23 self.close_detail = close_detail
27 self.end_game = end_game 24 self.end_game = end_game
28 25
26 def play_sound(self, scene_widget):
27 if self.soundfile:
28 sound = scene_widget.state.gd.sound.get_sound(self.soundfile)
29 sound.play()
30
29 def process(self, scene_widget): 31 def process(self, scene_widget):
30 """Helper function to do the right thing with a result object""" 32 """Helper function to do the right thing with a result object"""
31 if self.sound: 33 self.play_sound(scene_widget)
32 self.sound.play()
33 if self.message: 34 if self.message:
34 scene_widget.show_message(self.message, self.style) 35 scene_widget.show_message(self.message, self.style)
35 if self.detail_view: 36 if self.detail_view:
36 scene_widget.show_detail(self.detail_view) 37 scene_widget.show_detail(self.detail_view)
37 if (self.close_detail 38 if (self.close_detail