-
Notifications
You must be signed in to change notification settings - Fork 1
/
Parser.py
141 lines (120 loc) · 5.59 KB
/
Parser.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
import ConfigParser
class Parser:
def __init__(self):
self.mainConfig = ConfigParser.ConfigParser()
self.mainConfig.read("./data/config/main.cfg")
self.userConfig = ConfigParser.ConfigParser()
self.userConfig.read(self.mainConfig.get('main', 'user_config_file'))
self.wallConfig = ConfigParser.ConfigParser()
self.wallConfig.read(self.mainConfig.get('main', 'wall_config_file'))
self.unitConfig = ConfigParser.ConfigParser()
self.unitConfig.read(self.mainConfig.get('main', 'unit_config_file'))
self.objectConfig = ConfigParser.ConfigParser()
self.objectConfig.read(self.mainConfig.get('main', 'object_config_file'))
self.buildingConfig = ConfigParser.ConfigParser()
self.buildingConfig.read(self.mainConfig.get('main', 'building_config_file'))
# self.loadConfigs()
# def loadConfigs(self):
def isNumber(number): # Run for all, test to see if it is a number, and returns a float if it is
try:
float(number)
if (float(number) == int(number)):
return int(number)
else:
return float(number)
except ValueError:
if (number.capitalize() == 'Yes'):
return True
elif (number.capitalize() == 'No'):
return False
elif (number.capitalize() == 'None'):
return None
else:
return number
self.main = {}
self.user = {}
self.wall = {}
self.unit = {}
self.object = {}
self.building = {}
for section in self.mainConfig.sections():
data = {}
for option in self.mainConfig.options(section):
data[isNumber(option)] = isNumber(self.mainConfig.get(section, option))
self.main[section] = data
for section in self.userConfig.sections():
data = {}
for option in self.userConfig.options(section):
data[isNumber(option)] = isNumber(self.userConfig.get(section, option))
self.user[section] = data
for section in self.wallConfig.sections():
data = {}
for option in self.wallConfig.options(section):
data[isNumber(option)] = isNumber(self.wallConfig.get(section, option))
self.wall[section] = wallClasses(data)
for section in self.unitConfig.sections():
data = {}
for option in self.unitConfig.options(section):
data[isNumber(option)] = isNumber(self.unitConfig.get(section, option))
self.unit[section] = unitClasses(data)
for section in self.objectConfig.sections():
data = {}
for option in self.objectConfig.options(section):
data[isNumber(option)] = isNumber(self.objectConfig.get(section, option))
self.object[section] = objectClasses(data)
for section in self.buildingConfig.sections():
data = {}
for option in self.buildingConfig.options(section):
data[isNumber(option)] = isNumber(self.buildingConfig.get(section, option))
self.building[section] = buildingClasses(data)
print self.building
print 'END OF PARSER.PY!'
class wallClasses: # Makes a class out of a dict
def __init__(self, dictionary):#, name):
self.conductor = dictionary['conductor'] # Whether it conducts (power walls?)
self.fullName = dictionary['fullname'] # The name (GUI stuff)
self.walkable = dictionary['walkable'] # Whether it can be walked on
self.water = dictionary['water'] # Whether it's water (for water untis)
self.lava = dictionary['lava'] # Whether it's lava (flying)
self.solid = dictionary['solid'] # Whwther it can be passed through
self.speed_coef = dictionary['speed_coef'] # How fast units move through it
self.drillTime = dictionary['drilltime'] # How quickly it drills (100hp per second at 1x drilling)
self.texture = dictionary['texture'] # The texture file of the wall
self.selectable = dictionary['select'] # Whether the wall can be selected
self.dynamite = dictionary['dynamite'] # Can it be dynamited?
self.reinforce = dictionary['reinforce'] # Can it be reinforced?
class unitClasses:
def __init__(self, dictionary):#, name):
self.fullName = dictionary['fullname'] # The name for the GUI
self.HP = dictionary['hp'] # The HP
self.info = dictionary['info'] # Any info about the unit
self.moveType = dictionary['movetype'] # Air, land or water
self.model = dictionary['model'] # The path to the model
self.radius = dictionary['radius'] # The bounding radius of the object (used for drilling etc.)
self.mass = dictionary['mass'] # The mass
self.startForce = dictionary['startforce'] # The force that the unit starts moving at
self.maxForce = dictionary['maxforce'] # The maximum move force
self.dig = dictionary['digmulti'] # How quickly it drills
self.reinforce = dictionary['reinforcemulti'] # How quickly it reinforces
self.shovel = dictionary['shovelmulti'] # How quickly it shovels
self.hold = dictionary['hold'] # How many items it can hold
self.modelHeight = dictionary['modelheight'] # The maximum height of the model
self.selectScale = dictionary['selectscale'] # How big the select... thing... should be
self.job = False
class objectClasses:
def __init__(self, dictionary):
self.model = dictionary['model'] # The path to the model
self.pickup = dictionary['pickup'] # How many slots (hold) it will take up
self.eValue = dictionary['evalue'] # The energy crystal value of the item
self.oValue = dictionary['ovalue'] # The ore value of the item
self.stableTime = dictionary['stabletime'] # How long before it decharges
self.charge = dictionary['charge'] # What it charges up into
self.decharge = dictionary['decharge'] # What it decharges into
class buildingClasses:
def __init__(self, dictionary):
self.HP = dictionary['hp']
self.eCrystal = dictionary['ecrystal']
self.ore = dictionary['ore']
self.dynamite = dictionary['dynamite']
self.model = dictionary['model']
self.efence = dictionary['efence']