Exemple #1
0
    def add_tile(self, tile, no_flip=False, dedup=True):
        """Adds a tile into this tileset if the tileset does not already contain it.

        :param tile: the tile to add, as a two-dimensional list
        :param no_flip: don't store any flips of this tile
        :return: a tuple containing the tile's id in this tileset, whether the tile is stored as vertically flipped,
        and whether the tile is stored as horizontally flipped"""

        tile_hash = hash_tile(tile)

        if dedup:
            try:
                tile_id, vflip, hflip = self._used_tiles[tile_hash]
                return tile_id, vflip, hflip
            except KeyError:
                pass

        # The tile does not already exist in this tileset, so add it
        if self._num_tiles_used >= self.num_tiles_maximum:
            # Error, not enough room for a new tile
            return 0, False, False

        tile_copy = deepcopy(tile)
        tile_id = self._num_tiles_used
        self.tiles.append(tile_copy)
        self._num_tiles_used += 1

        if no_flip or not dedup:
            self._used_tiles[tile_hash] = tile_id, False, False
            return tile_id, False, False

        # The tile will be stored as horizontally flipped
        self._used_tiles[tile_hash] = tile_id, False, True

        tile_copy.reverse()
        # Verically flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, True, True

        for row in tile_copy:
            row.reverse()
        # Vertically and horizontally flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, True, False

        tile_copy.reverse()
        # Horizontally flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, False, False

        return tile_id, False, True
Exemple #2
0
    def add_tile(self, tile, no_flip=False):
        """Adds a tile into this tileset if the tileset does not already contain it.

        :param tile: the tile to add, as a two-dimensional list
        :param no_flip: don't store any flips of this tile
        :return: a tuple containing the tile's id in this tileset, whether the tile is stored as vertically flipped,
        and whether the tile is stored as horizontally flipped"""

        tile_hash = hash_tile(tile)
        try:
            tile_id, vflip, hflip = self._used_tiles[tile_hash]
            return tile_id, vflip, hflip
        except KeyError:
            pass

        # The tile does not already exist in this tileset, so add it
        if self._num_tiles_used >= self.num_tiles_maximum:
            # Error, not enough room for a new tile
            return 0, False, False

        tile_copy = deepcopy(tile)
        tile_id = self._num_tiles_used
        self.tiles.append(tile_copy)
        self._num_tiles_used += 1

        if no_flip:
            self._used_tiles[tile_hash] = tile_id, False, False
            return tile_id, False, False

        # The tile will be stored as horizontally flipped
        self._used_tiles[tile_hash] = tile_id, False, True

        tile_copy.reverse()
        # Verically flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, True, True

        for row in tile_copy:
            row.reverse()
        # Vertically and horizontally flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, True, False

        tile_copy.reverse()
        # Horizontally flipped tile
        self._used_tiles[hash_tile(tile_copy)] = tile_id, False, False

        return tile_id, False, True
Exemple #3
0
 def hash(self):
     return hash_tile(self.sprite)
Exemple #4
0
 def hash(self):
     return hash_tile(self.data)
Exemple #5
0
 def hash(self):
     return hash_tile(self.sprite)
Exemple #6
0
 def hash(self):
     return hash_tile(self.data)