-
Notifications
You must be signed in to change notification settings - Fork 0
/
factionize_items_all.py
81 lines (58 loc) · 1.94 KB
/
factionize_items_all.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
from module_troops import *
from module_items import *
from module_factions import *
from ID_factions import *
from process_common import *
import re
keep_old_faction=1
def list2string(lst):
out_str="["
for item in lst:
out_str=out_str+item+","
out_str=re.sub(",\Z","]",out_str)
return out_str
def set_item_faction():
r_tuple=[]
for k_item in xrange(len(items)):
faction_list=[]
for i_troop in xrange(len(troops)):
for i_item in troops[i_troop][7]:
if i_item==k_item:
if troops[i_troop][6]<=fac_noble_refugees and troops[i_troop][6]>=fac_no_faction:
faction_list.append(troops[i_troop][6])
faction_set=set(faction_list)
faction_list=list(faction_set)
if len(faction_set)>0:
faction_strings=[]
for i_fac in faction_list:
faction_strings.append("fac_"+factions[i_fac][0])
r_tuple.append([items[k_item][0], faction_strings,k_item])
return r_tuple
def parse_faction():
item_tuple=set_item_faction()
parsed=[]
file = open("./module_items.py","r")
content=file.read()
file.close()
for i_item_tuple in item_tuple:
print i_item_tuple[0],i_item_tuple[1]
if len(items[i_item_tuple[2]])==20 and keep_old_faction==0:
content=re.sub('(\["'+i_item_tuple[0]+'".*?)\[fac_.*?\]',r"\1"+list2string(i_item_tuple[1]),content,re.S)
elif len(items[i_item_tuple[2]])<20:
repstr=", "+list2string(i_item_tuple[1])
if len(items[i_item_tuple[2]])<19:
repstr=", []"+repstr
i=content.find('["'+i_item_tuple[0]+'"')
i=i+len('\["'+i_item_tuple[0]+'"')
match=0;
while (match<=0):
if(content[i]==']'):
match=match+1
if(content[i]=='['):
match=match-1
i=i+1
content=content[:i-1]+repstr+content[i-1:]
file = open("./module_items_factionize_all.py","w")
file.write(content)
file.close()
parse_faction()