兔肉腦花楊桃大骨湯才是最完美的食物!

This commit is contained in:
wasneet 2025-04-21 20:53:45 +08:00
parent f430040a7c
commit bd2ae80b1b

View File

@ -4,92 +4,135 @@ from tempfile import TemporaryDirectory
import subprocess
import shutil
import os
import re
import datetime
from tools import convert_zh_to_tw, import_translation_json
# Wasneet声明
# 这个版本完全是依照「不能跑就来打我」原则写的,欢迎纠错!
# ==============================
IMPORTLANG = input("语言?(跳过则语言默认为zh_CN)") # 語言選項
if len(IMPORTLANG) == 0:
IMPORTLANG = "zh_CN"
VERSION = "v" + input("版本号?(跳过则记录构建日期)") # 版本號
if len(VERSION) == 1:
VERSION = "构建于" + str(datetime.date.today())
WEBLATE_PATH = os.path.abspath("../psoutertale-weblate")
BUILD_PATH = os.path.abspath("..") # MDR留其他有地方不认字符串啊qwq,以我的能力只会分开写了
SOURCE_DIR = Path("../Petrichor-PSTVL").resolve() # AX留更改了一些目录(Line 21 & 25)以Petrichor-PSTVL为根目录psoutertale-weblate为上游仓库名假设git clone后的文件夹名默认不更改
# 删除过时构建
os.chdir(BUILD_PATH) # MDR留抄的qwq
for file in os.listdir(BUILD_PATH):
if re.match(r'.+.love', file):
os.remove(file)
# ========== 配置区域 ==========
IMPORTLANG = "zh_CN" # 語言選項
VERSION = "V1" # 版本號
WEBLATE_PATH = Path("F:/Deskto/psoutertale-weblate") # WEBLATE文件夾路徑須修改
SOURCE_DIR = Path("F:/Deskto/Petrichor-PSTVL").resolve() # PETRICHOR專案根目錄須修改
# ==============================
os.chdir(SOURCE_DIR / "translate")
# 拉取weblate仓库更改
print("🟡「提示」 Weblate文本獲取中...")
os.system(f"cd {WEBLATE_PATH} && git pull")
print("🟡「提示」 翻譯文件處理中...")
for lua_file in src_text_path.glob("*.lua"):
import_translation_json(
lua_file,
f"strings/{lua_file.stem}/en_US.json",
f"strings/{lua_file.stem}/{IMPORTLANG}.json",
f"text/{IMPORTLANG}/{lua_file.stem}.lua",
)
os.chdir("..")
PROJECT_ROOT = SOURCE_DIR
LANG_IMAGES = SOURCE_DIR / "images" / IMPORTLANG
BUILD_OUTPUT = f"{BUILD_PATH}/PETRICHOR-{IMPORTLANG} {VERSION}.love"
src_text_path = PROJECT_ROOT / "translate" / "src"
# Wasneet聲明
# 這個版本還是「能跑就行」,不准糾我錯!
# 7z校驗
if shutil.which("7z") is None:
print("🔴「錯誤」 沒安裝7-zip找我我能給你變一個出來啊。")
exit(1)
def main():
PROJECT_ROOT = SOURCE_DIR
LANG_IMAGES = SOURCE_DIR / "images" / IMPORTLANG
BUILD_OUTPUT = SOURCE_DIR / "translate" / "gamebuild" / f"Petrichor-{VERSION}.love"
src_text_path = PROJECT_ROOT / "translate" / "src"
translate_dir = PROJECT_ROOT / "translate"
# 繁瑣的校驗
if not LANG_IMAGES.exists():
print(f"🔴「錯誤」 哥們我怎麼找不到這個文件夾呢:{LANG_IMAGES} 應該不是我的鍋吧?")
exit(1)
print(f"🟢「初始化」 Hello\n 我現在開始裝箱 {IMPORTLANG} 版 Petrichor")
print(f" ▸ 版本號是:{VERSION}")
print(f" ▸ Weblate路徑是{WEBLATE_PATH}")
print(f" ▸ 專案根目錄是:{PROJECT_ROOT}\n")
print("🟡「提示」 遊戲文件裝箱中...")
original_cwd = os.getcwd()
try:
os.chdir(translate_dir)
print(f"🟡「切換目錄」 進入翻譯專案目錄:{os.getcwd()}")
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
print("\n🔵「文本同步」 從Weblate拉取最新譯文中...")
subprocess.run(f"cd {WEBLATE_PATH} && git pull", shell=True, check=True)
shutil.copytree(
SOURCE_DIR,
tmp_path,
ignore=shutil.ignore_patterns(
'translate/*',
'images',
'*.py',
'*.pyc',
'__pycache__',
'.git'
),
dirs_exist_ok=True
)
# 圖片多言語替換
shutil.copytree(
LANG_IMAGES,
tmp_path / "images",
dirs_exist_ok=True
)
print("\n🔵「文件準備」 處理LUA文本模板開始")
for lua_file in src_text_path.glob("*.lua"):
print(f"🟢 處理模板:{lua_file.stem}")
target_dir = translate_dir / "strings" / lua_file.stem
target_dir.mkdir(parents=True, exist_ok=True)
os.chdir(tmp_path)
command = f'7z a -tzip "{BUILD_OUTPUT}" .'
exit_code = os.system(command)
os.chdir(original_cwd)
print(" ▸ 克隆簡體中文譯文中...")
shutil.copy(
WEBLATE_PATH / "petrichor" / lua_file.stem / "zh_CN.json",
target_dir / "zh_CN.json"
)
if exit_code != 0:
print(f"🔴「錯誤」 裝箱失敗,退出碼:{exit_code}")
exit(1)
print(" ▸ 生成繁體中文譯文中...")
convert_zh_to_tw(
target_dir / "zh_CN.json",
target_dir / "zh_TW.json"
)
print(f"\n🟢「提示」 裝箱好啦!給你放在{BUILD_OUTPUT}了,記得看一眼嗷。")
print(" ▸ 編譯最後的語言文件...")
import_translation_json(
lua_file,
target_dir / "en_US.json",
target_dir / f"{IMPORTLANG}.json",
translate_dir / "text" / IMPORTLANG / f"{lua_file.stem}.lua"
)
print(f" ✔️ {lua_file.stem} ビンゴ \n")
print("\n🔵「資源校驗」")
if not LANG_IMAGES.exists():
print(f"🔴「報錯」 我怎麼找不到{LANG_IMAGES}啊,是我的問題嗎(汗")
print("🔴「提示」 你看看你路徑配置的對不對(汗")
return
image_count = len(list(LANG_IMAGES.glob("**/*"))) // 2
print(f"🟢 找到了 {image_count} 個圖片!應該全了!")
print("\n🔵「環境校驗」 來讓我找找你的7-zip...")
if not shutil.which("7z"):
print("🔴「報錯」 快點去安7-zip")
print("🔴 我給你個網址https://www.7-zip.org/")
return
print("🟢 好耶你有7-zip耶")
print(f"\n🟢 「開始裝箱」 開始裝箱{VERSION}咯...")
with TemporaryDirectory() as tmpdir:
tmp_path = Path(tmpdir)
print(f"🟢 我在你電腦裡面創建個臨時檔案夾{tmp_path}沒意見吧?")
print("\n🔵「準備文件」 克隆專案文件中...")
shutil.copytree(
PROJECT_ROOT,
tmp_path,
ignore=shutil.ignore_patterns(
'translate', 'images', '*.py', '*.pyc', '__pycache__', '.git'
),
dirs_exist_ok=True
)
file_count = len(list(tmp_path.glob("**/*"))) // 2
print(f"✔️ {file_count} 個專案文件已克隆完畢!")
print("\n🔵「資源替換」 寫入多語言文件中...")
shutil.copytree(
LANG_IMAGES,
tmp_path / "images",
dirs_exist_ok=True
)
print(f"✔️ {len(list((tmp_path / 'images').glob('**/*')))//2}個圖片資源替換完畢!")
print("\n🔵「壓縮」 LOVE文件生成中...")
os.chdir(tmp_path)
try:
subprocess.run(
f'7z a -tzip "{BUILD_OUTPUT}" .',
shell=True,
check=True,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)
except subprocess.CalledProcessError as e:
print(f"🔴「壓縮錯誤」 裝箱失敗啦T T錯誤碼{e.returncode}")
print("🔴 你看看你關沒關遊戲文件?")
return
finally:
os.chdir(PROJECT_ROOT)
if BUILD_OUTPUT.exists():
print(f"\n🎉「裝箱完畢」 完成啦!!")
print(f"📦 給你放在{BUILD_OUTPUT}了,")
print(f"📏 檔案尺寸是{BUILD_OUTPUT.stat().st_size // 1024}KB應該沒啥問題可能吧")
else:
print("\n🔴「不明瞭的錯誤」 檔案生成失敗")
except Exception as e:
print(f"\n🔴「啥情況?!」 {str(e)}")
finally:
print("\n🔵「清理完畢」 行啦我給之前創建那個文件夾刪了嗷")
print("🟢「再見咯」 放心的關閉該窗口吧!")
if __name__ == "__main__":
main()