From cd68f56906a1cda1b17bf729c8f8ded602a4dfaa Mon Sep 17 00:00:00 2001 From: DazedAnon Date: Sun, 14 Jul 2024 21:46:16 -0500 Subject: [PATCH] Couple of nscript changes --- modules/nscript.py | 25 +++++++++++++++++++++++-- modules/rpgmakermvmz.py | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/modules/nscript.py b/modules/nscript.py index 93ed9fc..04e2088 100644 --- a/modules/nscript.py +++ b/modules/nscript.py @@ -230,11 +230,31 @@ def translateOnscripter(data, pbar, filename, translatedList): translatedText = f'\u3000{translatedText}\\' # Unconvert Codes - matchList = re.findall(r'([$#%].*?)[^\w]', translatedText) + matchList = re.findall(r'([$].+?)[^\w]', translatedText) if matchList: for match in matchList: translatedText = translatedText.replace(match, match.translate(wide_to_ascii)) + # Unconvert Color Codes + matchList = re.findall(r'([#][\w\d]{6})', translatedText) + if matchList: + for match in matchList: + translatedText = translatedText.replace(match, match.translate(wide_to_ascii)) + + # Unconvert Variables + matchList = re.findall(r'([%]\w.+?)[^\w_]', translatedText) + if matchList: + for match in matchList: + translatedText = translatedText.replace(match, match.translate(wide_to_ascii)) + + # Fix Broken Code + matchList = re.findall(r'(: .*)', translatedText, re.DOTALL) + if matchList: + for match in matchList: + code = match.replace('\n', ' ') + translatedText = translatedText.replace(match, '\\' + f'{code.translate(wide_to_ascii)}'.replace('\\', '')) + + # Set Data data[i] = data[i].replace(originalString, translatedText) i += 1 @@ -528,10 +548,11 @@ def extractTranslation(translatedTextList, is_list): line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. if is_list: - string_list = [line_dict[key] for key in sorted(line_dict.keys(), key=lambda x: int(x[4:]))] + string_list = list(line_dict.values()) return string_list except Exception as e: print(e) + return translatedTextList def countTokens(characters, system, user, history): inputTotalTokens = 0 diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index 7e94d6c..3fec16d 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -2220,7 +2220,7 @@ def extractTranslation(translatedTextList, is_list): line_dict = json.loads(translatedTextList) # If it's a batch (i.e., list), extract with tags; otherwise, return the single item. if is_list: - string_list = [line_dict[key] for key in sorted(line_dict.keys(), key=lambda x: int(x[4:]))] + string_list = list(line_dict.values()) return string_list except Exception as e: print(e)