view objects/containers.py @ 1:4912a6f97c52

Various improvements to the build process including support for self-contained builds. * Note that despite all of these changes PARPG still does not run because asset paths are not standardized, * Modified the SCons script so that by default running `scons` with no arguments creates a self-contained "build" under a build subdirectory to make in-source testing easier. To install PARPG, use `scons install` instead. * Got rid of the binary launcher and replaced it with a shell script for unix and a batch script for Windows (batch script is untested). The binary turned out to be too much trouble to maintain. * Modified the parpg.settings module and parpg.main entry script so that PARPG searches through several default search paths for configuration file(s). PARPG thus no longer crashes if it can't find a configuration file in any particular search path, but will crash it if can't find any configuration files. * Paths supplied to parpg.main are now appended as search paths for the configuration file(s). * Changed the default configuration file name to "parpg.cfg" to simplify searches. * Created the site_scons directory tree where SCons extensions and tools should be placed. * Created a new SCons builder, CopyRecurse, which can copy only certain files and folders from a directory tree using filters (files and folders that start with a leading dot "." e.g. ".svn" are ignored by default). * Added the CPython SCons tool (stands for Compile-Python - I didn't name it!), which provides the InstallPython builder for pre-compiling python sources before they are installed. However, it is currently broken and only installs the python sources.
author M. George Hansen <technopolitica@gmail.com>
date Tue, 31 May 2011 02:46:20 -0700
parents 7a89ea5404b1
children
line wrap: on
line source

#   This file is part of PARPG.

#   PARPG 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, either version 3 of the License, or
#   (at your option) any later version.

#   PARPG 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.

#   You should have received a copy of the GNU General Public License
#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.

"""Containes classes defining concrete container game objects like crates,
   barrels, chests, etc."""

__all__ = ["WoodenCrate", "Footlocker"]

_AGENT_STATE_NONE, _AGENT_STATE_OPENED, _AGENT_STATE_CLOSED, \
_AGENT_STATE_OPENING, _AGENT_STATE_CLOSING = xrange(5)

from composed import ImmovableContainer
from fife import fife

class WoodenCrate (ImmovableContainer):
    def __init__(self, object_id, name = 'Wooden Crate',
                 text = 'A battered crate', gfx = 'crate', **kwargs):
        ImmovableContainer.__init__(self, ID = object_id, name = name, 
                                    gfx = gfx, text = text, **kwargs)
        
class ContainerBehaviour(fife.InstanceActionListener):
    def __init__(self, parent = None, agent_layer = None):
        fife.InstanceActionListener.__init__(self)
        self.parent = parent
        self.layer = agent_layer
        self.state = _AGENT_STATE_CLOSED
        self.agent = None

    def attachToLayer(self, agent_id):
        """ Attaches to a certain layer
            @type agent_id: String
            @param agent_id: ID of the layer to attach to.
            @return: None"""
        self.agent = self.layer.getInstance(agent_id)
        self.agent.addActionListener(self)
        self.state = _AGENT_STATE_CLOSED
        self.agent.act('closed', self.agent.getLocation())
        
    def onInstanceActionFinished(self, instance, action):
        """What the Actor does when it has finished an action.
           Called by the engine and required for InstanceActionListeners.
           @type instance: fife.Instance
           @param instance: self.agent (the Actor listener is listening for this
            instance)
           @type action: ???
           @param action: ???
           @return: None"""
        if self.state == _AGENT_STATE_OPENING:
            self.agent.act('opened', self.agent.getFacingLocation(), True)
            self.state = _AGENT_STATE_OPENED
        if self.state == _AGENT_STATE_CLOSING:
            self.agent.act('closed', self.agent.getFacingLocation(), True)
            self.state = _AGENT_STATE_CLOSED
        
    def open (self):
        if self.state != _AGENT_STATE_OPENED and self.state != \
                                                _AGENT_STATE_OPENING:
            self.agent.act('open', self.agent.getLocation())
            self.state = _AGENT_STATE_OPENING

    def close(self):
        if self.state != _AGENT_STATE_CLOSED and self.state != \
                                                _AGENT_STATE_CLOSING:
            self.agent.act('close', self.agent.getLocation())
            self.state = _AGENT_STATE_CLOSING  
    
class Footlocker(ImmovableContainer):
    def __init__ (self, object_id, agent_layer=None, name = 'Footlocker',
                  text = 'A Footlocker', gfx = 'lock_box_metal01', **kwargs):
        ImmovableContainer.__init__(self, ID = object_id, name = name, 
                                    gfx = gfx, text = text, **kwargs)
        self.behaviour = None

        self.attributes.append("AnimatedContainer")
        self.createBehaviour(agent_layer)        
        
    def prepareStateForSaving(self, state):
        """Prepares state for saving
        @type state: dictionary
        @param state: State of the object  
        """
        ImmovableContainer.prepareStateForSaving(self, state)
        del state["behaviour"]
    
    def createBehaviour(self, layer):
        self.behaviour = ContainerBehaviour(self, layer)

    def setup(self):
        """@return: None"""
        self.behaviour.attachToLayer(self.ID)

    def open (self):
        super (Footlocker, self).open()
        self.behaviour.open()

    def close(self):
        super (Footlocker, self).close()
        self.behaviour.close()