Exemple #1
0
    def load_snapshot(self):
        if not os.path.exists(self.snapshot_path):
            return False

        log.info("Loading snapshot: %s" % self.snapshot_path)
        with open(self.snapshot_path, "r") as f:
            snapshot = f.read()
            # if self.config['persistence'].get('compressed'):
            #     snapshot = zlib.decompress(snapshot)
            snapshot = self.snapshot_serializer.unserialize(snapshot)

            log.info("Creating entities...")

            for entity_dict in snapshot["entities"]:
                entity = Entity.from_dict(
                    {"id": entity_dict["id"], "hearing": entity_dict["hearing"]}, self
                )
                self._max_id = max(self._max_id, entity.id)

            log.info("Creating components...")

            for entity_dict in snapshot["entities"]:
                entity = self.get(entity_dict["id"])
                entity.attach_from_dict(entity_dict)

        return True
Exemple #2
0
    def load_snapshot(self):
        if not os.path.exists(self.snapshot_path):
            return False

        log.info('Loading snapshot: %s' % self.snapshot_path)
        with open(self.snapshot_path, 'r') as f:
            snapshot = f.read()
            # if self.config['persistence'].get('compressed'):
            #     snapshot = zlib.decompress(snapshot)
            snapshot = self.snapshot_serializer.unserialize(snapshot)

            log.info('Creating entities...')

            for entity_dict in snapshot['entities']:
                entity = Entity.from_dict({
                    'id': entity_dict['id'],
                    'hearing': entity_dict['hearing'],
                }, self)
                self._max_id = max(self._max_id, entity.id)

            log.info('Creating components...')

            for entity_dict in snapshot['entities']:
                entity = self.get(entity_dict['id'])
                entity.attach_from_dict(entity_dict)

        return True
Exemple #3
0
 def clone(self, entity):
     # TODO FIXME: This is fairly awful
     return Entity.from_dict(entity.to_dict(), self)
Exemple #4
0
 def spawn(self, components=[], **kwargs):
     entity = Entity(**kwargs)
     self.add(entity)
     if components:
         entity.components.add(components)
     return entity
Exemple #5
0
 def clone(self, entity):
     # TODO FIXME: This is fairly awful
     return Entity.from_dict(entity.to_dict(), self)