예제 #1
0
    def load_player(self, username):
        fp = self.folder.child("players").child("%s.dat" % username)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % username)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                                          (username, fp.path))

        try:
            player = Player(username=username)
            x, y, z = [i.value for i in tag["Pos"].tags]
            player.location.pos = Position(x, y, z)

            yaw = tag["Rotation"].tags[0].value
            pitch = tag["Rotation"].tags[1].value
            player.location.ori = Orientation.from_degs(yaw, pitch)

            if "Inventory" in tag:
                self._load_inventory_from_tag(player.inventory,
                                              tag["Inventory"])
        except KeyError, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (player, e))
예제 #2
0
    def load_chunk(self, x, z):
        name = name_for_anvil(x, z)
        fp = self.folder.child("region").child(name)
        region = Region(fp)
        chunk = Chunk(x, z)

        try:
            data = region.get_chunk(x, z)
            tag = NBTFile(buffer=StringIO(data))
            self._load_chunk_from_tag(chunk, tag)
        except MissingChunk:
            raise SerializerReadException("No chunk %r in region" % chunk)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                                          (chunk, e))
예제 #3
0
    def load_level(self):
        fp = self.folder.child("level.dat")
        if not fp.exists():
            raise SerializerReadException("Level doesn't exist!")

        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            raise SerializerReadException("Level (in %s) is corrupt!" %
                                          fp.path)

        try:
            spawn = (tag["Data"]["SpawnX"].value, tag["Data"]["SpawnY"].value,
                     tag["Data"]["SpawnZ"].value)
            seed = tag["Data"]["RandomSeed"].value
            time = tag["Data"]["Time"].value
            level = Level(seed, spawn, time)
            return level
        except KeyError, e:
            # Just raise. It's probably gonna be caught and ignored anyway.
            raise SerializerReadException("Level couldn't be loaded: %s" % e)
예제 #4
0
파일: beta.py 프로젝트: JDShu/bravo
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()

        fp = fp.child(filename)
        if not fp.exists():
            raise SerializerReadException("%r doesn't exist!" % chunk)

        tag = self._read_tag(fp)
        if not tag:
            raise SerializerReadException("%r (in %s) is corrupt!" %
                    (chunk, fp.path))

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException("%r couldn't be loaded: %s" %
                    (chunk, e))
예제 #5
0
    def load_level(self, level):
        tag = self._read_tag(self.folder.child("level.dat"))
        if not tag:
            return

        try:
            level.spawn = (tag["Data"]["SpawnX"].value,
                           tag["Data"]["SpawnY"].value,
                           tag["Data"]["SpawnZ"].value)

            level.seed = tag["Data"]["RandomSeed"].value
            level.time = tag["Data"]["Time"].value
        except KeyError:
            # Just raise. It's probably gonna be caught and ignored anyway.
            raise SerializerReadException("Incomplete level data")
예제 #6
0
    def load_chunk(self, chunk):
        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        fp = self.folder.child(first).child(second)
        if not fp.exists():
            fp.makedirs()
        fp = fp.child(filename)

        tag = self._read_tag(fp)
        if not tag:
            return

        try:
            self._load_chunk_from_tag(chunk, tag)
        except Exception, e:
            raise SerializerReadException(e)
예제 #7
0
 def load_player(self, username):
     if username in self.players:
         return deepcopy(self.players[username])
     raise SerializerReadException("%r couldn't be loaded" % username)
예제 #8
0
 def load_level(self):
     if self.level:
         return deepcopy(self.level)
     raise SerializerReadException("Level couldn't be loaded")
예제 #9
0
 def load_chunk(self, x, z):
     key = x, z
     if key in self.chunks:
         return deepcopy(self.chunks[key])
     raise SerializerReadException("%d, %d couldn't be loaded" % key)