Mercurial > parpg-source
diff gamemodel.py @ 39:3011bc71ab20
Added funcionality to load Entities from file
author | KarstenBock@gmx.net |
---|---|
date | Mon, 05 Sep 2011 14:47:21 +0200 |
parents | 06145a6ee387 |
children | ff3e395abf91 |
line wrap: on
line diff
--- a/gamemodel.py Mon Sep 05 14:46:43 2011 +0200 +++ b/gamemodel.py Mon Sep 05 14:47:21 2011 +0200 @@ -21,16 +21,16 @@ from fife import fife from fife.extensions.serializers.xmlobject import XMLObjectLoader +from parpg.grease.geometry import Vec2d from parpg import vfs from gamestate import GameState -from objects import createObject -from objects.composed import CarryableItem, CarryableContainer from gamemap import GameMap from common.utils import locateFiles from common.utils import parseBool -from inventory import Inventory from parpg.dialogueparsers import YamlDialogueParser, DialogueFormatError +from parpg.entities import createEntity +from parpg import behaviours try: import xml.etree.cElementTree as ElementTree @@ -452,7 +452,7 @@ self.game_state.maps[map_name] = new_map new_map.load(map_file) - def createAgent(self, agent, inst_id): + def createAgent(self, agent, inst_id, world): object_type = agent["ObjectType"] object_id = agent["ObjectModel"] \ if agent.has_key("ObjectModel") \ @@ -498,38 +498,28 @@ inst.act('default', target, True) inst_dict = {} - inst_dict["id"] = inst_id + inst_dict["identifier"] = inst_id + inst_dict["world"]= world inst_dict["type"] = object_type - inst_dict["xpos"] = x_pos - inst_dict["ypos"] = y_pos + inst_dict["pos"] = Vec2d(x_pos, y_pos) inst_dict["gfx"] = object_id - inst_dict["is_open"] = parseBool(agent["Open"]) \ - if agent.has_key("Open") \ - else False - inst_dict["locked"] = parseBool(agent["Locked"]) \ - if agent.has_key("Locked") \ - else False - inst_dict["name"] = agent["ViewName"] - inst_dict["real_name"] = agent["RealName"] \ - if agent.has_key("RealName") \ - else agent["ViewName"] - inst_dict["text"] = agent["Text"] \ - if agent.has_key("Text") \ - else None + if agent.has_key("Open"): + inst_dict["is_open"] = parseBool(agent["Open"]) + if agent.has_key("Locked"): + inst_dict["locked"] = parseBool(agent["Locked"]) + if agent.has_key("ViewName"): + inst_dict["view_name"] = agent["ViewName"] + inst_dict["real_name"] = agent["RealName"] \ + if agent.has_key("RealName") else agent["ViewName"] + if agent.has_key("Text"): + inst_dict["desc"] = agent["Text"] if self.dialogues.has_key(inst_id): inst_dict["dialogue"] = self.dialogues[inst_id] - inst_dict["target_map_name"] = agent["TargetMap"] \ - if agent.\ - has_key("TargetMap") \ - else None - inst_dict["target_x"] = agent["TargetPosition"][0] \ - if agent.\ - has_key("TargetPosition") \ - else None - inst_dict["target_y"] = agent["TargetPosition"][1] \ - if agent.\ - has_key("TargetPosition") \ - else None + if agent.has_key("TargetMap"): + inst_dict["target_map_name"] = agent["TargetMap"] + if agent.has_key("TargetPosition"): + inst_dict["target_x"] = agent["TargetPosition"][0] + inst_dict["target_y"] = agent["TargetPosition"][1] if agent.has_key("Inventory"): inventory = Inventory() inventory_objs = agent["Inventory"] @@ -554,10 +544,16 @@ item_data = agent["item"] inst_dict["item"] = item_data inst_dict["item_type"] = agent["ItemType"] + if agent.has_key("Behaviour"): + inst_dict["behaviour"] = getattr(behaviours, agent["Behaviour"])() + #TODO: Add real statistics and bulk + if object_type == "Character": + inst_dict["statistics"] = {} + inst_dict["max_bulk"] = 100 self.createMapObject(self.active_map.agent_layer, inst_dict) - def placeAgents(self): + def placeAgents(self, world): """Places the current maps agents """ if not self.active_map: return @@ -567,7 +563,7 @@ continue if self.active_map.agent_layer.getInstances(agent): continue - self.createAgent(agents[agent], agent) + self.createAgent(agents[agent], agent, world) def placePC(self): """Places the PlayerCharacter on the map""" @@ -631,10 +627,10 @@ # create the extra data extra = {} if layer is not None: - extra['agent_layer'] = layer + extra['layer'] = layer attributes = self.checkAttributes(attributes) - obj = createObject(attributes, extra) + obj = createEntity(attributes, extra) if obj.trueAttr("PC"): self.addPC(layer, obj)