82 lines
4.9 KiB
Python
82 lines
4.9 KiB
Python
"""Normalize observed English UI labels for the existing mirror controller."""
|
||
import re
|
||
|
||
LABELS = {
|
||
'confirm':'确认', 'continue':'继续', 'proceed':'继续', 'enter':'进入', 'cancel':'取消',
|
||
'leave':'离开', 'close':'关闭', 'startbattle':'开始战斗', 'startcombat':'开始战斗',
|
||
'battle!':'开始战斗', 'chainbattle!':'开始战斗',
|
||
'select':'选择', 'selectasinner':'选择一位罪人', 'chooseasinner':'选择一位罪人',
|
||
'commence':'进行判定', 'commencecheck':'进行判定', 'performcheck':'进行判定', 'checksuccess':'判定成功',
|
||
'checkfailure':'判定失败', 'checkpassed':'判定成功', 'checkfailed':'判定失败',
|
||
'result':'结果', 'options':'选项', 'choices':'选项', 'veryhigh':'极高',
|
||
'high':'高', 'shop':'商店', 'specialshop':'特殊商店', 'refresh':'刷新',
|
||
'enhancegifts':'强化饰品', 'enhancee.g.ogifts':'强化饰品', 'purchase':'购买',
|
||
'buy':'购买', 'purchased':'已购买', 'currentownedskills':'当前持有技能',
|
||
'thunderbranch':'雷枝', '雷击木':'雷枝', 'talismanbundle':'成捆的符咒',
|
||
'standard-dutybattery':'标准负载电池', 'standarddutybattery':'标准负载电池',
|
||
'thrill':'快感', 'selecte.g.ogifts':'选择E.G.O饰品',
|
||
'selecte.g.ogift':'选择E.G.O饰品', 'declinegifts':'拒绝饰品',
|
||
'declinegift':'拒绝饰品', 'refusegifts':'拒绝饰品',
|
||
'refusegift':'拒绝饰品', 'selectede.g.ogift':'选择E.G.O饰品',
|
||
'gaine.g.ogift':'获得E.G.O饰品', 'gaine.g.ogift!':'获得E.G.O饰品!',
|
||
'obtaine.g.ogift!':'获得E.G.O饰品!', 'e.g.ogiftobservation':'饰品观测',
|
||
'e.g.ogiftget!':'获得E.G.O饰品!',
|
||
'e.g.ogiftsearch':'额外观测', 'eg.dgiftsearch':'额外观测',
|
||
'nextfloor':'下一层', 'gotonextfloor':'前往下一层', 'proceedtonextfloor':'前往下一层', 'claim':'领取',
|
||
'additionalhardship':'追加的苦难', 'additionalhardships':'追加的苦难',
|
||
'obtaine.g.ogift':'获得E.G.O饰品', 'obtaine.g.ogifts':'获得E.G.O饰品',
|
||
'claimrewards':'领取奖励', 'explorationcomplete':'探索完成',
|
||
'explorationcompleted':'探索完成', 'dungeoncomplete':'探索完成',
|
||
'drive':'驾驶席', 'sinners':'罪人', 'exploring:':'探索状态',
|
||
'beforeentry':'入场前', 'retry':'重试', 'dungeonprogress':'迷宫进度',
|
||
}
|
||
|
||
def normalize(state):
|
||
if state.get('_lc_labels_normalized'):
|
||
return state
|
||
rate_items = []
|
||
for item in state.get('items') or []:
|
||
raw = item['text']
|
||
compact = re.sub(r'\s+', '', raw).lower().lstrip('×x')
|
||
compact = compact.replace('e.g.0', 'e.g.o')
|
||
text = LABELS.get(compact, raw)
|
||
if text == raw:
|
||
match = re.search(r'select(?:the)?(?:floor)?(\d+)(?:st|nd|rd|th)?floorthemepack', compact)
|
||
if not match:
|
||
match = re.search(r'selectfloorthemepack(?:for)?floor(\d+)', compact)
|
||
if not match:
|
||
match = re.search(r'selectfloor(\d+)themepack', compact)
|
||
if match:
|
||
text = '选择%s层主题卡包' % match[1]
|
||
elif re.search(r'(?:select|choose).*encounterreward', compact):
|
||
text = '选择遭遇战奖励卡'
|
||
elif re.search(r'exploring(?:floor)?\d+', compact):
|
||
text = '正在探索第%s层' % re.search(r'\d+', compact)[0]
|
||
elif compact.startswith('select') and re.search(r'\d+/\d+', compact):
|
||
text = '选择' + re.search(r'\d+/\d+', compact)[0]
|
||
elif compact.startswith('refresh'):
|
||
text = raw.replace(raw[:7], '刷新')
|
||
elif compact.startswith('chooseacharactertoperform'):
|
||
text = '选择一位罪人'
|
||
elif re.match(r'who(?:will|should)', compact):
|
||
text = '应该让谁 ' + raw
|
||
elif compact.startswith('skillreplacement') or compact.startswith('replaceskill'):
|
||
text = '技能替换 ' + raw
|
||
# English OCR sometimes merges several adjacent probability labels.
|
||
# Keep each explicit Very High span as a separate observed candidate.
|
||
if item.get('y', 0) > state.get('screen', {}).get('h', 1080) * .8 and 'veryhigh' in compact:
|
||
for match in re.finditer('veryhigh', compact):
|
||
center = item['x'] + (match.start() + len(match[0]) / 2) * item['w'] / len(compact)
|
||
rate_items.append(dict(item, text='极高', original_text=raw,
|
||
x=round(center - 25), w=50))
|
||
for english, chinese in [('Sinclair','辛克莱'), ('Hong Lu','鸿璐'),
|
||
('Heathcliff','希斯克利夫'), ('Outis','奥提斯'), ('Gregor','格里高尔'),
|
||
('Ryoshu','良秀'), ('Faust','浮士德')]:
|
||
text = text.replace(english, chinese)
|
||
if text != raw:
|
||
item['original_text'] = raw
|
||
item['text'] = text
|
||
state['items'] = (state.get('items') or []) + rate_items
|
||
state['_lc_labels_normalized'] = True
|
||
return state
|