配置解析脚本
This commit is contained in:
parent
a0763a9973
commit
a37014fabf
@ -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",
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user