Map loading fixes and improvements
This commit is contained in:
@ -63,18 +63,54 @@ for objectgroup in root.findall('objectgroup'):
|
||||
isEnt = objectgroup.attrib['name'].lower().find('ent') != -1
|
||||
|
||||
for tiledObject in objectgroup.findall('object'):
|
||||
# /8 because tiled uses pixels for objects but we use tile indexes (8x8px)
|
||||
floatX = float(tiledObject.attrib['x'])
|
||||
floatY = float(tiledObject.attrib['y'])
|
||||
|
||||
# tiled uses Px and uses bottom left of sprite
|
||||
obj = {
|
||||
"x": int(round(float(tiledObject.attrib['x']) / 8)),
|
||||
"y": int(round(float(tiledObject.attrib['y']) / 8)),
|
||||
"x": int( round(floatX / 8) ),
|
||||
"y": int( round((floatY - 8) / 8) )
|
||||
}
|
||||
|
||||
propertiesElement = tiledObject.find('properties')
|
||||
if propertiesElement is None:
|
||||
propertyElements = []
|
||||
else:
|
||||
propertyElements = propertiesElement.findall('property')
|
||||
|
||||
properties = {}
|
||||
for prop in propertyElements:
|
||||
properties[prop.attrib['name']] = prop.attrib['value']
|
||||
|
||||
if isEnt:
|
||||
if not 'type' in tiledObject.attrib:
|
||||
raise Exception('Entity missing type attribute')
|
||||
entType = tiledObject.attrib['type']
|
||||
if entType == 'player':
|
||||
obj['type'] = 1
|
||||
elif entType == 'npc':
|
||||
obj['type'] = 2
|
||||
elif entType == 'sign':
|
||||
obj['type'] = 3
|
||||
|
||||
obj["texts"] = []
|
||||
for key in properties:
|
||||
if key.find('text') != -1:
|
||||
obj["texts"].append(properties[key])
|
||||
|
||||
elif entType == 'door':
|
||||
obj['type'] = 4
|
||||
obj["door"] = {}
|
||||
|
||||
if 'x' in properties:
|
||||
obj["door"]["x"] = int(properties['x'])
|
||||
if 'y' in properties:
|
||||
obj["door"]["y"] = int(properties['y'])
|
||||
if 'direction' in properties:
|
||||
obj["door"]["direction"] = int(properties['direction'])
|
||||
if 'map' in properties:
|
||||
obj["door"]["map"] = properties['map']
|
||||
|
||||
else:
|
||||
raise Exception('Unknown entity type: ' + entType)
|
||||
|
||||
|
Reference in New Issue
Block a user