-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsign_extract.py
71 lines (55 loc) · 2.21 KB
/
sign_extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import glob
import json
import csv
import struct
import re
from common import *
is_Sign_ModularFacility_only = False
files = glob.glob(f'archive/offset_annotated/AbioticFactor/Content/Maps/**/*.*', recursive=True)
csv_file = open(f'out/signs_{VERSION}{"" if is_Sign_ModularFacility_only else "_all"}.csv', 'w', newline='')
writer = csv.writer(csv_file, delimiter='\t')
csv_file2 = open(f'out/signs_{VERSION}{"" if is_Sign_ModularFacility_only else "_all"}_no_offset.csv', 'w', newline='')
writer2 = csv.writer(csv_file2, delimiter='\t')
outer_trim_pattern = re.compile(r'_\d+$')
for file in files:
map_name = file.split('/')[-1].split('\\')[-1].split('.')[0]
with open(file) as f:
objects = json.load(f)
for data in objects:
object_type = data.get('Type', '')
if 'Properties' not in data:
continue
properties = data['Properties']
# if object_type == 'Sign_ModularFacility_C':
# text = properties['DisplayText[5]']
# continue # 아래 것만 바꾸면 됨
# elif object_type == 'TextRenderComponent':
if object_type == 'TextRenderComponent':
outer = data['Outer']
if (is_Sign_ModularFacility_only and not outer.startswith('Sign_ModularFacility')) or \
'Text' not in properties or \
'CultureInvariantString' not in properties['Text']:
continue
text = properties['Text']['CultureInvariantString']
else:
continue
outer = re.sub(outer_trim_pattern, '', outer)
if '!@#' not in text:
continue
text, text_start = text.split('!@#')
if text == '' or text.isspace():
continue
text = visualize_whitespace(text)
writer.writerow([
f'AbioticFactor/Content/Maps/{map_name}.umap',
outer,
int(text_start) + 4, # 텍스트 사이즈부터 시작하는데 메인 스크립트가 실제 텍스트 오프셋을 기대해서 4만큼 더하기
'',
text
])
writer2.writerow([
f'AbioticFactor/Content/Maps/{map_name}.umap',
outer,
'',
text
])