From 5615071dd0a2e206b59f1f677c0d9f05997af6a5 Mon Sep 17 00:00:00 2001 From: Dazed Date: Sun, 8 Oct 2023 15:17:40 -0500 Subject: [PATCH] Fix subVars --- modules/csv.py | 6 ++--- modules/json.py | 6 ++--- modules/rpgmakerace.py | 6 ++--- modules/rpgmakermvmz.py | 42 ++++++++++++++++++++------------- modules/txt.py | 6 ++--- modules/tyrano.py | 51 +++++++++++++++++++++-------------------- 6 files changed, 64 insertions(+), 53 deletions(-) diff --git a/modules/csv.py b/modules/csv.py index 60ce1a3..aa95947 100644 --- a/modules/csv.py +++ b/modules/csv.py @@ -242,7 +242,7 @@ def subVars(jaString): count = 0 colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) colorList = set(colorList) - if len(iconList) != 0: + if len(colorList) != 0: for color in colorList: jaString = jaString.replace(color, '') count += 1 @@ -251,7 +251,7 @@ def subVars(jaString): count = 0 nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) nameList = set(nameList) - if len(iconList) != 0: + if len(nameList) != 0: for name in nameList: jaString = jaString.replace(name, '') count += 1 @@ -260,7 +260,7 @@ def subVars(jaString): count = 0 varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) varList = set(varList) - if len(iconList) != 0: + if len(varList) != 0: for var in varList: jaString = jaString.replace(var, '') count += 1 diff --git a/modules/json.py b/modules/json.py index 2529504..0756433 100644 --- a/modules/json.py +++ b/modules/json.py @@ -174,7 +174,7 @@ def subVars(jaString): count = 0 colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) colorList = set(colorList) - if len(iconList) != 0: + if len(colorList) != 0: for color in colorList: jaString = jaString.replace(color, '') count += 1 @@ -183,7 +183,7 @@ def subVars(jaString): count = 0 nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) nameList = set(nameList) - if len(iconList) != 0: + if len(nameList) != 0: for name in nameList: jaString = jaString.replace(name, '') count += 1 @@ -192,7 +192,7 @@ def subVars(jaString): count = 0 varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) varList = set(varList) - if len(iconList) != 0: + if len(varList) != 0: for var in varList: jaString = jaString.replace(var, '') count += 1 diff --git a/modules/rpgmakerace.py b/modules/rpgmakerace.py index 7aa18d4..beebf6a 100644 --- a/modules/rpgmakerace.py +++ b/modules/rpgmakerace.py @@ -1348,7 +1348,7 @@ def subVars(jaString): count = 0 colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) colorList = set(colorList) - if len(iconList) != 0: + if len(colorList) != 0: for color in colorList: jaString = jaString.replace(color, '') count += 1 @@ -1357,7 +1357,7 @@ def subVars(jaString): count = 0 nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) nameList = set(nameList) - if len(iconList) != 0: + if len(nameList) != 0: for name in nameList: jaString = jaString.replace(name, '') count += 1 @@ -1366,7 +1366,7 @@ def subVars(jaString): count = 0 varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) varList = set(varList) - if len(iconList) != 0: + if len(varList) != 0: for var in varList: jaString = jaString.replace(var, '') count += 1 diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index 223873a..0ff3c3b 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -862,21 +862,31 @@ def searchCodes(page, pbar): jaString = codeList[i]['parameters'][0] if type(jaString) != str: continue + + # Force Speaker + if 'natu' in jaString: + speaker = 'Natsu' + continue + elif 'kotohana' in jaString: + speaker = 'Kotohana' + continue + elif 'aoi' in jaString: + speaker = 'Aoi' + continue + elif 'misaki' in jaString: + speaker = 'Misaki' + continue + elif 'koume' in jaString: + speaker = 'Koume' + continue + elif 'titose' in jaString: + speaker = 'Chitose' + continue + else: + speaker = 'Unknown' # Definitely don't want to mess with files if '_' in jaString: - if 'natu' in jaString: - speaker = 'Natu' - elif 'kotohana' in jaString: - speaker = 'Kotohana' - elif 'aoi' in jaString: - speaker = 'Aoi' - elif 'misaki' in jaString: - speaker = 'Misaki' - elif 'koume' in jaString: - speaker = 'Koume' - elif 'titose' in jaString: - speaker = 'Chitose' continue # If there isn't any Japanese in the text just skip @@ -1385,7 +1395,7 @@ def subVars(jaString): count = 0 colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) colorList = set(colorList) - if len(iconList) != 0: + if len(colorList) != 0: for color in colorList: jaString = jaString.replace(color, '') count += 1 @@ -1394,7 +1404,7 @@ def subVars(jaString): count = 0 nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) nameList = set(nameList) - if len(iconList) != 0: + if len(nameList) != 0: for name in nameList: jaString = jaString.replace(name, '') count += 1 @@ -1403,7 +1413,7 @@ def subVars(jaString): count = 0 varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) varList = set(varList) - if len(iconList) != 0: + if len(varList) != 0: for var in varList: jaString = jaString.replace(var, '') count += 1 @@ -1467,7 +1477,7 @@ def translateGPT(t, history, fullPromptFlag): subbedT = varResponse[0] # If there isn't any Japanese in the text just skip - if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', subbedT): + if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴ]+', subbedT): return(t, 0) """Translate text using GPT""" diff --git a/modules/txt.py b/modules/txt.py index c3f4a5e..5c7df89 100644 --- a/modules/txt.py +++ b/modules/txt.py @@ -222,7 +222,7 @@ def subVars(jaString): count = 0 colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) colorList = set(colorList) - if len(iconList) != 0: + if len(colorList) != 0: for color in colorList: jaString = jaString.replace(color, '') count += 1 @@ -231,7 +231,7 @@ def subVars(jaString): count = 0 nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) nameList = set(nameList) - if len(iconList) != 0: + if len(nameList) != 0: for name in nameList: jaString = jaString.replace(name, '') count += 1 @@ -240,7 +240,7 @@ def subVars(jaString): count = 0 varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) varList = set(varList) - if len(iconList) != 0: + if len(varList) != 0: for var in varList: jaString = jaString.replace(var, '') count += 1 diff --git a/modules/tyrano.py b/modules/tyrano.py index be0298f..2a310ba 100644 --- a/modules/tyrano.py +++ b/modules/tyrano.py @@ -302,47 +302,48 @@ def subVars(jaString): allList = [iconList, colorList, nameList, varList] return [jaString, allList] -def resubVars(translatedText, allList): - # Fix Spacing and ChatGPT Nonsense - matchList = re.findall(r'<\s?.+?\s?>', translatedText) - if len(matchList) > 0: - for match in matchList: - text = match.replace(' ', '') - translatedText = translatedText.replace(match, text) +def subVars(jaString): + jaString = jaString.replace('\u3000', ' ') # Icons count = 0 - if len(allList[0]) != 0: - for var in allList[0]: - translatedText = translatedText.replace('', var) + iconList = re.findall(r'[\\]+[iI]\[[0-9]+\]', jaString) + iconList = set(iconList) + if len(iconList) != 0: + for icon in iconList: + jaString = jaString.replace(icon, '') count += 1 # Colors count = 0 - if len(allList[1]) != 0: - for var in allList[1]: - translatedText = translatedText.replace('', var) + colorList = re.findall(r'[\\]+[cC]\[[0-9]+\]', jaString) + colorList = set(colorList) + if len(colorList) != 0: + for color in colorList: + jaString = jaString.replace(color, '') count += 1 # Names count = 0 - if len(allList[1]) != 0: - for var in allList[2]: - translatedText = translatedText.replace('', var) + nameList = re.findall(r'[\\]+[nN]\[[0-9]+\]', jaString) + nameList = set(nameList) + if len(nameList) != 0: + for name in nameList: + jaString = jaString.replace(name, '') count += 1 - # Vars + # Variables count = 0 - if len(allList[1]) != 0: - for var in allList[3]: - translatedText = translatedText.replace('', var) + varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) + varList = set(varList) + if len(varList) != 0: + for var in varList: + jaString = jaString.replace(var, '') count += 1 - # Remove Color Variables Spaces - # if '\\c' in translatedText: - # translatedText = re.sub(r'\s*(\\+c\[[1-9]+\])\s*', r' \1', translatedText) - # translatedText = re.sub(r'\s*(\\+c\[0+\])', r'\1', translatedText) - return translatedText + # Put all lists in list and return + allList = [iconList, colorList, nameList, varList] + return [jaString, allList] @retry(exceptions=Exception, tries=5, delay=5) def translateGPT(t, history, fullPromptFlag):