view gamelib/scenes/game_widgets.py @ 544:f79d1d3df8e8

pep8 cleanup
author Neil Muller <neil@dip.sun.ac.za>
date Sat, 11 Feb 2012 12:31:33 +0200
parents 821b322e903b
children 098ea4ea0d0d
line wrap: on
line source

"""Generic, game specific widgets"""


from gamelib.state import Thing, Result


class Door(Thing):
    """A door somewhere"""

    DEST = "map"
    SCENE = None

    def __init__(self):
        self.NAME = self.SCENE + '.door'
        Thing.__init__(self)

    def is_interactive(self, tool=None):
        return True

    def interact_without(self):
        """Go to map."""
        self.state.set_current_scene("map")

    def get_description(self):
        return 'An open doorway leads to the rest of the ship.'

    def interact_default(self, item):
        return self.interact_without()


def make_jim_dialog(mesg, state):
    "Utility helper function"
    if state.scenes['bridge'].get_data('ai status') == 'online':
        return Result(mesg, style='JIM')
    else:
        return None


class BaseCamera(Thing):
    "Base class for the camera puzzles"

    INITIAL = 'online'
    INITIAL_DATA = {
         'state': 'online',
    }

    def get_description(self):
        status = self.state.scenes['bridge'].get_data('ai status')
        if status == 'online':
            return "A security camera watches over the room"
        elif status == 'looping':
            return "The security camera is currently offline but should be" \
                    " working soon"
        else:
            return "The security camera is powered down"

    def is_interactive(self, tool=None):
        return self.state.scenes['bridge'].get_data('ai status') == 'online'

    def interact_with_escher_poster(self, item):
        # Order matters here, because of helper function
        if self.state.scenes['bridge'].get_data('ai status') == 'online':
            ai_response = make_jim_dialog("3D scene reconstruction failed."
                    " Critical error. Entering emergency shutdown.",
                    self.state)
            self.state.scenes['bridge'].set_data('ai status', 'looping')
            return ai_response

    def animate(self):
        ai_status = self.state.scenes['bridge'].get_data('ai status')
        if ai_status != self.get_data('status'):
            self.set_data('status', ai_status)
            self.set_interact(ai_status)
        super(BaseCamera, self).animate()