예제 #1
0
 def init_files(self):
     if not hasattr(self, "scenario_folder") or not hasattr(
             self, "file_name"):
         raise ValueError(
             "Path and filename need to be initialised using TestObject.init()"
         )
     default_scenario = AoE2Scenario.create_default()
     read_scenario = AoE2Scenario.from_file(
         f"{self.scenario_folder}{self.file_name}.aoe2scenario")
     return {'default': default_scenario, 'read': read_scenario}
예제 #2
0
def open_scen():
    global scenario
    global trigger_manager
    global openfile

    # 选择场景
    open_success = False
    while open_success == False:
        openfile_t = askopenfilename(title='选择 AoE2 DE 场景文件',
                                     filetypes=[('决定版场景', '*.aoe2scenario'),
                                                ('所有文件', '*')])
        if openfile_t.strip() == "" and openfile.strip() != "":
            # 未选择文件,非首次打开 => 放弃操作
            return 0
        else:
            openfile = openfile_t
        if openfile.strip() == "":
            # 未选择文件,首次打开 => 新建场景
            openfile = '临时/default0.aoe2scenario'
            scenario_folder = '临时/'
            input_file = 'default0'
            scenario = AoE2Scenario.create_default()
            break
        # 分析场景路径
        scenario_folder, input_file = os.path.split(openfile)
        scenario_folder += "/"
        input_file, fileext = os.path.splitext(input_file)
        if fileext == "":
            fileext = ".aoe2scenario"
        try:
            scenario = AoE2Scenario.from_file(scenario_folder + input_file +
                                              fileext)
            open_success = True
        except Exception as reason:
            if len(reason.args) != 0:
                if reason.args[
                        0] == 'Currently unsupported version. Please read the message above. Thank you.':
                    reason = '场景文件格式过旧,请使用游戏编辑器重新保存场景。\n\n——亦或场景文件格式版本过新,请检查当前工具的版本。'
            tk.messagebox.showerror(title='打开失败',
                                    message=f'无法读取场景,原因:\n{reason}')
            open_success = False
        except:
            tk.messagebox.showerror(title='打开失败', message=f'无法读取场景,原因:\n未知原因。')
            open_success = False

    window.title(window_title + ' - [' + input_file + '.aoe2scenario]')
    trigger_manager = scenario.trigger_manager
    trigger_relist()
    get_units_list()

    return 0