Skip to content

Instantly share code, notes, and snippets.

@jbzdarkid
Last active June 18, 2016 23:23
Show Gist options
  • Save jbzdarkid/3722c00e441db452ce0674d1fdb808cd to your computer and use it in GitHub Desktop.
Save jbzdarkid/3722c00e441db452ce0674d1fdb808cd to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from zipfile import ZipFile
from os import sep
from re import findall, sub
dialogues = '''
TermDlg.CLI_Global.Ln0013.0.text.LoadingLibraryOSW1W1
TermDlg.ElevatorFloors.Ln0004.0.text.DetectingAuxiliaryHardware
>
~TermDlg.Common.List
TermDlg.CLI_Global.Ln0105.0.text.SearchingForLocallyCachedResources
TermDlg.UserName.Webcrawl
0000/16/18
TermDlg.FoundTexts.General.Truth.Name
TermDlg.UserName.LitArch
TermDlg.Date.1912CE
TermDlg.FoundTexts.Athena.Chapters.Name
TermDlg.UserName.LitArch
TermDlg.Date.1872CE
TermDlg.FoundTexts.Butler.HumanReproduction.Name
TermDlg.CLI_Global.Ln0040.0.text.GuestLocal
~TermDlg.ElevatorFloors.Ln0018.0.text.DeviceManager
TermDlg.ElevatorFloors.Ln0047.0.text.DeviceManagerV001Is
TermDlg.ElevatorFloors.Ln0061.0.text.ChooseAnOption1Show
~2
TermDlg.ElevatorFloors.Ln0096.0.text.YouAreCurrentlyOn
TermDlg.ElevatorFloors.Ln0113.0.text.CurrentAccessParametersFloor0
TermDlg.ElevatorFloors.Ln0121.0.text.Floor2Locked
TermDlg.ElevatorFloors.Ln0127.0.text.Floor3LockedRequiresCode
TermDlg.ElevatorFloors.Ln0133.0.text.Floor4LockedRequiresCode
TermDlg.ElevatorFloors.Ln0139.0.text.Floor5LockedRequiresCode
TermDlg.ElevatorFloors.Ln0145.0.text.Floor6LockedRequiresCode
TermDlg.ElevatorFloors.Ln0152.0.text.SelectFloorToReconfigure0
~2
TermDlg.ElevatorFloors.Ln0188.0.text.AccessToThatFloorIs
~TermDlg.Common.YesShort
TermDlg.ElevatorFloors.Ln0308.0.text.UnlockingW3W3W3W3
TermDlg.ElevatorFloors.Ln0061.0.text.ChooseAnOption1Show
~4
TermDlg.ElevatorFloors.Ln0334.0.text.ExitingDeviceManager
>
~TermDlg.Common.Exit
TermDlg.Epitaphs.Ln0003.0.text.ChooseYourEpitaph
>
'''.split('\n')[1:-1]
data = {}
TALOS_DIR = r'F:\Steam\steamapps\common\The Talos Principle\Content\Talos'
with ZipFile(TALOS_DIR+sep+'All_01.gro') as all1:
for file in all1.namelist():
if 'translation_All.txt' in file:
lang = file[22:25]
with all1.open(file) as f:
lines = f.read().split('\n')
data[lang] = {line.split('=')[0]:line.split('=', 1)[1] for line in lines if '=' in line}
with ZipFile(TALOS_DIR+sep+'All_02.gro') as all2:
for file in all2.namelist():
if 'translation_All.txt' in file:
lang = file[22:25]
with all2.open(file) as f:
lines = f.read().split('\n')
data[lang] = {line.split('=')[0]:line.split('=', 1)[1] for line in lines if '=' in line}
with ZipFile(TALOS_DIR+sep+'All_03.gro') as all3:
for file in all3.namelist():
if 'translation_All.txt' in file:
lang = file[22:25]
with all3.open(file) as f:
lines = f.read().split('\n')
data[lang] = {line.split('=')[0]:line.split('=', 1)[1] for line in lines if '=' in line}
times = {}
for lang in data:
times[lang] = {'wait':0, 'typed':0, 'chars':0}
output = ''
for line in dialogues:
typed = False
if line == '':
output += '\n'
continue
if line[0] == '~':
typed = True
line = line[1:]
if line not in data[lang]:
output = output[:-1]
output += line
if typed:
output += '\n'
times[lang]['typed'] += len(line)
if lang == 'enu':
print output[-10:]
continue
trans_line = data[lang][line]
trans_line = trans_line.replace('%s0', '')
trans_line = trans_line.replace('%p', '')
if '\\n' not in trans_line:
trans_line = trans_line.strip()
trans_line = trans_line.replace('\\n', '\n')
trans_line = trans_line.replace('<span class="strong">', '')
trans_line = trans_line.replace('</span>', '')
for match in findall('%w(\d)', trans_line):
times[lang]['wait'] += int(match)
trans_line = sub('%w\d', '', trans_line)
output += trans_line
if typed:
output += '\n'
times[lang]['typed'] += len(line)
else:
times[lang]['chars'] += len(trans_line)
if output and lang == 'enu':
print output
output = []
for lang in times:
output.append([times[lang]['wait'], times[lang]['typed'], times[lang]['chars'], lang])
output.sort()
for o in output:
print o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment