-
Notifications
You must be signed in to change notification settings - Fork 0
/
rimworld_main_0330_test.py
153 lines (117 loc) · 4.47 KB
/
rimworld_main_0330_test.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
import universal_functions as uf
import os
from itertools import groupby, chain
#MAIN DEFINITIONS
citiesout_path = r"D:\Google Drive\Games Archives\Rimworld\Save backups\Anhatia Accord (Permadeath).txt"
if os.path.exists(citiesout_path)==False:
citiesout_path = r"C:\Users\Ace\Google Drive\Games Archives\Rimworld\Save backups\Anhatia Accord (Permadeath).txt"
raw_data = []
with open(citiesout_path,'r') as f:
lines = f.readlines()
for line in lines:
raw_data.append(line)
# print(line,)
def get_sections(fle,string):
with open(fle) as f:
grps = groupby(f, key=lambda x: x.lstrip().startswith(string))
for k, v in grps:
if k:
yield chain([next(v)], (next(grps)[1])) # all lines up to next #TYPE
colonist_demarker = '<abilityDataClassAbilityUser.AbilityData>AbilityUser.GenericCompAbilityUser</abilityDataClassAbilityUser.AbilityData>'
# colonist_demarker = '<kindDef>Colonist</kindDef>'
colony_pawns = get_sections(citiesout_path, colonist_demarker)
colony_pawns = [list(i) for i in colony_pawns]
# colony_pawns = [i for i in colony_pawns if 'Colonist' in ''.join(i)]
colony_pawns_final = []
pawn_names = []
colonist_demarker_2 = 'Faction_9'
end_demarker = '<abilityDataPawnAbilityUser.AbilityData>Thing_Human'
end_demarker = '<medCare>Best</medCare>'
for idx,each in enumerate(colony_pawns):
# if idx==10:
# print(each)
if any(colonist_demarker_2 in x for x in each):
branch = []
for pawn in each:
if '<nick>' in pawn:
pawn_names.append(pawn)
if end_demarker not in pawn:
branch.append(pawn)
else:
break
colony_pawns_final.append(branch)
print([len(i) for i in colony_pawns_final])
print(len(colony_pawns_final))
pawn_dict = {}
skill_begin = '<skills>'
skill_end = '</skills>'
skill_relevant = ['<def>','<level>','<passion>']
substrings_to_remove = ["</def>","\n","<def>","<level>","<passion>","</level>","</passion>"]
pawn_subdict_keys = ["Level", "Passion"]
pawn_names_substrings = ['<nick>','</nick>']
for i in pawn_names_substrings:
pawn_names = [x.replace(i,'') for x in pawn_names]
for idx,(i,name) in enumerate(zip(colony_pawns_final,pawn_names)):
# if len(i)<1000:
pawn_dict[name] = {}
print(idx,name,len(i))
for idx2,j in enumerate(i):
if skill_begin in j:
skill_begin_idx = idx2
elif skill_end in j:
skill_end_idx = idx2
pawn_skills = i[skill_begin_idx:skill_end_idx]
pawn_skills = [i.replace('\t','') for i in pawn_skills]
#Distill down to skill cat, skill and passion
pawn_skills = [i for i in pawn_skills if any(w in i for w in skill_relevant)]
groups = []
#Group each into nested list, taking into account passions
# for each in pawn_skills:
# if '<def>' in each:
# groups.append([])
for idx,each in enumerate(pawn_skills):
# print(idx,each)
if '<def>' in each:
try:
if '<passion>' in pawn_skills[idx+2]:
branch = [each,pawn_skills[idx+1],pawn_skills[idx+2]]
else:
branch = [each,pawn_skills[idx+1]]
except IndexError:
try:
branch = [each,pawn_skills[idx+1]]
except IndexError:
branch = [each]
if len(branch)==2:
branch.append('na')
groups.append(branch)
for x in substrings_to_remove:
groups = [[j.replace(x,'') for j in i] for i in groups]
for idx,val in enumerate(groups):
print(groups[idx][1])
# try:
# groups[idx][idx2][1] = int(groups[idx][idx2][1])
# except:
# groups[idx][idx2][1] = 0
# print('groups',idx,name,groups)
keys = [i.pop(0) for i in groups]
# print('keys',keys)
for group_idx,i in enumerate(groups):
pawn_dict[name][keys[group_idx]] = {}
for k,v in zip(pawn_subdict_keys,i):
pawn_dict[name][keys[group_idx]][k] = v
# print('groups',groups)
# print('skills',name,pawn_skills)
# if idx==18:
# if end_demarker in j:
# print('ending',idx2)
# break
# print('')
# print('')
# if 'Michael' in i:
# count+=1
# print(idx,i)
# print('')
for keys,values in pawn_dict.items():
print(keys,values)
print('')