"""
example how to proccess a tmx map to support map[layer].find_cell(**conditions)

cocos .tmx and .xml maps are not equal citizens, thus the need of extra steps.

For this example the road-map.tmx in the cocos test directory was loaded in tmx
editor, a tile was selected in the tiles panel and a property 'player_start'
with value 1 was set;
Then the same tile was put in a cell of the map, and the map saved as
'road-map-modified.tmx'

This script should run from the test directory, the same as the map and other
resources live. 

Note that setting the player_start value to True will not work as expected:
the property will appear in python with value 'True' ( a string )  

"""

import pyglet
from pyglet.window import key

pyglet.resource.path.append(pyglet.resource.get_script_home())
pyglet.resource.reindex()

import cocos
from cocos import tiles, actions, layer

from cocos.director import director
director.init(width=800, height=600, do_not_scale=True, resizable=True)

scroller = layer.ScrollingManager()
map_ = tiles.load('road-map-modified.tmx')

def copy_tile_properties_to_cell(map_):
    """for each cell in each layer tile properties are copied to cell properties
    """
    for name in map_.contents:
        obj = map_[name]
        if isinstance(obj, cocos.tiles.RectMapLayer):
            for col in obj.cells:
                for cell in col:
                    cell.properties.update(cell.tile.properties)
                    #print cell.properties

copy_tile_properties_to_cell(map_)
tilemap = map_['map0']
start = tilemap.find_cells(player_start = True)[0]
print start


            
