import os
import json
import re
# Создаем папку для чистых JSON файлов
os.makedirs("json_output", exist_ok=True)
# Список системных слов, которые НЕЛЬЗЯ переводить
blacklist = ["bg_", "flg_", "switch", "sure", "memory_", "EXPORT_", "init", "exit", "local", "UTC"]
total_files = 0
print("Конвертация файлов в JSON...")
for file_name in os.listdir("."):
# Читаем .txt файлы, которые сделал ваш unwrap скрипт
if file_name.endswith(".txt") and file_name != "README.txt":
json_data = {}
with open(file_name, "r", encoding="utf-8", errors="ignore") as f:
for line in f:
# Проверяем формат строки: [0xАдрес] Текст
if " " in line:
parts = line.split(" ", 1)
hex_address = parts[0].strip() # Это будет ключом в JSON
text_content = parts[1].strip()
# Проверяем, не является ли строка системной командой
is_system = any(word in text_content for word in blacklist)
# Если это реальный текст (длиной больше 1 символа) и не код — сохраняем
if not is_system and len(text_content) > 1:
json_data[hex_address] = text_content
# Если в файле нашли диалоги, сохраняем JSON
if json_data:
total_files += 1
output_name = os.path.join("json_output", file_name.replace(".txt", ".json"))
with open(output_name, "w", encoding="utf-8") as out_f:
json.dump(json_data, out_f, ensure_ascii=False, indent=4)
print(f"Готово! Обработано файлов: {total_files}. Все файлы сохранены в папку 'json_output'")