138 lines
5.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from tools import *
from pathlib import Path
from tempfile import TemporaryDirectory
import subprocess
import shutil
import os
from tools import convert_zh_to_tw, import_translation_json
# ========== 配置区域 ==========
IMPORTLANG = "zh_CN" # 語言選項
VERSION = "V1" # 版本號
WEBLATE_PATH = Path("F:/Deskto/psoutertale-weblate") # WEBLATE文件夾路徑須修改
SOURCE_DIR = Path("F:/Deskto/Petrichor-PSTVL").resolve() # PETRICHOR專案根目錄須修改
# ==============================
# Wasneet聲明
# 這個版本還是「能跑就行」,不准糾我錯!
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"
print(f"🟢「初始化」 Hello\n 我現在開始裝箱 {IMPORTLANG} 版 Petrichor")
print(f" ▸ 版本號是:{VERSION}")
print(f" ▸ Weblate路徑是{WEBLATE_PATH}")
print(f" ▸ 專案根目錄是:{PROJECT_ROOT}\n")
try:
os.chdir(translate_dir)
print(f"🟡「切換目錄」 進入翻譯專案目錄:{os.getcwd()}")
print("\n🔵「文本同步」 從Weblate拉取最新譯文中...")
subprocess.run(f"cd {WEBLATE_PATH} && git pull", shell=True, check=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)
print(" ▸ 克隆簡體中文譯文中...")
shutil.copy(
WEBLATE_PATH / "petrichor" / lua_file.stem / "zh_CN.json",
target_dir / "zh_CN.json"
)
print(" ▸ 生成繁體中文譯文中...")
convert_zh_to_tw(
target_dir / "zh_CN.json",
target_dir / "zh_TW.json"
)
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()