コード例 #1
0
 def execute(self, command, *args, **kwargs):
     args: List[str]
     args2 = []
     command_class: BaseCommand = Registry.get_command(command)
     for index in range(0, len(command_class.args)):
         if command_class.args[index] == int:
             if args[index].isnumeric():
                 args2.append(int(args[index]))
                 continue
             return ParserError(f"Invalid type for argument {index}, it's not an integer")
         elif command_class.args[index] == float:
             if args[index].isdigit():
                 args2.append(float(args[index]))
                 continue
             return ParserError(f"Invalid type for argument {index}, it's not a float'")
         elif command_class.args[index] == SPRITE:
             if args[index] in [s.get_sname() for s in Registry.get_sprites()]:
                 args.append(Registry.get_sprite(args[index]))
                 continue
             if args[index].count(":") == 1:
                 return ParserError(f"No such sprite: {repr(args[index])}")
             return ParserError(f"Invalid type for argument {index}")
         else:
             raise ParserError(f"Invalid Command Argument type: {repr(command_class.args[index])}")
     command_class.execute(*args2, **kwargs)
コード例 #2
0
    def create_savedata(self, path, seed):
        game_data = {
            "GameInfo": {
                "seed": seed
            },
            "GameMap": {
                "id": self.get_uname(),
                "seed": seed,
                "initialized": False,
                "Randoms": []
            }
        }

        def dict_exclude_key(key, d: dict):
            d2 = d.copy()
            del d2[key]
            return d2

        spriteinfo_data = {
            "qbubbles:bubble": {
                "speedMultiplier": 5,
                "maxAmount": 100
            },
            "Sprites":
            [sprite.get_sname() for sprite in Registry.get_sprites()],
            "SpriteData":
            dict(((s.get_sname(),
                   dict_exclude_key("objects", dict(s.get_spritedata())))
                  for s in Registry.get_sprites()))
        }

        spriteData = dict()
        for sprite in Registry.get_sprites():
            spriteData[sprite.get_sname()] = sprite.get_spritedata().default

        Registry.saveData = {
            "GameData": game_data,
            "SpriteInfo": spriteinfo_data,
            "SpriteData": spriteData
        }

        bubble_data = {
            "bub-id": [],
            "bub-special": [],
            "bub-action": [],
            "bub-radius": [],
            "bub-speed": [],
            "bub-position": [],
            "bub-index": [],
            "key-active": False
        }

        game_data_file = NZTFile(f"{path}/game.nzt", "w")
        game_data_file.data = game_data
        game_data_file.save()
        game_data_file.close()

        sprite_info_file = NZTFile(f"{path}/spriteinfo.nzt", "w")
        sprite_info_file.data = spriteinfo_data
        sprite_info_file.save()
        sprite_info_file.close()

        os.makedirs(f"{path}/sprites/", exist_ok=True)

        for sprite in spriteData.keys():
            sprite_path = '/'.join(sprite.split(":")[:-1])
            if not os.path.exists(f"{path}/sprites/{sprite_path}"):
                os.makedirs(f"{path}/sprites/{sprite_path}", exist_ok=True)
            sprite_data_file = NZTFile(
                f"{path}/sprites/"
                f"{sprite.replace(':', '/')}.nzt", "w")
            sprite_data_file.data = spriteData[sprite]
            sprite_data_file.save()
            sprite_data_file.close()

        game_data_file = NZTFile(f"{path}/bubble.nzt", "w")
        game_data_file.data = bubble_data
        game_data_file.save()
        game_data_file.close()