changeset 116:7f7f54c4077b

Fixed dropping items on the map.
author KarstenBock@gmx.net
date Mon, 03 Oct 2011 18:25:31 +0200
parents 26e65f27dbd7
children f2ef124128db
files gamemodel.py gamescenecontroller.py objects/action.py
diffstat 3 files changed, 35 insertions(+), 25 deletions(-) [+]
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"""
--- a/gamescenecontroller.py	Mon Oct 03 14:12:17 2011 +0200
+++ b/gamescenecontroller.py	Mon Oct 03 18:25:31 2011 +0200
@@ -245,11 +245,13 @@
                                     .getExactLayerCoordinates()
                 commands = ({"Command": "ResetMouseCursor"}, 
                             {"Command": "StopDragging"})
-                self.model.game_state.getObjectById("PlayerCharacter").fifeagent.approach([coord.x, 
-                                                                 coord.y],
-                                    DropItemAction(self, 
-                                                   data_drag.dragged_item, 
-                                                   commands))
+                player_char = (self.model.game_state.
+                               getObjectById("PlayerCharacter"))
+                action =  DropItemAction(self, 
+                                         data_drag.dragged_item, 
+                                         commands)
+                player_char.fifeagent.behaviour.approach([coord.x, coord.y], 
+                                                         action)
             else:
                 self.model.movePlayer(self.model.getCoords(scr_point))
         elif(evt.getButton() == fife.MouseEvent.RIGHT):
--- a/objects/action.py	Mon Oct 03 14:12:17 2011 +0200
+++ b/objects/action.py	Mon Oct 03 18:25:31 2011 +0200
@@ -425,20 +425,16 @@
         
     def execute(self):
         map_name = self.model.game_state.current_map_name
-        map_item_values = {}
-        map_item_values["ViewName"] = self.item.name
-        map_item_values["ObjectType"] = "MapItem"
-        map_item_values["ItemType"] = self.item.item_type
-        map_item_values["Map"] = map_name
-        coords = self.model.game_state.getObjectById("PlayerCharacter").fifeagent.\
-                                        getLocation().getExactLayerCoordinates()
-        map_item_values["Position"] = (coords.x, coords.y)
-        map_item_values["Rotation"] = 0
-        map_item_values["item"] = self.item
-        agent = {}
-        agent[self.item.ID] = map_item_values
-        self.model.addAgent("All", agent)
-        self.model.placeAgents()
+        identifier = self.item.entity.general.identifier
+        agent_values = self.model.items[identifier]
+        coords = (self.model.game_state.getObjectById("PlayerCharacter").
+                  fifeagent.behaviour.getLocation().getExactLayerCoordinates()
+                  )
+        agent_values["Position"] = (coords.x, coords.y)
+        agent_values["Rotation"] = 0
+        self.model.deleteObject(identifier)
+        self.model.addAgent(map_name, {identifier: agent_values})
+        self.model.placeAgents(self.item.entity.world)
         super(DropItemAction, self).execute()
         
 class DropItemFromContainerAction(DropItemAction):