From 0d446c83dddf46ba194b9d0de5594f96267cb371 Mon Sep 17 00:00:00 2001 From: SherkeyXD <57581480+SherkeyXD@users.noreply.github.com> Date: Mon, 29 Dec 2025 00:34:52 +0800 Subject: [PATCH] chore: update template tool --- tools/GetImageFromROI/cutter.py | 23 +++++++++-------------- tools/GetImageFromROI/updater.py | 29 ++++++++++++----------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/tools/GetImageFromROI/cutter.py b/tools/GetImageFromROI/cutter.py index 18abd6fcee..9e5ae21340 100644 --- a/tools/GetImageFromROI/cutter.py +++ b/tools/GetImageFromROI/cutter.py @@ -45,7 +45,7 @@ if __name__ == "__main__": task.setdefault("crop_doc", crop_doc) tasks[name] = task - for raw_image in src_path.glob("*.png"): + for raw_image in src_path.rglob("*.png"): print("Processing file:", str(raw_image)) image = cv2.imread(str(raw_image)) if image is None: @@ -53,28 +53,23 @@ if __name__ == "__main__": continue cur_ratio = image.shape[1] / image.shape[0] - if cur_ratio >= std_ratio: # 说明是宽屏或默认16:9,按照高度计算缩放 - dsize_width: int = (int)(cur_ratio * std_height) + if cur_ratio >= std_ratio: + dsize_width: int = int(cur_ratio * std_height) dsize_height: int = std_height - else: # 否则可能是偏正方形的屏幕,按宽度计算 + else: dsize_width: int = std_width dsize_height: int = std_width / cur_ratio dsize = (dsize_width, dsize_height) image = cv2.resize(image, dsize, interpolation=cv2.INTER_AREA) + theme_name = str(raw_image.relative_to(src_path).with_suffix('')) + for i in tasks: - filename = "" - if "template" not in tasks[i]: + if "crop_doc" not in tasks[i]: continue - template = tasks[i]["template"] - if isinstance(template, str): - filename = template - elif isinstance(template, list): - filename = template[0] - - if not filename.startswith(f"{raw_image.stem}/"): - continue + default_temp_name = tasks[f"{i.split('-Entry')[0]}Default"].get("template", "") + filename = f"{theme_name}/{default_temp_name.split("Default/")[-1]}" crop_doc = tasks[i].get("crop_doc", {}) roi = crop_doc.get("roi") diff --git a/tools/GetImageFromROI/updater.py b/tools/GetImageFromROI/updater.py index d7d5577523..04dc0c27b6 100644 --- a/tools/GetImageFromROI/updater.py +++ b/tools/GetImageFromROI/updater.py @@ -12,13 +12,12 @@ template_path = task_file.parent / "template" def update_ui_theme_tasks(): - # Iterate over UiTheme json files for json_path in task_file.glob("UiTheme/*.json"): print(f"Processing {json_path}") with json_path.open("r", encoding="utf-8") as f: tasks = json.load(f) - prefix = json_path.stem # e.g. Depot + prefix = json_path.stem entry_task_name = f"{prefix}-Entry" default_task_name = f"{prefix}Default" @@ -32,8 +31,6 @@ def update_ui_theme_tasks(): print(f"Skipping {json_path}: Default template invalid.") continue - # default_template is like "Default/DepotEnter.png" - # We want "DepotEnter.png" template_suffix = default_template.split("/")[-1] entry_task = tasks[entry_task_name] @@ -41,29 +38,27 @@ def update_ui_theme_tasks(): modified = False - for image in src_path.glob("*.png"): - theme_name = image.stem # e.g. Together - new_task_name = f"{prefix}{theme_name}" - # Check if task already exists + theme_variants = {} + for image in src_path.rglob("*.png"): + theme_path = image.relative_to(src_path).with_suffix("") + group_key = theme_path.parts[0] + theme_variants.setdefault(group_key, []).append(theme_path) + + for group_key, variants in theme_variants.items(): + new_task_name = f"{prefix}{group_key}" if new_task_name in tasks: continue - print(f"Adding new task: {new_task_name}") - - # Create new task + templates = [(variant / template_suffix).as_posix() for variant in variants] + template_value = templates[0] if len(templates) == 1 else templates new_task = { "baseTask": default_task_name, - "template": f"{theme_name}/{template_suffix}", + "template": template_value, } - - # Add to tasks tasks[new_task_name] = new_task - - # Add to next list if new_task_name not in next_list: next_list.append(new_task_name) - modified = True if modified: