comparison gamelib/scenes/game_widgets.py @ 525:821b322e903b

Separate "scene widgets" from "game-specific widgets".
author Jeremy Thurgood <firxen@gmail.com>
date Wed, 08 Sep 2010 14:02:11 +0200
parents gamelib/scenes/scene_widgets.py@8f3c82c685a4
children f79d1d3df8e8 2f1952748cdb
comparison
equal deleted inserted replaced
524:a91cb4bffd5d 525:821b322e903b
1 """Generic, game specific widgets"""
2
3
4 from gamelib.state import Thing, Result
5
6
7 class Door(Thing):
8 """A door somewhere"""
9
10 DEST = "map"
11 SCENE = None
12
13 def __init__(self):
14 self.NAME = self.SCENE + '.door'
15 Thing.__init__(self)
16
17 def is_interactive(self, tool=None):
18 return True
19
20 def interact_without(self):
21 """Go to map."""
22 self.state.set_current_scene("map")
23
24 def get_description(self):
25 return 'An open doorway leads to the rest of the ship.'
26
27 def interact_default(self, item):
28 return self.interact_without()
29
30
31 def make_jim_dialog(mesg, state):
32 "Utility helper function"
33 if state.scenes['bridge'].get_data('ai status') == 'online':
34 return Result(mesg, style='JIM')
35 else:
36 return None
37
38
39 class BaseCamera(Thing):
40 "Base class for the camera puzzles"
41
42 INITIAL = 'online'
43 INITIAL_DATA = {
44 'state': 'online',
45 }
46
47 def get_description(self):
48 status = self.state.scenes['bridge'].get_data('ai status')
49 if status == 'online':
50 return "A security camera watches over the room"
51 elif status == 'looping':
52 return "The security camera is currently offline but should be working soon"
53 else:
54 return "The security camera is powered down"
55
56 def is_interactive(self, tool=None):
57 return self.state.scenes['bridge'].get_data('ai status') == 'online'
58
59 def interact_with_escher_poster(self, item):
60 # Order matters here, because of helper function
61 if self.state.scenes['bridge'].get_data('ai status') == 'online':
62 ai_response = make_jim_dialog("3D scene reconstruction failed. Critical error. Entering emergency shutdown.", self.state)
63 self.state.scenes['bridge'].set_data('ai status', 'looping')
64 return ai_response
65
66 def animate(self):
67 ai_status = self.state.scenes['bridge'].get_data('ai status')
68 if ai_status != self.get_data('status'):
69 self.set_data('status', ai_status)
70 self.set_interact(ai_status)
71 super(BaseCamera, self).animate()
72