-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMorphExtraction.py
125 lines (117 loc) · 4.55 KB
/
MorphExtraction.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
import io
import re
BIOMORPH_FILE = "biomorph.txt"
FILE_TO_EXPORT = "morphs.yaml"
APTITUDES = ["COG", "COO", "SOM", "SAV", "WIL", "REF", "INT"]
class Morph:
def __init__(self, data,morph_type):
self.Data = io.StringIO(data)
self.Name = self.Data.readline()
self.Type = morph_type
self.Implants = []
self.Movement = []
self.AptitudeMax = []
self.Durability = ""
self.WoundThresh = ""
self.Advantages = []
self.Disadvantages = []
self.Traits = []
self.Notes = ""
self.CP = ""
self.Cost = ""
self.SpeedMod = ""
self.Description = ""
self.parse_data()
self.write_to_file()
def write_to_file(self):
print ("Name: ", self.Name)
print ("Type: ", self.Type)
print ("Implants: ", self.Implants)
print ("Movement: ", self.Movement)
# print ("APTITUDES (Maximum)")
# for apt in APTITUDES:
# print(apt)
print ("Durability: ", self.Durability)
print ("Wound Threshold: ", self.WoundThresh)
print ("Advantages: ", self.Advantages)
print ("Descritpion: ", self.Description)
def parse_data(self):
for line in self.Data:
if "Implants: " in line:
self.Implants = line.split(',')
self.Implants[0] = self.Implants[0][9:]
elif "Durability: " in line:
self.Durability = line.partition(': ')
self.Durability = self.Durability[2]
elif "Wound Threshold: " in line:
self.WoundThresh = line.partition(': ')
self.WoundThresh = self.WoundThresh[2]
elif "Advantages: " in line:
temp = line.partition(': ')
temp = temp[2].split(',')
print (self.Name)
print (temp)
for item in temp:
if "trait" in item:
self.Traits.append(item) # remove the traits that are lumped
if "Movement Rate" in item:
self.Movement.append(item) # remove the movement rate upgrades
self.Advantages += self.advantage_parsing(item)
elif "Disadvantages: " in line:
temp = line.partition(': ')
temp = temp[2].split(',')
for item in temp:
if "trait" in item:
self.Traits.append(item)
elif "Movement Rate" in item:
self.Movement.append(item)
elif "Credit Cost: " in line:
self.Cost = line
elif "CP Cost: " in line:
self.CP = line
elif "Movement Rate: " in line:
temp = line.partition(': ')
self.Movement += temp[2]
elif "Aptitude Maximum: " in line:
pass #TODO
elif "Notes: " in line:
pass #TODO
else:
self.Description += line
def advantage_parsing(self, item):
Apt_Check = [apt for apt in APTITUDES if apt in item]
if Apt_Check:
m = re.search('([+])([0-9]+)', item) # Get the +5, +10 or +15 aptitude
num = m.group(2)
return [{Apt_Check[0]: num}]
elif "choice" in item:
if "one" in item:
m = re.search('([+])([0-9]+)', item) # Get the +5, +10 or +15 aptitude
num = m.group(2)
return [{"Choice": num}]
elif "two" in item:
m = re.search('([+])([0-9]+)', item) # Get the +5, +10 or +15 aptitude
num = m.group(2)
return [{"Choice": num}, {"Choice": num}]
elif "three" in item:
m = re.search('([+])([0-9]+)', item) # Get the +5, +10 or +15 aptitude
num = m.group(2)
return [{"Choice": num}, {"Choice": num}, {"Choice": num}]
if "skill" in item:
m = re.search('([+])([0-9]+)', item) # Get the +5, +10 or +15 aptitude
num = m.group(2)
s = re.search('([0-9]+[ ])([A-Z]\w+)', item)
skill = s.group(2)
return [{skill: num}]
return []
if __name__ == '__main__':
data = open(BIOMORPH_FILE, 'r')
data = data.read()
temp = data.partition('---')
temp = temp[2]
while temp is not "":
temp = temp.partition('---')
if "END" not in temp[0]:
morph_data = temp[0]
morph_to_save = Morph(morph_data, "Biomorph")
temp = temp[2]