修改py文件中路径处理相关

This commit is contained in:
ExMingYan 2025-05-05 16:37:20 +08:00
parent 6b857e041a
commit 5614d7b87f
11 changed files with 54 additions and 28 deletions

View File

@ -1,3 +1,4 @@
#!/usr/bin/python python3
# 原始字符串
text = "全副武装的样子。\n即使是极巨化宝可梦的\n攻击也能轻易抵挡。"

View File

@ -1,9 +1,19 @@
#!/usr/bin/python python3
import os
import openpyxl
import re
# 获取py文件所在文件夹绝对路径
pydir = os.path.dirname(os.path.realpath(__file__))
#获取excel相对py文件路径
excel_path = os.path.join(pydir, "src", "精灵跟随.xlsx")
# 获取C文件所在文件夹相对py文件路径
cdir = os.path.join(os.path.dirname(pydir), "src")
# 文件路径
excel_path = r"c:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\python_tools\src\精灵跟随.xlsx"
c_file_path = r"c:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\src\follower_helper.c"
c_file_path = os.path.join(cdir, "follower_helper.c")
# 读取 Excel 文件
wb = openpyxl.load_workbook(excel_path)

View File

@ -1,8 +1,16 @@
#!/usr/bin/python python3
import os
import re
# 获取py文件所在文件夹绝对路径
pydir = os.path.dirname(os.path.realpath(__file__))
# 获取C文件所在文件夹相对py文件路径
cdir = os.path.join(os.path.dirname(pydir), "src")
# 文件路径
input_file = r"c:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\src\strings.c"
output_file = r"c:\Users\Nox\Documents\GitHub\pokeemerald-expansion-Chinese\extracted_strings.txt"
input_file = os.path.join(cdir, "strings.c")
output_file = os.path.join(os.path.dirname(pydir), "extracted_strings.txt")
# 正则表达式匹配变量名和 _("...") 之间的内容
pattern = re.compile(r'const\s+u8\s+(\w+)\[\]\s*=\s*_\("([^"]*)"\)')

View File

@ -1,10 +1,13 @@
#!/usr/bin/python python3
import re
import os
from openpyxl import load_workbook
pydir = os.path.dirname(os.path.abspath(__file__))
# 文件路径
c_file_path = os.path.dirname(os.path.abspath(__file__))+"/../src/battle_message.c"
xlsx_file_path = os.path.dirname(os.path.abspath(__file__))+"/src/战斗文本.xlsx"
c_file_path = os.path.join(os.path.dirname(pydir), "src", "battle_message.c")
xlsx_file_path = os.path.join(pydir, "src", "战斗文本.xlsx")
# 读取 xlsx 文件并解析为字典
def load_translations(xlsx_file_path):

View File

@ -1,3 +1,4 @@
#!/usr/bin/python python3
import re
import openpyxl
import os
@ -45,8 +46,8 @@ def replace_in_c_file(c_file, replacement_dict):
# 主函数
def main():
current_folder = os.path.dirname(os.path.abspath(__file__))
xlsx_file = current_folder+"/src/debug文本.xlsx" # Excel 文件路径
c_file = current_folder+"/../src/battle_debug.c" # C 文件路径
xlsx_file = os.path.join(current_folder, "src", "debug文本.xlsx") # Excel 文件路径
c_file = os.path.join(os.path.dirname(current_folder), "src", "battle_debug.c") # C 文件路径
# 加载替换字典
replacement_dict = load_replacement_dict(xlsx_file)

View File

@ -1,11 +1,12 @@
#!/usr/bin/python python3
import openpyxl
import re
import os
# 文件路径
base_dir = os.path.dirname(os.path.abspath(__file__))
h_file_path = os.path.join(base_dir, "../src/data/decoration/header.h")
xlsx_path = os.path.join(base_dir, "src/装饰物品.xlsx")
h_file_path = os.path.join(os.path.dirname(base_dir), "src", "data", "decoration", "header.h")
xlsx_path = os.path.join(base_dir, "src", "装饰物品.xlsx")
# 加载Excel文件
wb = openpyxl.load_workbook(xlsx_path)

View File

@ -1,10 +1,12 @@
#!/usr/bin/python python3
import openpyxl
import re
import os
# 文件路径
h_file_path = os.path.dirname(os.path.abspath(__file__))+"/../src/data/decoration/description.h"
xlsx_path = os.path.dirname(os.path.abspath(__file__))+"/src/装饰物品.xlsx"
base_dir = os.path.dirname(os.path.abspath(__file__))
h_file_path = os.path.join(os.path.dirname(base_dir), "src", "data", "decoration", "description.h")
xlsx_path = os.path.join(base_dir, "src", "装饰物品.xlsx")
# 加载Excel文件
wb = openpyxl.load_workbook(xlsx_path)

View File

@ -1,3 +1,4 @@
#!/usr/bin/python python3
import os
import re
import pandas as pd
@ -60,13 +61,13 @@ def replace_item_info(content, df):
return content
def log(message):
with open(current_folder+"\log.txt", "a", encoding="utf-8") as log_file:
with open(os.path.join(current_folder, "log.txt"), "a", encoding="utf-8") as log_file:
log_file.write(message + "\n")
print(message)
if __name__ == "__main__":
work_file = current_folder +"\..\src\data\items.h"
df = pd.read_excel(current_folder +r'\src\道具.xlsx')
work_file = os.path.join(os.path.dirname(current_folder), "src", "data", "items.h")
df = pd.read_excel(os.path.join(current_folder, "src", "道具.xlsx"))
df.set_index('道具', inplace=True)

View File

@ -1,3 +1,4 @@
#!/usr/bin/python python3
import os
import re
import pandas as pd
@ -56,14 +57,13 @@ def replace_species_info(content, df):
return content
def log(message):
with open(current_folder+"\log.txt", "a", encoding="utf-8") as log_file:
with open(os.path.join(current_folder, "log.txt"), "a", encoding="utf-8") as log_file:
log_file.write(message + "\n")
print(message)
if __name__ == "__main__":
work_folder = current_folder +"\..\src\data\pokemon\species_info"
df = pd.read_excel(current_folder +r'\src\图鉴.xlsx')
work_folder = os.path.join(os.path.dirname(current_folder), "src", "data", "pokemon", "species_info")
df = pd.read_excel(os.path.join(current_folder, "src", "图鉴.xlsx"))
df.set_index('name', inplace=True)
for filename in os.listdir(work_folder):

View File

@ -1,3 +1,4 @@
#!/usr/bin/python python3
import os
import re
import pandas as pd
@ -60,14 +61,13 @@ def replace_move_info(content, df):
return content
def log(message):
with open(current_folder+"\log.txt", "a", encoding="utf-8") as log_file:
with open(os.path.join(current_folder, "log.txt"), "a", encoding="utf-8") as log_file:
log_file.write(message + "\n")
print(message)
if __name__ == "__main__":
work_file = current_folder +"\..\src\data\moves_info.h"
df = pd.read_excel(current_folder +r'\src\招式.xlsx')
work_file = os.path.join(os.path.dirname(current_folder), "src", "data", "moves_info.h")
df = pd.read_excel(os.path.join(current_folder, "src", "招式.xlsx"))
df.set_index('招式', inplace=True)

View File

@ -1,4 +1,4 @@
#!/usr/bin/python python3
import os
import re
import pandas as pd
@ -44,13 +44,12 @@ def replace_move_info(content, df):
return content
def log(message):
with open(current_folder+"\log.txt", "a", encoding="utf-8") as log_file:
with open(os.path.join(current_folder, "log.txt"), "a", encoding="utf-8") as log_file:
log_file.write(message + "\n")
print(message)
if __name__ == "__main__":
work_file = current_folder +"\..\src\strings.c"
df = pd.read_excel(current_folder + r'\src\文本.xlsx')
work_file = os.path.join(os.path.dirname(current_folder), "src", "strings.c")
df = pd.read_excel(os.path.join(current_folder, "src", "文本.xlsx"))
# 检查并清理重复的“变量名”
df = df.drop_duplicates(subset='变量名', keep='first')