Beispiel #1
0
def first_use():
    global config_dir
    global editor_config_dir
    global base_config_dir
    global default_map_dir
    global game
    print(
        Utils.yellow_bright("Configuration wizard (fresh install or update)"))
    print(
        "You may see that wizard because hgl-editor was updated with new settings.\n"
        "Please check that everything is fine (your previous values are showned as "
        "default values)\n")
    if not os.path.exists(config_dir):
        os.makedirs(config_dir)
    if not os.path.exists(os.path.join(base_config_dir, "editor", "maps")):
        os.makedirs(os.path.join(base_config_dir, "editor", "maps"))
    if not os.path.exists(editor_config_dir):
        os.makedirs(editor_config_dir)
    print(
        "We need to set up the default directory where we are going to save maps.",
        f"Default is {default_map_dir}",
    )
    new_default = str(input("Default maps directory: "))
    while (not os.path.exists(new_default) or not os.path.isdir(new_default)
           or not os.path.isabs(new_default)) and new_default != "":
        print(
            Utils.red(
                "The path to directory needs to exists and be absolute."))
        new_default = str(input("Default maps directory: "))
    if new_default != "":
        default_map_dir = new_default
    if not os.path.exists(os.path.join(config_dir, "directories.json")):
        with open(os.path.join(config_dir, "directories.json"), "w") as fp:
            fp.write(f'["{default_map_dir}","hac-maps","maps"]')
    if not os.path.exists(os.path.join(editor_config_dir, "settings.json")):
        game.create_config("settings")
        game.config("settings")["directories"] = [
            default_map_dir, "hac-maps", "maps"
        ]
        game.config("settings")["config_file_version"] = 10100
        game.config("settings")["enable_partial_display"] = True
        game.config("settings")["partial_display_viewport"] = [10, 30]
        game.config("settings")["menu_mode"] = "full"
        game.config("settings")["last_used_board_parameters"] = {
            "name": None,
            "width": None,
            "height": None,
        }
        game.config("settings")["object_library"] = []
Beispiel #2
0
    game.clear_screen()
    print(
        Utils.cyan_bright("HAC-GAME-LIB - EDITOR v" +
                          Constants.HAC_GAME_LIB_VERSION))

    print('Looking for existing maps in selected directories...', end='')
    with open('directories.json') as paths:
        directories = json.load(paths)
        hmaps = []
        try:
            for directory in directories:
                files = [f'{directory}/{f}' for f in os.listdir(directory)]
                hmaps += files
            print(Utils.green('OK'))
        except FileNotFoundError as e:
            print(Utils.red('KO'))

    if len(hmaps) > 0:
        map_num = 0
        game.add_menu_entry('boards_list', None, "Choose a map to edit")
        for m in hmaps:
            print(f"{map_num} - edit {m}")
            game.add_menu_entry('boards_list', str(map_num), f"edit {m}",
                                f"{m}")
            map_num += 1
        game.add_menu_entry('boards_list', 'B', "Go Back to main menu")
    else:
        print('No pre-existing map found.')
    print('n - create a new map')
    print('q - Quit the editor')
    choice = input('Enter your choice (and hit ENTER): ')