Changeset 319 for trunk/game/scripts


Ignore:
Timestamp:
10/12/09 18:26:37 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #73: Patch by eliedebrauwer. Fixed save to match the recent adaptations to gamestate.py, load is still WIP. comment[s:trac, t:73]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/engine.py

    r314 r319  
    6363        # can't pickle SwigPyObjects 
    6464        behaviours = {} 
    65         behaviours[self.game_state.PC.ID] = self.game_state.PC.behaviour; 
     65        behaviour_player = self.game_state.PC.behaviour; 
    6666        self.game_state.PC.behaviour = None; 
    6767         
    68         npcs = [npc for npc in self.game_state.objects.values() \ 
    69                 if npc.trueAttr("NPC")] 
    70         for npc in npcs: 
    71             behaviours[npc.ID] = npc.behaviour; 
    72             npc.behaviour = None; 
    73          
     68        # Backup the behaviours  
     69        for map_id in self.game_state.objects: 
     70            behaviours[map_id]={} 
     71            for (object_id, npc) in self.game_state.objects[map_id].items(): 
     72                print object_id 
     73                if npc.trueAttr("NPC"): 
     74                    behaviours[map_id][object_id]=npc.behaviour 
     75                    npc.behaviour = None; 
     76        print behaviours  
     77        # Pickle it  
    7478        pickle.dump(self.game_state, f) 
    7579        f.close() 
    7680         
    77         # restore behaviours 
    78         for npc in npcs: 
    79             npc.behaviour = behaviours[npc.ID]; 
    80         self.game_state.PC.behaviour = behaviours[self.game_state.PC.ID] 
     81        # Restore behaviours 
     82        for map_id in behaviours: 
     83            for (object_id,behaviour) in behaviours[map_id].items(): 
     84                self.game_state.objects[map_id][object_id].behaviour = \ 
     85                    behaviours[map_id][object_id] 
     86                 
     87        self.game_state.PC.behaviour = behaviour_player 
    8188 
    8289    def load(self, path, filename): 
     
    95102        self.game_state = pickle.load(f) 
    96103        f.close() 
    97         if self.game_state.current_map: 
     104        if self.game_state.current_map_file: 
    98105            self.loadMap(self.game_state.current_map_name, \ 
    99106                         self.game_state.current_map_file)  
Note: See TracChangeset for help on using the changeset viewer.