-
Notifications
You must be signed in to change notification settings - Fork 50
/
gen_enemy_mats.py
executable file
·178 lines (154 loc) · 4.75 KB
/
gen_enemy_mats.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env python3
##-----------------------------------------------------------------------------
##
## Copyright (C) 2016 Arks-Layer, Graham Sanderson
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.
##
##-----------------------------------------------------------------------------
##
## Generates some easy translations relating to enemies.
##
##-----------------------------------------------------------------------------
import json
import re
import sys
## Function Definitions ------------------------------------------------------|
##
## LoadEnemies
##
def LoadEnemies(fname):
#{
ret = {
"ダーカー": "Darker",
"獣": "Monster",
"巨大獣": "Giant Monster",
"鳥": "Bird"
}
j = json.load(open(fname, "r", encoding = "utf8"))
for code in j:
#{
obj = j[code]
if "Text" in obj and "Enabled" in obj and obj["Enabled"]:
ret[obj["OriginalText"]] = obj["Text"]
#}
return ret
#}
##
## Item
##
def Item(items, name):
#{
item = items[name]
if type(item) is list: return item[0]
else: return item
#}
##
## UpToDateItem
##
def UpToDateItem(ln, item):
#{
if type(item) is list:
#{
for k in item:
if ln.find(k) != -1:
return True
return False
#}
else:
return ln.find(item) != -1
#}
##
## ProcFile
##
def ProcFile(fp, out, enemies, items, delimiters):
#{
for ln in fp:
#{
for delim in delimiters:
#{
match = re.match("\\s+\"OriginalText\": \"(.+)" + delim + "(.+)\",\n", ln)
if match is not None and \
match.group(1) in enemies and \
match.group(2) in items:
#{
ln1 = next(fp)
name = enemies[match.group(1)]
item = Item(items, match.group(2))
if not UpToDateItem(ln1, items[match.group(2)]):
#{
ln = ln + \
" \"Text\": \"" + name + " " + item + "\",\n" + \
" \"Enabled\": true\n"
ln2 = next(fp)
if ln2.find("\"Enabled\"") == -1: ln = ln + ln2
#}
else:
ln = ln + ln1
break
#}
#}
out.write(ln)
#}
#}
##
## Main
##
def Main():
#{
enemies = LoadEnemies("rmd/Enemies.json")
with open("rmd/Materials.json", "r", newline = "", encoding = "utf8") as fp:
with open("rmd/Materials.json.1", "w", newline = "", encoding = "utf8") as out:
ProcFile(fp, out, enemies,
{
"甲殻": "Carapace",
"甲羅": "Shell",
"目片": "Eye Piece",
"眼片": "Eyeball",
"刃": "Blade",
"刃片": "Blades",
"脚片": "Leg",
"鱗片": "Scale",
"殻": "Husk",
"殻片": "Husk Part",
"皮片": "Pelt",
"爪": "Claw",
"爪片": "Claw Part",
"ヒレ片": "Fillet",
"羽片": "Wing",
"針片": "Stinger",
"牙片": "Fang",
"盾片": "Exoskeleton",
"骨": "Bone",
"肉": [ "Flesh", "Meat" ],
"ミルク": "Milk",
"体煽": "Trunk"
}, ["の"])
with open("rmd/Enemy Cores.json", "r", newline = "", encoding = "utf8") as fp:
with open("rmd/Enemy Cores.json.1", "w", newline = "", encoding = "utf8") as out:
ProcFile(fp, out, enemies,
{
"コア": "Core",
"超コア": "Ultra Core",
"極コア": "Climax Core"
}, ["の", "・"])
#}
## Entry Point ---------------------------------------------------------------|
if __name__ == "__main__": Main()
## EOF