#
# TmxData
#
# Wrapper of a TiledMap
# generated by pytmx.util_pygame.load_pygame('MapName.tmx')
#
# All the data are parsed to give more elemental functionalities
#
# layer  : All layer in order (bottom to top)
# gidMap : The gidMap between gid and real position in Tilesets
#
# For info only, useful function of TiledMap :
#       get_tile_gid(i,j,layer(number))
#       get_layer_by_name(name)
#

import pytmx
import pprint as pp
import re


class TmxData:
    def __init__(self, rawTmxData):

        self.rawTmxData = rawTmxData

        self.tileWidth = self.rawTmxData.tileWidth
        self.tileHeight = self.rawTmxData.tileHeight

        self.extractLayerName()
        self.gidMap = self.rawTmxData.tiledgidmap


        pp.pprint(self.layer)


    # Give the type of the designed tile at position (i,j)
    def get_tileType(self,i,j,layerNumber):
        return self.rawTmxData.get_tile_gid(i,j,layerNumber)

                    # upRightTileGid = map.tmxData.get_tile_gid((sprite.collisionMask.rect.right + i*self.tileWidth)/self.tileWidth, sprite.collisionMask.rect.top/self.tileHeight, COLLISION_LAYER)


    # Private function for constructor
    def extractLayerName(self):

        self.layer =[]
        dim = len(self.rawTmxData.layers)
        for k in range(0,dim-1):
            layer = pp.pformat(self.rawTmxData.layers[k])
            layer = re.findall(r'"([^"]*)"', layer)[0]
            self.layer.append(layer)

