-
Notifications
You must be signed in to change notification settings - Fork 0
/
#minimapinfoDB.py
114 lines (96 loc) · 2.96 KB
/
#minimapinfoDB.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
# -*- coding: utf-8 -*-
import os
import codecs
import sys
import re
import datetime
from lxml import etree
def getTextID(txt):
txtgp = re.search(r"_LT\[xml.[^\.]*.([0-9]+)\]", txt)
if txtgp is None:
return ""
return int(txtgp.group(1))
targetName = "minimapinfo"
targetTXTName = targetName
localeName = ""
outputName = "Mabi_Minimapinfo"
dataDBText = {}
dataDB = {}
hasTXT = False
hasXML = False
fileList = os.listdir("./data/")
for fileN in fileList:
if hasXML and hasTXT:
break
txtNameMatch = re.match(targetTXTName+".([a-zA-Z]*).txt", fileN)
if txtNameMatch is not None:
targetTXTName = fileN
localeName = txtNameMatch.group(1)
hasTXT = True
continue
xmlNameMatch = re.match(targetName+".xml", fileN)
if xmlNameMatch is not None:
hasXML = True
continue
if hasTXT is False:
print("Missing "+targetTXTName+" TXT file.")
sys.exit()
if hasXML is False:
print("Missing "+targetName+" XML file.")
sys.exit()
today = datetime.datetime.now().strftime("%Y%m%d")
outdir = os.getcwd()+"/patch-"+localeName+"-"+today+"/mod/"
print("Output: " + outdir)
try:
os.makedirs(outdir)
except:
pass
#targetName.XXXXX.txt
infilename = targetTXTName
try:
fi = codecs.open("./data/" + infilename,'r', encoding='utf-16')
line = fi.readline()
fi.seek(0)
except:
fi.close()
fi = codecs.open("./data/" + infilename,'r', encoding='utf-8-sig')
for line in fi:
oline = re.match(r"([0-9]{0,8})\t(([^\r])+)\r\n", line)
if oline is not None:
dataDBText[int(oline.group(1))] = oline.group(2)
fi.close()
print(infilename + " processed.")
#targetName.xml
infilename = targetName + ".xml"
parser = etree.XMLParser(recover=True)
tree = etree.parse("./data/" + infilename, parser)
root = tree.getroot()
for elelist in list(root):
if elelist.tag == "SearchExceptRegionList":
continue
for ele in elelist:
ID = int(ele.attrib["RegionID"])
finalName = "No." + str(ID)
if "MapName" in ele.attrib:
NameID = getTextID(ele.attrib["MapName"])
Name = dataDBText.get(NameID,"")
if Name != "":
finalName = Name
if re.search(u'[\uac00-\ud7af]', finalName) != None:
if "MapLocalName" in ele.attrib:
LocalNameID = getTextID(ele.attrib["MapLocalName"])
LocalName = dataDBText.get(LocalNameID,"")
if LocalName != "":
finalName = LocalName
elif "FieldID" in ele.attrib:
finalName = dataDB.get(int(ele.attrib["FieldID"]), ele.attrib["FieldID"])+"_No."+str(ID)
dataDB[ID] = finalName
print(infilename + " processed.")
dataIDs = list(dataDB.keys())
dataIDs.sort()
fo = codecs.open(outdir+outputName+".ini", 'w', encoding="utf-16")
fo.write("["+outputName+"]\r\n")
for key in dataIDs:
fo.write(str(key)+"="+dataDB[key]+"\r\n")
fo.close()
print(outputName + ".ini generated.")