Ignore:
Timestamp:
Sep 6, 2013, 8:44:14 PM (7 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
Message:

Move the inventory to world, to slightly reduce overall hackyness

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/world.py

    r373 r374  
    2626            'kills': 0,
    2727            'rooms': 0,
    28             'protagonist': Protagonist(pymunk.Space(), self,
    29                                        starting_position),
    3028            'level': (first_level, starting_position),
    3129            'level_state': {},
     30            'inventory': set(),
    3231        }
     32        self.__dict__['protagonist'] = Protagonist(
     33            pymunk.Space(), self, starting_position)
    3334
    3435    def __getattr__(self, name):
     
    5556    def save(self):
    5657        data = self._data.copy()
    57         data['inventory'] = sorted(data.pop('protagonist').inventory)
     58        data['inventory'] = sorted(data['inventory'])
    5859        fn = self._save_location()
    5960        if not os.path.isdir(os.path.dirname(fn)):
     
    6869        with open(fn) as f:
    6970            data = load(f)
    70         self.protagonist.inventory = set(data.pop('inventory', []))
    71         for k, v in data.iteritems():
    72             setattr(self, k, v)
     71        data['inventory'] = set(data['inventory'])
     72        self.__dict__['_data'] = data
    7373        return True
    7474
Note: See TracChangeset for help on using the changeset viewer.