Ignore:
Timestamp:
09/03/13 08:47:27 (8 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Phase:
public
Message:

Round-tripping through load/save shouldn't discard objects

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/level.py

    r145 r164  
    3030        self._glue = go.PuzzleGlue()
    3131        self._drawables = []
     32        self._game_objects = []
    3233
    3334    def _get_data(self):
     
    3536        with resources.get_file('levels', self.name) as f:
    3637            return load(f)
     38
     39    def _dump_data(self, f):
     40        # For manipulation in tests.
     41        dump({
     42            'size': [self.x, self.y],
     43            'base_tile': self.basetile,
     44            'polygons': self.polygons,
     45            'game_objects': self._game_objects,
     46        }, f)
    3747
    3848    def load(self, space):
     
    4454            for point in points:
    4555                self.polygons[i].append(tuple(point))
    46         for game_object_dict in data.get('game_objects', []):
     56        self._game_objects = data.get('game_objects', [])
     57        for game_object_dict in self._game_objects:
    4758            self._create_game_object(space, **game_object_dict)
    4859
     
    8495            return False
    8596        with resources.get_file('levels', self.name, mode='w') as f:
    86             dump({
    87                 'size': [self.x, self.y],
    88                 'base_tile': self.basetile,
    89                 'polygons': self.polygons,
    90             }, f)
     97            self._dump_data(f)
    9198        return True
    9299
Note: See TracChangeset for help on using the changeset viewer.