-
Notifications
You must be signed in to change notification settings - Fork 44
/
generate_portrait_sl.py
128 lines (113 loc) · 3.67 KB
/
generate_portrait_sl.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import argparse
import os
import sys
import re
import collections
import io
import functools
def get_clean_dct(fname):
with io.open(fname, 'r', encoding='utf8') as f:
text = f.readlines()
dct = {}
entry = []
current_name = ""
for line in text:
txt = re.sub(r"#.*", "", line)
txt = re.sub(r"^\s*$", "", txt)
if txt:
entry.append(txt)
match = re.search(r"\s*name\s*=\s*(.+)", txt)
if match:
current_name = match.group(1).strip()
match = re.match(r"[A-Z]{3}", txt)
if match:
current_name = match.group(0).strip()
match = re.match(r"^}", txt)
if match:
dct[current_name] = entry.copy()
entry = []
duplicates = set()
for key, value in dct.items():
for key2, value2 in dct.items():
if key != key2 and not key in duplicates and not key2 in duplicates:
if functools.reduce(lambda i, j : i and j, map(lambda m, k: m == k, value[2:], value2[2:]), True):
duplicates.add(key2)
for d in duplicates:
dct.pop(d)
print(duplicates)
clean_dct = {}
for key, value in dct.items():
cat = ""
gender = ""
entry = []
for line in value:
if cat and gender and re.search(r"}", line):
k = "%s_%s_%s" % (key, cat, gender)
clean_dct[k] = entry.copy()
entry = []
gender = ""
if cat and gender and not re.search(r"{", line):
entry.append(line.strip())
match = re.match(r"\s*(army|navy|operative)", line)
if match:
cat = match.group(1)
match = re.match(r"\s*(female|male)", line)
if cat and match:
gender = match.group(1)
return clean_dct
def generate_sl(clean_dict):
duplicates = set()
for key, value in clean_dict.items():
for key2, value2 in clean_dict.items():
if key != key2 and not key in duplicates and not key2 in duplicates:
if functools.reduce(lambda i, j : i and j, map(lambda m, k: m == k, value, value2), True):
if re.search(r"(africa|asia|europe)", key):
duplicates.add(key2)
else:
duplicates.add(key)
for d in duplicates:
clean_dict.pop(d)
print(duplicates)
out = []
for tag, types in clean_dct.items():
if len(types) < 1:
continue
entry = ''' defined_text = { #max %d
name = Get_%s
''' % (len(types), tag)
for idx, name in enumerate(types):
entry += ''' text = {
trigger = { state = %d }
localization_key = "GFX_%s_portrait"
}
''' % (idx+1, re.search(r"([^/\.]+)\.", name).group(1))
entry += "}"
out.append(entry)
return out
clean_dct = get_clean_dct("portraits/eaw_portraits.txt")
clean_dct_o = get_clean_dct("portraits/eaw_operative_portraits.txt")
out = ["spriteTypes = {"]
st = set()
for key, value in clean_dct.items():
for x in value:
st.add(x)
for key, value in clean_dct_o.items():
for x in value:
st.add(x)
for x in sorted(st):
txt = ''' spriteType = {
name = "GFX_%s"
textureFile = %s
}''' % (re.search(r"([^/\.]+)\.", x).group(1), x)
out.append(txt)
out.append("}")
with io.open("out_gfx.gfx", 'w', encoding='utf8') as f:
f.write("\n".join(out))
dct = clean_dct
dct.update(clean_dct_o)
out = []
out.extend(generate_sl(dct))
with io.open("out.txt", 'w', encoding='utf8') as f:
f.write("\n".join(out))