示例#1
0
文件: world.py 项目: ztripez/bravo
    def save_player(self, username, player):

        f = self.folder.child("players")
        if not f.exists():
            f.makedirs()
        f = f.child("%s%s" % (username, extension()))
        write_to_file(player.save_to_tag(), f.open("w"))
示例#2
0
文件: world.py 项目: ztripez/bravo
    def __init__(self, folder):
        """
        Load a world from disk.

        :Parameters:
            folder : str
                The directory containing the world.
        """

        self.folder = FilePath(folder)
        if not self.folder.exists():
            self.folder.makedirs()

        self.chunk_cache = weakref.WeakValueDictionary()
        self.dirty_chunk_cache = dict()

        self._pending_chunks = dict()

        self.spawn = (0, 0, 0)
        self.seed = random.randint(0, sys.maxint)

        level = self.folder.child("level%s" % extension())
        if level.exists() and level.getsize():
            self.load_from_tag(read_from_file(level.open("r")))

        write_to_file(self.save_to_tag(), level.open("w"))

        self.chunk_management_loop = LoopingCall(self.sort_chunks)
        self.chunk_management_loop.start(1)
示例#3
0
文件: world.py 项目: ztripez/bravo
    def save_chunk(self, chunk):

        if not chunk.dirty:
            return

        first, second, filename = names_for_chunk(chunk.x, chunk.z)
        f = self.folder.child(first).child(second)
        if not f.exists():
            f.makedirs()
        f = f.child(filename)
        write_to_file(chunk.save_to_tag(), f.open("w"))

        chunk.dirty = False