From 6907b8ceb0a6dfe729d5fb7c8e0b0dd1e76137a1 Mon Sep 17 00:00:00 2001 From: Gurkengewuerz Date: Wed, 25 Oct 2023 01:40:08 +0200 Subject: [PATCH] feat: add bundled cleanup script --- assets/translation/clean_bundled.py | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 assets/translation/clean_bundled.py diff --git a/assets/translation/clean_bundled.py b/assets/translation/clean_bundled.py new file mode 100644 index 0000000..ada2131 --- /dev/null +++ b/assets/translation/clean_bundled.py @@ -0,0 +1,56 @@ +import json +import glob +import os + +from fuzzywuzzy import process, fuzz + +def normalize_classnames(classname): + return str(classname).replace("_", "").replace(" ", "") + +todo_types = ["roomitemtypes", "wallitemtypes"] + +orig_furniture_data = {} +# Load the JSON file +with open('../assets/gamedata/FurnitureData.json', 'r', encoding='utf-8') as f: + orig_furniture_data = json.load(f) + +orig_product_dict = {} +# Load the JSON file +with open('../assets/gamedata/ProductData.json', 'r', encoding='utf-8') as f: + orig_product_dict = json.load(f) + +classnames = set() + +for todo_type in todo_types: + for furnitype in orig_furniture_data[todo_type]["furnitype"]: + classnames.add(normalize_classnames(furnitype['classname'])) + + +for product in orig_product_dict["productdata"]["product"]: + classnames.add(normalize_classnames(product['code'])) + +not_matched = set() +nitro_files = glob.glob("../assets/bundled/furniture/*.nitro") +nitro_files_len = float(len(nitro_files)) +for index, nitro in enumerate(nitro_files): + f_name = os.path.basename(nitro) + normalized = normalize_classnames(f_name.rstrip(".nitro")) + matched = False + perc = str(round((float(index + 1) / nitro_files_len) * 100.0, 2)) + "%" + for clazz in classnames.copy(): + string_matched = fuzz.ratio(clazz, normalized) + if string_matched > 75: + matched = True + print("Matched", f_name, clazz, perc) + break + if not matched: + not_matched.add(nitro) + print("Unmatched delete", f_name, perc) + os.remove(nitro) + + +print() +print() +print("-------------------------------") +print(f"Known Classes: {len(classnames)}") +print(f"Unused Files: {len(not_matched)} this result in {int(nitro_files_len - len(not_matched))} remaining files") \ No newline at end of file