Beispiel #1
0
    import sys
    import os
    import levelDownloader

    print("~ Level Length Calculator by zmx (formula from stadust) ~")

    levelFile: str = ''
    levelString: bytes = b''

    if os.getenv("MAIN", "false").lower() == "false":
        levelDownloader.url = "https://absolllute.com/gdps/\
gdapi/downloadGJLevel19.php"

    if len(sys.argv) != 2:
        print(f"""Usage: {sys.argv[0]} <id>...
The following environment variables modify execution:
MAIN - download from 2.1""")
        sys.exit()

    try:
        levelFile = sys.argv[1]
        levelString, levelInfo = levelDownloader.downloadLevel(int(levelFile))
        print(f'Downloaded level `{levelInfo["2"]}`')
    except BaseException:
        print("could not download level!")
        sys.exit(1)
    seconds = getLevelLength(levelString.decode('utf8'))
    minutes, mSeconds = divmod(seconds, 60.0)
    print(f'Length: {round(minutes)}m {math.ceil(mSeconds)}s')
    # ceiling is more accurate to gd?
                        action="store_true")
    parser.add_argument(
        "--color",
        help="convert colored blocks to non colored 1.9 equivalents",
        action="store_true")
    parser.add_argument("--song", help="set custom song id", type=int)

    args = parser.parse_args()

    mainID = args.id

    levelString: LevelString = LevelString(b"")
    levelInfo: RobDict = RobDict({})

    try:
        levelString, levelInfo = levelDownloader.downloadLevel(mainID)
    except BaseException:
        print("invalid level!")
        sys.exit()

    print(f"Downloaded level `{levelInfo['2']}`")
    if args.club:
        print("""Clubstep block conversion enabled!
This can make some levels impossible!""")
        levelUtil.convClubstep = True
    if args.color:
        print("""Color block conversion enabled!
This can make some levels impossible!""")
        levelUtil.convColor = True
    if args.glow:
        print("Glow conversion enabled!")
        levelDownloader.url = "https://absolllute.com/gdps/\
gdapi/downloadGJLevel19.php"

    else:
        print("2.1 level download/upload enabled!")
        levelConverter.url = "http://www.boomlings.com/database/\
uploadGJLevel21.php"

        levelConverter.gameVersion = 21

    # we ensure that at least two arguments are provided
    full_list = [args.base] + args.ids

    for id in full_list:
        try:
            levelString, curLevelInfo = levelDownloader.downloadLevel(
                int(id))  # i promise this isn't dangerous
            print(f"Downloaded level `{curLevelInfo['2']}`")

            levelObjects = levelString.decode().split(';')
            curLevelHeader = levelObjects.pop(0)
            levels.append(levelObjects)

            if id == args.base:
                levelInfo = curLevelInfo
                print(f"Using info from `{levelInfo['2']}`")
                levelHeader = curLevelHeader
        except:
            print(f"Please specfiy a valid id - {id} is broken!")
            sys.exit()

    finalLevel = List[List[str]]