server/gamefiles/data/quest/pre_qc.py

169 lines
3.7 KiB
Python
Raw Permalink Normal View History

# -*- coding: 949 -*-
# <20><> <20>״<EFBFBD><D7B4><EFBFBD> pre qc.
# <20><20><><EFBFBD><EFBFBD>Ʈ <20><><EFBFBD><EFBFBD><EEBFA1> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ְ<EFBFBD>,
# state<74><65>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> when, function<6F><6E> <20>ƿ츣<C6BF><ECB8A3> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>.
# <20><><EFBFBD><EFBFBD> '<27><><EFBFBD><EFBFBD>'<27><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ұ<EFBFBD><D2B0>ϰ<EFBFBD>, <20><> <20>ǹ̰<C7B9> <20><><EFBFBD><EFBFBD>.
# <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> '<27><><EFBFBD><EFBFBD>'<27><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ view <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ʿ<EFBFBD><CABF>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
# fuction setting () <20><> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD><D4BC><EFBFBD> <20>̿<EFBFBD><CCBF>Ͽ<EFBFBD>,
# <20>Ź<EFBFBD> <20><><EFBFBD>̺<EFBFBD><CCBA><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD><E4B3BB><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD>.
# <20>̴<EFBFBD> <20>ſ<EFBFBD> <20><>ȿ<EFBFBD><C8BF><EFBFBD><EFBFBD><EFBFBD>̹Ƿ<CCB9>,
# c<><63> preprocesser<65><72> <20><><EFBFBD><EFBFBD> pre qc<71><63> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20>ֵ<EFBFBD><D6B5><EFBFBD> <20>Ͽ<EFBFBD><CFBF><EFBFBD>.
# <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> qc<71><63> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ϱ<EFBFBD> <20><><EFBFBD><EFBFBD> pre_qc.py<70><79> <20><><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>,
# pre_qc.py<70><79> define <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD>ϰ<EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
# pre_qc/filename<6D><65> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
import sys
def split_by_quat (buf):
p = False
l = list (buf)
l.reverse()
s = ""
res = []
while l:
c = l.pop()
if c == '"':
if p == True:
s += c
res += [s]
s = ""
else:
if len (s) != 0:
res += [s]
s = '"'
p = not p
elif c == "\\" and l[0] == '"':
s += c
s += l.pop()
else:
s += c
if len (s) != 0:
res += [s]
return res
def AddSepMiddleOfElement (l, sep):
l.reverse()
new_list = [l.pop()]
while l:
new_list.append (sep)
new_list.append (l.pop())
return new_list
def my_split_with_seps(s, seps):
res = [s]
for sep in seps:
new_res = []
for r in res:
sp = r.split (sep)
sp = AddSepMiddleOfElement (sp, sep)
new_res += sp
res = new_res
new_res = []
for r in res:
if r != '':
new_res.append (r)
return new_res
def my_split(s, seps):
res = [s]
for sep in seps:
new_res = []
for r in res:
sp = r.split (sep)
new_res += sp
res = new_res
new_res = []
for r in res:
if r != '':
new_res.append (r)
return new_res
def MultiIndex (list, key):
l = []
i = 0
for s in list:
if s == key:
l.append (i)
i = i + 1
return l
def Replace (lines, parameter_table, keys):
r = []
for string in lines:
l = split_by_quat (string)
for s in l:
if s[0] == '"':
r += [s]
else:
tokens = my_split_with_seps (s, ["\t", ",", " ", "=", "[", "]",'-','<','>','~','!','.','(',')'])
for key in keys:
try:
idices = MultiIndex(tokens, key)
for i in idices:
tokens[i] = parameter_table[key][0]
except:
pass
r += tokens
return r
def MakeParameterTable(lines, parameter_table, keys):
names = []
values = []
group_names = []
group_values = []
idx = 0
for line in lines:
idx += 1
line = line.strip("\n")
if (-1 != line.find("--")):
line = line[0:line.find("--")]
tokens = my_split(line, ["\t", ",", " ", "=", "[", "]", "\r", "\n"])
if len(tokens) == 0:
continue
if cmp (tokens[0], "quest") == 0:
start = idx
break
if cmp (tokens[0], "define") == 0:
if cmp (tokens[1], "group") == 0:
group_value = []
for value in tokens[3:]:
if parameter_table.get(value, 0) != 0:
value = prameter_table[value]
group_value.append (value)
parameter_table [tokens[2]] = group_value
keys.append(tokens[2])
elif len(tokens) > 5:
print "%d %s" % (idx, "Invalid syntax")
print "define [name] = [value]"
print "define group [name] = \"[\"[v0],[v1], ... \"]\""
else :
if tokens[1] == "rgd_kill_num":
print "fucking"
value = tokens[2]
if parameter_table.get(value, 0) != 0:
value = prameter_table[value]
parameter_table[tokens[1]] = [value]
keys.append (tokens[1])
parameter_table = dict (zip (group_names, group_values))
return start
def run(filename):
parameter_table = dict()
keys = []
filename = filename.strip("\n")
if filename == "":
return
lines = open (filename).readlines()
start = MakeParameterTable (lines, parameter_table, keys)
if len (keys) == 0:
return False
lines = lines [start-1:]
r = Replace (lines, parameter_table, keys)
f = file ("pre_qc/"+filename, "w")
for s in r:
f.write(s)
return True