Package parpg :: Module gamemodel :: Class GameModel
[hide private]
[frames] | no frames]

Class GameModel

source code

object --+
         |
        GameModel

GameModel holds the logic for the game. Since some data (object position and so forth) is held in the fife, and would be pointless to replicate, we hold a instance of the fife view here. This also prevents us from just having a function heavy controller.

Instance Methods [hide private]
 
__init__(self, engine, settings)
Initialize the instance.
source code
 
checkAttributes(self, attributes)
Checks for attributes that where not given in the map file and fills them with values from the object database
source code
 
isIDUsed(self, ID) source code
 
createUniqueID(self, ID) source code
 
createContainerItems(self, container_objs)
Create the items of a container from a dictionary
source code
 
createContainerObject(self, attributes)
Create an object that can be stored in an container and return it
source code
 
createInventoryObject(self, container, attributes)
Create an inventory object and place it into a container
source code
 
deleteObject(self, object_id)
Removes an object from the game
source code
 
save(self, path, filename)
Writes the saver to a file.
source code
 
load(self, path, filename)
Loads a saver from a file.
source code
 
teleport(self, agent, position)
Called when a an agent is moved instantly to a new position.
source code
fife.Object
getObjectAtCoords(self, coords)
Get the object which is at the given coords
source code
fife.Location
getCoords(self, click)
Get the map location x, y coordinates from the screen coordinates
source code
 
pause(self, paused)
Pause/Unpause the game
source code
 
togglePause(self)
Toggle paused state.
source code
 
isPaused(self)
Returns wheter the game is paused or not
source code
 
readMapFiles(self)
Read all a available map-files and store them
source code
 
addAgent(self, namespace, agent)
Adds an agent to the agents dictionary
source code
 
readAgentsOfMap(self, map_name)
Read the agents of the map
source code
 
readAllAgents(self)
Read the agents of the all_agents_file and store them
source code
 
getAgentsOfMap(self, map_name)
Returns the agents that are on the given map
source code
 
getAgentsOfActiveMap(self)
Returns the agents that are on active map
source code
 
clearAgents(self)
Resets the agents dictionary
source code
 
loadMap(self, map_name)
Load a new map.
source code
 
createAgent(self, agent, inst_id) source code
 
placeAgents(self)
Places the current maps agents
source code
 
placePC(self)
Places the PlayerCharacter on the map
source code
 
changeMap(self, map_name, target_position=None)
Registers for a map change on the next pump().
source code
 
deleteMaps(self)
Clear all currently loaded maps from FIFE as well as clear our local map cache
source code
 
setActiveMap(self, map_name)
Sets the active map that is to be rendered.
source code
 
createMapObject(self, layer, attributes)
Create an object and add it to the current map.
source code
 
addPC(self, layer, player_char)
Add the PlayerCharacter to the map
source code
 
addObject(self, layer, obj)
Adds an object to the map.
source code
boolean
objectActive(self, ident)
Given the objects ID, pass back the object if it is active, False if it doesn't exist or not displayed
source code
 
movePlayer(self, position)
Code called when the player should move to another location
source code
 
teleportAgent(self, agent, position)
Code called when an agent should teleport to another location
source code
 
readObjectDB(self)
Reads the Object Information Database from a file.
source code
 
getAgentImportFiles(self)
Searches the agents directory for import files
source code
 
getDialogues(self)
Searches the dialogue directory for dialogues
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Class Variables [hide private]
  ALL_AGENTS_KEY = "All"
  MAX_ID_NUMBER = 1000
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, engine, settings)
(Constructor)

source code 

Initialize the instance.

Parameters:
  • engine - A fife.Engine object
  • setting (parpg.settings.Settings object) - The applications settigns
  • emgome (fife.Engine)
Returns:
None
Overrides: object.__init__

checkAttributes(self, attributes)

source code 

Checks for attributes that where not given in the map file and fills them with values from the object database

Parameters:
  • attributes (Dictionary) - attributes to check
Returns:
The modified attributes

createContainerItems(self, container_objs)

source code 

Create the items of a container from a dictionary

Parameters:
  • container_objs (dict) - Dictionary containing the items

createContainerObject(self, attributes)

source code 

Create an object that can be stored in an container and return it

Parameters:
  • attributes (Dictionary) - Dictionary of all object attributes
Returns:
The created object

createInventoryObject(self, container, attributes)

source code 

Create an inventory object and place it into a container

Parameters:
  • container (base.Container) - Container where the item is on
  • attributes (Dictionary) - Dictionary of all object attributes
Returns:
None

deleteObject(self, object_id)

source code 

Removes an object from the game

Parameters:
  • object_id (str) - ID of the object

save(self, path, filename)

source code 

Writes the saver to a file.

Parameters:
  • filename (string) - the name of the file to write to
Returns:
None

load(self, path, filename)

source code 

Loads a saver from a file.

Parameters:
  • filename (string) - the name of the file (including path) to load from
Returns:
None

teleport(self, agent, position)

source code 

Called when a an agent is moved instantly to a new position. The setting of position may wan to be created as its own method down the road.

Parameters:
  • position (String Tuple) - X,Y coordinates passed from engine.changeMap
Returns:
fife.Location

getObjectAtCoords(self, coords)

source code 

Get the object which is at the given coords

Parameters:
  • coords (fife.Screenpoint) - Coordinates where to check for an object
Returns: fife.Object
An object or None

getCoords(self, click)

source code 

Get the map location x, y coordinates from the screen coordinates

Parameters:
  • click (fife.ScreenPoint) - Screen coordinates
Returns: fife.Location
The map coordinates

pause(self, paused)

source code 

Pause/Unpause the game

Returns:
nothing

togglePause(self)

source code 

Toggle paused state.

Returns:
nothing

addAgent(self, namespace, agent)

source code 

Adds an agent to the agents dictionary

Parameters:
  • namespace (str) - the namespace where the agent is to be added to
  • agent (dict) - The agent to be added

readAgentsOfMap(self, map_name)

source code 

Read the agents of the map

Parameters:
  • map_name (str) - Name of the map

getAgentsOfMap(self, map_name)

source code 

Returns the agents that are on the given map

Parameters:
  • map_name (str) - Name of the map
Returns:
A dictionary with the agents of the map

getAgentsOfActiveMap(self)

source code 

Returns the agents that are on active map

Returns:
A dictionary with the agents of the map

loadMap(self, map_name)

source code 

Load a new map.

Parameters:
  • map_name (string) - Name of the map to load
Returns:
None

changeMap(self, map_name, target_position=None)

source code 

Registers for a map change on the next pump().

Parameters:
  • map_name (String) - Id of the map to teleport to
  • map_file (String) - Filename of the map to teleport to
  • target_position (Tuple) - Position of PlayerCharacter on target map. @return None

deleteMaps(self)

source code 

Clear all currently loaded maps from FIFE as well as clear our local map cache

Returns:
nothing

setActiveMap(self, map_name)

source code 

Sets the active map that is to be rendered.

Parameters:
  • map_name (String) - The name of the map to load
Returns:
None

createMapObject(self, layer, attributes)

source code 

Create an object and add it to the current map.

Parameters:
  • layer (fife.Layer) - FIFE layer object exists in
  • attributes (Dictionary) - Dictionary of all object attributes
  • instance (fife.Instance) - FIFE instance corresponding to the object
Returns:
None

addPC(self, layer, player_char)

source code 

Add the PlayerCharacter to the map

Parameters:
  • layer (fife.Layer) - FIFE layer object exists in
  • player_char (PlayerCharacter) - PlayerCharacter object
  • instance (fife.Instance) - FIFE instance of PlayerCharacter
Returns:
None

addObject(self, layer, obj)

source code 

Adds an object to the map.

Parameters:
  • layer (fife.Layer) - FIFE layer object exists in
  • obj (GameObject) - corresponding object class
  • instance (fife.Instance) - FIFE instance of object
Returns:
None

objectActive(self, ident)

source code 

Given the objects ID, pass back the object if it is active, False if it doesn't exist or not displayed

Parameters:
  • ident (string) - ID of object
Returns: boolean
Status of result (True/False)

movePlayer(self, position)

source code 

Code called when the player should move to another location

Parameters:
  • position (fife.ScreenPoint) - Screen position to move to
Returns:
None

teleportAgent(self, agent, position)

source code 

Code called when an agent should teleport to another location

Parameters:
  • position (fife.ScreenPoint) - Screen position to teleport to
Returns:
None