From a37014fabf907600935054ddd97010a59b1969b9 Mon Sep 17 00:00:00 2001 From: hahwu <31872165+hahwu@users.noreply.github.com> Date: Tue, 10 Feb 2026 18:46:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E8=A7=A3=E6=9E=90=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/cfg/cfg_xlsx.json | 3 ++- tool/cfg/tool_cfg_json.py | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tool/cfg/cfg_xlsx.json b/tool/cfg/cfg_xlsx.json index 1eaa9ef8..345cfb90 100644 --- a/tool/cfg/cfg_xlsx.json +++ b/tool/cfg/cfg_xlsx.json @@ -140,7 +140,8 @@ "out_file": "Item.json", "key": "Id", "sheet_name" :"Item", - "fields" :["Id", "IType", "Effect","Name"] + "fields" :["Id", "IType", "Effect","Name"], + "web_fields" :["Id", "IType", "Effect","Name","FullResourcePath"] }, { "in_file": "Card.xlsx", diff --git a/tool/cfg/tool_cfg_json.py b/tool/cfg/tool_cfg_json.py index d1a9046e..854c618f 100644 --- a/tool/cfg/tool_cfg_json.py +++ b/tool/cfg/tool_cfg_json.py @@ -2,7 +2,12 @@ import os import json import openpyxl import csv +import argparse # Copy-Item -Path "d:\Github\docs\tool\config\*" -Destination "D:\Github\pet_home_server\src\server\gamedata\config\" -Force -Recurse +parser = argparse.ArgumentParser(description="Convert config tables to JSON.") +parser.add_argument("-w", "--web", action="store_true", help="Use web_field when available") +args = parser.parse_args() + current_dir = os.getcwd() # 读取配置文件 cfg_path = os.path.join(current_dir, 'tool/cfg/cfg_xlsx.json') @@ -62,7 +67,9 @@ for file_cfg in file_list: index = row_dict.pop(file_cfg["key"]) # 获取第一列的值作为索引并移除第一列 # 仅保留需要的字段 - row_dict = {field: row_dict[field] for field in file_cfg['fields'] if field in row_dict} + fields_to_use = file_cfg.get("web_fields") if args.web and "web_fields" in file_cfg else file_cfg["fields"] + print(f"Using fields for {file_cfg['out_file']}: {fields_to_use} args.web: {args.web} web_fields in file_cfg: {'web_fields' in file_cfg}") + row_dict = {field: row_dict[field] for field in fields_to_use if field in row_dict} for key, value in row_dict.items(): try: row_dict[key] = json.loads(value)