diff --git a/modules/rpgmakermvmz.py b/modules/rpgmakermvmz.py index a4f1675..7fbc2cf 100644 --- a/modules/rpgmakermvmz.py +++ b/modules/rpgmakermvmz.py @@ -29,7 +29,7 @@ MAXHISTORY = 10 ESTIMATE = '' TOKENS = [0, 0] NAMESLIST = [] -FIRSTLINESPEAKERS = False # If 1st line of dialogue is a speaker, set to True +FIRSTLINESPEAKERS = True # If 1st line of dialogue is a speaker, set to True NAMES = False # Output a list of all the character names found BRFLAG = False # If the game uses
instead FIXTEXTWRAP = True # Overwrites textwrap @@ -754,6 +754,7 @@ def searchCodes(page, pbar, jobList, filename): # Grab String if len(codeList[i]['parameters']) > 0: jaString = codeList[i]['parameters'][0] + oldjaString = jaString else: codeList[i]['code'] = -1 i += 1 @@ -775,13 +776,23 @@ def searchCodes(page, pbar, jobList, filename): # jaString = re.sub(retardRegex, '富士見', jaString) # Speaker Check - # Colors - speakerList = re.findall(r'^[\\]+[cC]\[[\d]+\](.+?)[\\]+[Cc]\[[\d]\]\\?\\?$', jaString) + speakerList = [] + + # m and z Codes + match = re.search(r'(.*?)[\\]+m\[\d+?\][\\]+z\[\d+?\]', jaString) + if match: + speakerList.append(match.group(1)) + if '\\c' in speakerList[0]: + speakerList = re.findall(r'^[\\]+[cC]\[[\d]+\](.+?)[\\]+[Cc]\[[\d]\]\\?\\?$', speakerList[0]) # Brackets if len(speakerList) == 0: speakerList = re.findall(r'^【(.*?)】$', jaString) + # Colors + if len(speakerList) == 0: + speakerList = re.findall(r'^[\\]+[cC]\[[\d]+\](.+?)[\\]+[Cc]\[[\d]\]\\?\\?$', jaString) + # None if len(speakerList) == 0 and FIRSTLINESPEAKERS is True: if len(jaString) < 40 \ @@ -789,7 +800,7 @@ def searchCodes(page, pbar, jobList, filename): and codeList[i+1]['code'] in [401, 405, -1] \ and len(codeList[i+1]['parameters']) > 0 \ and len(codeList[i+1]['parameters'][0]) > 0: - if codeList[i+1]['parameters'][0][0] in ['「', '"', '(', '(', '*', '[']: + if codeList[i+1]['parameters'][0].strip()[0] in ['「', '"', '(', '(', '*', '[']: speakerList = re.findall(r'.+', jaString) if len(speakerList) != 0 and codeList[i+1]['code'] in [401, 405, -1]: @@ -797,7 +808,7 @@ def searchCodes(page, pbar, jobList, filename): response = getSpeaker(speakerList[0]) speaker = response[0] totalTokens[0] += response[1][0] - totalTokens[1] += response[1][1] + totalTokens[1] += response[1][1] # Set Data codeList[i]['parameters'][0] = jaString.replace(speakerList[0], speaker) @@ -899,13 +910,6 @@ def searchCodes(page, pbar, jobList, filename): codeList[j]['parameters'] = [fullSpeaker + finalJAString] codeList[j]['code'] = code - # Catch Vars that may break the TL - varString = '' - matchList = re.findall(r'^[\\_]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]', finalJAString) - if len(matchList) != 0: - varString = matchList[0] - finalJAString = finalJAString.replace(matchList[0], '') - # Remove any textwrap if FIXTEXTWRAP is True: finalJAString = re.sub(r'\n', ' ', finalJAString) @@ -1025,9 +1029,6 @@ def searchCodes(page, pbar, jobList, filename): translatedText = translatedText + endtag endtag = '' - # //SE[#] - translatedText = varString + translatedText - # Set Data if speakerID != None: codeList[speakerID]['parameters'] = [fullSpeaker] @@ -1222,6 +1223,29 @@ def searchCodes(page, pbar, jobList, filename): translatedText = textwrap.fill(translatedText, width=WIDTH) codeList[i]['parameters'][3][argVar] = translatedText pbar.update(1) + + if 'MNKR_CommonPopupCoreMZ' in headerString: + argVar = 'text' + ### Message Text First + if argVar in codeList[i]['parameters'][3]: + jaString = codeList[i]['parameters'][3][argVar] + + # If there isn't any Japanese in the text just skip + # if not re.search(r'[一-龠]+|[ぁ-ゔ]+|[ァ-ヴー]+', jaString): + # i += 1 + # continue + + # Remove any textwrap & TL + jaString = re.sub(r'\n', ' ', jaString) + response = translateGPT(jaString, '', False) + translatedText = response[0] + totalTokens[0] += response[1][0] + totalTokens[1] += response[1][1] + + # Textwrap & Set + translatedText = textwrap.fill(translatedText, width=WIDTH) + codeList[i]['parameters'][3][argVar] = translatedText + pbar.update(1) ## Event Code: 657 [Picture Text] [Optional] if 'code' in codeList[i] and codeList[i]['code'] == 657 and CODE657 is True: @@ -2050,111 +2074,30 @@ def getSpeaker(speaker): def subVars(jaString): jaString = jaString.replace('\u3000', ' ') - # Nested - count = 0 - nestedList = re.findall(r'[\\]+[\w]+\[[\\]+[\w]+\[[0-9]+\]\]', jaString) - nestedList = set(nestedList) - if len(nestedList) != 0: - for icon in nestedList: - jaString = jaString.replace(icon, '[Nested_' + str(count) + ']') - count += 1 - - # Icons - count = 0 - iconList = re.findall(r'[\\]+[iIkKwWaA]+\[[0-9]+\]', jaString) - iconList = set(iconList) - if len(iconList) != 0: - for icon in iconList: - jaString = jaString.replace(icon, '[Ascii_' + str(count) + ']') - count += 1 - - # Colors - count = 0 - colorList = re.findall(r'([\\]+c\[\d+\][\\]+c|[\\]+c\[\d+\])', jaString) - colorList = set(colorList) - if len(colorList) != 0: - for color in colorList: - jaString = jaString.replace(color, '[Color_' + str(count) + ']') - count += 1 - - # Names - count = 0 - nameList = re.findall(r'[\\]+[nN]\[.+?\]+', jaString) - nameList = set(nameList) - if len(nameList) != 0: - for name in nameList: - jaString = jaString.replace(name, '[Noun_' + str(count) + ']') - count += 1 - - # Variables - count = 0 - varList = re.findall(r'[\\]+[vV]\[[0-9]+\]', jaString) - varList = set(varList) - if len(varList) != 0: - for var in varList: - jaString = jaString.replace(var, '[Var_' + str(count) + ']') - count += 1 - # Formatting count = 0 - formatList = re.findall(r'[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]', jaString) - formatList = set(formatList) - if len(formatList) != 0: - for var in formatList: + codeList = re.findall(r'[\\]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]', jaString) + codeList = set(codeList) + if len(codeList) != 0: + for var in codeList: jaString = jaString.replace(var, '[FCode_' + str(count) + ']') count += 1 # Put all lists in list and return - allList = [nestedList, iconList, colorList, nameList, varList, formatList] - return [jaString, allList] + return [jaString, codeList] -def resubVars(translatedText, allList): +def resubVars(translatedText, codeList): # Fix Spacing and ChatGPT Nonsense matchList = re.findall(r'\[\s?.+?\s?\]', translatedText) if len(matchList) > 0: for match in matchList: text = match.strip() translatedText = translatedText.replace(match, text) - - # Nested - count = 0 - if len(allList[0]) != 0: - for var in allList[0]: - translatedText = translatedText.replace('[Nested_' + str(count) + ']', var) - count += 1 - - # Icons - count = 0 - if len(allList[1]) != 0: - for var in allList[1]: - translatedText = translatedText.replace('[Ascii_' + str(count) + ']', var) - count += 1 - - # Colors - count = 0 - if len(allList[2]) != 0: - for var in allList[2]: - translatedText = translatedText.replace('[Color_' + str(count) + ']', var) - count += 1 - - # Names - count = 0 - if len(allList[3]) != 0: - for var in allList[3]: - translatedText = translatedText.replace('[Noun_' + str(count) + ']', var) - count += 1 - - # Vars - count = 0 - if len(allList[4]) != 0: - for var in allList[4]: - translatedText = translatedText.replace('[Var_' + str(count) + ']', var) - count += 1 # Formatting count = 0 - if len(allList[5]) != 0: - for var in allList[5]: + if len(codeList) != 0: + for var in codeList: translatedText = translatedText.replace('[FCode_' + str(count) + ']', var) count += 1 @@ -2168,14 +2111,11 @@ def batchList(input_list, batch_size): def createContext(fullPromptFlag, subbedT): characters = 'Game Characters:\n\ -シェーア (Shea) - Female\n\ -ミューテ (Mute) - Female\n\ -タビノ (Tabino) - Female\n\ -スラミー (Slamy) - Female\n\ -クリスタ (Christa) - Female\n\ -ソフィー (Sophie) - Female\n\ -ドーラ (Dora) - Female\n\ -ミューレ (Mule) - Female\n\ +レイラ (Layla) - Female\n\ +ミア (Mia) - Female\n\ +ローズ (Rose) - Female\n\ +テオ (Theo) - Male\n\ +ハルファス (Halfas) - Female\n\ ' system = PROMPT + VOCAB if fullPromptFlag else \ diff --git a/modules/wolf.py b/modules/wolf.py index a80ae27..091e4e3 100644 --- a/modules/wolf.py +++ b/modules/wolf.py @@ -65,7 +65,7 @@ CODE122 = False # Other CODE210 = False -CODE300 = True +CODE300 = False CODE250 = False # Database @@ -427,44 +427,34 @@ def searchCodes(events, pbar, jobList, filename): ### Event Code: 300 Common Events if codeList[i]['code'] == 300 and CODE300 == True: - # Validate size - if len(codeList[i]['stringArgs']) > 1: + # Choices + if codeList[i]['stringArgs'][0] == "選択肢/確認": # Grab String - jaString = codeList[i]['stringArgs'][1] + choiceList = codeList[i]['stringArgs'][1].split(',') - # Skip Heavy Var Text - if 'Hシナリオtext演出' in codeList[i]['stringArgs'][0] or r'/evcg' in jaString: - i += 1 - continue + # Translate Question + question = codeList[i]['stringArgs'][2] + response = translateGPT(question, "", True) + translatedText = response[0] + totalTokens[0] = response[1][0] + totalTokens[1] = response[1][1] - # Catch Vars that may break the TL - # varString = '' - # matchList = re.findall(r'^[\\_]+[\w]+\[[a-zA-Z0-9\\\[\]\_,\s-]+\]', jaString) - # if len(matchList) != 0: - # varString = matchList[0] - # jaString = jaString.replace(matchList[0], '') + # Translate Question + codeList[i]['stringArgs'][2] = translatedText - # Remove Textwrap - jaString = jaString.replace('\n', ' ') + # Translate Choices + response = translateGPT(choiceList, translatedText, True) + choiceListTL = response[0] + totalTokens[0] = response[1][0] + totalTokens[1] = response[1][1] - # Fix Multiple Spaces - jaString = re.sub(r'\s+', ' ', jaString) + # Replace Commas + for j in range(len(choiceListTL)): + choiceListTL[j] = choiceListTL[j].replace(', ', '、') - # Pass 1 - if not setData: - list300.append(jaString) - else: - translatedText = list300[0] - list300.pop(0) - - # Add Textwrap - translatedText = textwrap.fill(translatedText, WIDTH) - - # Add back Potential Variables in String - translatedText = translatedText - - # Set Data - codeList[i]['stringArgs'][1] = translatedText + # Convert to String and Set + translatedText = ','.join(choiceListTL) + codeList[i]['stringArgs'][1] = translatedText ### Event Code: 250 Common Events if codeList[i]['code'] == 250 and CODE250 == True: @@ -605,14 +595,14 @@ def searchDB(events, pbar, jobList, filename): for table in tableList: # Translate NPC - if table['name'] == '主人公ステータス' and NPCFLAG == True: + if table['name'] == 'キャラ会話' and NPCFLAG == True: for npc in table['data']: dataList = npc['data'] # Parse for j in range(len(dataList)): # Name - if 'スペシャルゲージ名称' in dataList[j].get('name'): + if '翔太' in dataList[j].get('name'): # Pass 1 (Grab Data) if setData == False: if dataList[j].get('value') != '': @@ -625,7 +615,7 @@ def searchDB(events, pbar, jobList, filename): NPCList[0].pop(0) # Description - if 'NULL' in dataList[j].get('name'): + if '菊池' in dataList[j].get('name'): # Pass 1 (Grab Data) if setData == False: if dataList[j].get('value') != '': @@ -651,7 +641,7 @@ def searchDB(events, pbar, jobList, filename): NPCList[1].pop(0) # Description - if 'NULL' in dataList[j].get('name'): + if '篠宮' in dataList[j].get('name'): # Pass 1 (Grab Data) if setData == False: if dataList[j].get('value') != '': @@ -704,14 +694,14 @@ def searchDB(events, pbar, jobList, filename): scenarioList[2].pop(0) # Grab Items - if table['name'] == 'アイテム' and ITEMFLAG == True: + if table['name'] == '道具' and ITEMFLAG == True: for item in table['data']: dataList = item['data'] # Parse for j in range(len(dataList)): # Name - if 'アイテム名' in dataList[j].get('name'): + if 'NULL' in dataList[j].get('name'): # Pass 1 (Grab Data) if setData == False: if dataList[j].get('value') != '': @@ -724,7 +714,7 @@ def searchDB(events, pbar, jobList, filename): itemList[0].pop(0) # Description - if '説明文' in dataList[j].get('name'): + if '説明' in dataList[j].get('name'): # Pass 1 (Grab Data) if setData == False: if dataList[j].get('value') != '': @@ -1115,7 +1105,7 @@ def searchDB(events, pbar, jobList, filename): translate = True # ITEMS - if len(itemList[0]) > 0: + if len(itemList[1]) > 0: # Progress Bar total = 0 for itemArray in itemList: diff --git a/modules/wolf2.py b/modules/wolf2.py index 65da1c6..3324fc9 100644 --- a/modules/wolf2.py +++ b/modules/wolf2.py @@ -78,7 +78,7 @@ def handleWOLF2(filename, estimate): else: try: - with open('translated/' + filename, 'w', encoding='cp932', errors='ignore') as outFile: + with open('translated/' + filename, 'w', encoding='shift_jis', errors='ignore') as outFile: start = time.time() translatedData = openFiles(filename) @@ -162,7 +162,7 @@ def translateWOLF(data, translatedList, pbar, filename): while i < len(data): # Speaker - matchList = re.findall(r'(.*):$', data[i]) + matchList = re.findall(r'(.*):', data[i]) if len(matchList) != 0: response = getSpeaker(matchList[0]) speaker = response[0] @@ -173,6 +173,37 @@ def translateWOLF(data, translatedList, pbar, filename): else: speaker = '' + # Options + if '//選択肢' in data[i]: + i += 1 + choiceList = [] + initialIndex = i + while('//' in data[i] and 'の場合' not in data[i]): + choiceList.append(re.search(r'\/\/(.*)', data[i]).group(1)) + i += 1 + + # Translate + response = translateGPT(choiceList, 'This will be a dialogue option', True) + tokens[0] += response[1][0] + tokens[1] += response[1][1] + choiceListTL = response[0] + + # Set Data + if len(choiceList) == len(choiceListTL): + # Set Data + i = initialIndex + while('//' in data[i] and 'の場合' not in data[i]): + choiceListTL[0] = choiceListTL[0].replace(', ', '、') + data[i] = f'//{choiceListTL[0]}\n' + choiceListTL.pop(0) + i += 1 + + # Mismatch + else: + with LOCK: + if filename not in MISMATCH: + MISMATCH.append(filename) + # Lines if r'/' not in data[i] and data[i] != '\n': # Pass 1 @@ -325,7 +356,6 @@ def createContext(fullPromptFlag, subbedT): ちか (Chika) - Female\n\ 和樹 (Kazuki) - Male\n\ かずき (Kazuki) - Male\n\ -松本 (Matsumoto) - Unknown\n\ 猿山 (Saruyama) - Male\n\ 菊池 (Kikuchi) - Male\n\ 篠宮 (Shinomiya) - Male\n\