Mercurial > parpg-source
diff gamemodel.py @ 116:7f7f54c4077b
Fixed dropping items on the map.
author | KarstenBock@gmx.net |
---|---|
date | Mon, 03 Oct 2011 18:25:31 +0200 |
parents | 81b51b9d861e |
children | 452bbc3d915d |
line wrap: on
line diff
--- a/gamemodel.py Mon Oct 03 14:12:17 2011 +0200 +++ b/gamemodel.py Mon Oct 03 18:25:31 2011 +0200 @@ -51,6 +51,7 @@ function heavy controller.""" ALL_AGENTS_KEY = "All" MAX_ID_NUMBER = 1000 + GENERIC_ITEM_GFX = "generic_item" def __init__(self, engine, settings): """Initialize the instance. @@ -146,12 +147,15 @@ @type object_id: str """ game_object = self.deleteObject(object_id) self.game_state.addObject(object_id, new_map, game_object) - + def deleteObject(self, object_id): """Removes an object from the game @param object_id: ID of the object @type object_id: str """ - del self.agents["All"][object_id] + if self.agents["All"].has_key(object_id): + del self.agents["All"][object_id] + else: + del self.items[object_id] return self.game_state.deleteObject(object_id) def save(self, path, filename): @@ -298,8 +302,10 @@ if agent_values["Entity"].has_key("graphics") \ and agent_values["Entity"]["graphics"].has_key("gfx"): object_model = agent_values["Entity"]["graphics"]["gfx"] + elif agent_values.has_key("Template"): + object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"] else: - object_model = self.object_db[agent_values["Template"]]["graphics"]["gfx"] + object_model = self.GENERIC_ITEM_GFX import_file = self.agent_import_files[object_model] loadImportFile(self.obj_loader, import_file, self.engine) @@ -367,9 +373,11 @@ entity_data["fifeagent"] = {} if agent.has_key("Template"): entity_data = self.checkAttributes(entity_data, agent["Template"]) - object_id = entity_data["graphics"]["gfx"] \ - if entity_data["graphics"].has_key("gfx") \ - else "generic_item" + object_id = (entity_data["graphics"]["gfx"] + if entity_data.has_key("graphics") and + entity_data["graphics"].has_key("gfx") + else self.GENERIC_ITEM_GFX + ) map_obj = self.fife_model.getObject(str(object_id), "PARPG") if not map_obj: logging.warning("Object with inst_id={0}, ns=PARPG, " @@ -474,6 +482,9 @@ return obj def create_item(self, identifier, item_data, world, item_type): + if not item_data["description"].has_key("view_name"): + item_data["description"]["view_name"] = ( + item_data["description"]["real_name"]) item = createEntity(item_data, identifier, world, None) item.containable.item_type = item_type self.game_state.addObject(identifier, None, item) @@ -490,6 +501,7 @@ if self.active_map.agent_layer.getInstances(agent): continue self.createAgent(agents[agent], agent, world) + self.updateObjectDB(world) def placePC(self, world): """Places the PlayerCharacter on the map"""