import cocos
import pyglet

class Minimap(cocos.tiles.RectMapLayer):

    def __init__(self, map_size):
        # Create tileset

        self.you_tile = pyglet.image.load('img/minimap-you.png')
        self.nok_tile = pyglet.image.load('img/minimap-nok.png')
        self.ok_tile = pyglet.image.load('img/minimap-ok.png')
        self.unknown_tile = pyglet.image.load('img/minimap-unknown.png')

        self.Tileset = cocos.tiles.TileSet(0, None)
        self.Tileset.add( {} , self.you_tile, 'minimap-you')
        self.Tileset.add( {} , self.nok_tile, 'minimap-nok')
        self.Tileset.add( {} , self.ok_tile, 'minimap-ok')
        self.Tileset.add( {} , self.unknown_tile, 'minimap-unknown')
        
        self.map_size = map_size

        self.cells = []
        for i in range(self.map_size[0]):
            col = []
            for j in range(self.map_size[1]):
                col.append('minimap-unknown')
            self.cells.append(col)

        for i in range(len(self.cells)):
            for j in range(len(self.cells[0])):
                self.cells[i][j] = cocos.tiles.RectCell(i,j,1,1,{},self.Tileset[self.cells[i][j]])


        super(Minimap, self).__init__('minimap', 1, 1, self.cells)

    def update_tile(self, i, j, value):
        self.cells[i][j] = cocos.tiles.RectCell(i,j,1,1,{},self.Tileset[value])

    def refresh(self):
        super(Minimap, self).__init__('minimap', 1, 1, self.cells)
        self.set_view(0,0,100,100)
