<commit_before>local Tilemap = {}
Tilemap.__index = Tilemap

local Vector = require (fuccboi_path .. '/libraries/hump/vector')
local fn = require (fuccboi_path .. '/libraries/moses/moses')

function Tilemap.new(x, y, tile_width, tile_height, tilesets, tile_grid, settings)
    local self = {}
    local settings = settings or {}

    -- Initializes this tilemap to an area so it can be update/drawn if that area is active
    self.area = settings.area or fg.world.areas['Default']

    -- Padding (horizontal and vertical) in pixels between each tile
    self.padding = settings.padding or 0

    -- Top left position of the map
    self.x = x
    self.y = y

    -- Tile width and height, needs to match the size of each tile in the tileset tilesets
    self.tile_width = tile_width
    self.tile_height = tile_height

    -- A single or multiple tilesets
    if type(tilesets) == 'userdata' then self.tilesets = {tilesets}
    else self.tilesets = tilesets end

    -- 2D array containing tile data for the map, each element = a tile number
    self.tile_grid = tile_grid 

    -- If input data is from a Tiled map...
    if type(tile_width) == 'string' then
        local tiled_map_path = tile_width 
        self.tiled_data = require(tiled_map_path)

        -- Set tile size
        self.tile_width = self.tiled_data.tilewidth
        self.tile_height = self.tiled_data.tileheight

        -- Set tileset images
        self.tilesets = {}
        for _, tileset in ipairs(self.tiled_data.tilesets) do
            -- Image path starts with .., meaning have to substitute .. for 
            -- whatever is the first directory before a / in tiled_map_path
            if tileset.image:sub(1, 2) == '..' then
                table.insert(self.tilesets, love.graphics.newImage(tiled_map_path:sub(1, 
                             tiled_map_path:find('/')) .. tileset.image:sub(4, -1)))
            -- Already the full path, just use that as it is
            else table.insert(self.tilesets, love.graphics.newImage(tileset.image)) end
        end

        -- Set tile grid
        self.tile_grid = {}
        for i = 1, self.tiled_data.height do
            self.tile_grid[i] = {}
            for j = 1, self.tiled_data.width do
                self.tile_grid[i][j] = 0
            end
        end
        for _, layer in ipairs(self.tiled_data.layers) do
            if layer.type == 'tilelayer' then
                local width, height = layer.width, layer.height
                for i = 1, height do
                    for j = 1, width do
                        if layer.data[(i-1)*width + j] ~= 0 then
                            self.tile_grid[i][j] = layer.data[(i-1)*width + j]<commit_msg>Fix collision layer drawing (when it shouldn't) for Tiled maps<commit_after>local Tilemap = {}
Tilemap.__index = Tilemap

local Vector = require (fuccboi_path .. '/libraries/hump/vector')
local fn = require (fuccboi_path .. '/libraries/moses/moses')

function Tilemap.new(x, y, tile_width, tile_height, tilesets, tile_grid, settings)
    local self = {}
    local settings = settings or {}

    -- Initializes this tilemap to an area so it can be update/drawn if that area is active
    self.area = settings.area or fg.world.areas['Default']

    -- Padding (horizontal and vertical) in pixels between each tile
    self.padding = settings.padding or 0

    -- Top left position of the map
    self.x = x
    self.y = y

    -- Tile width and height, needs to match the size of each tile in the tileset tilesets
    self.tile_width = tile_width
    self.tile_height = tile_height

    -- A single or multiple tilesets
    if type(tilesets) == 'userdata' then self.tilesets = {tilesets}
    else self.tilesets = tilesets end

    -- 2D array containing tile data for the map, each element = a tile number
    self.tile_grid = tile_grid 

    -- If input data is from a Tiled map...
    if type(tile_width) == 'string' then
        local tiled_map_path = tile_width 
        self.tiled_data = require(tiled_map_path)

        -- Set tile size
        self.tile_width = self.tiled_data.tilewidth
        self.tile_height = self.tiled_data.tileheight

        -- Set tileset images
        self.tilesets = {}
        for _, tileset in ipairs(self.tiled_data.tilesets) do
            -- Image path starts with .., meaning have to substitute .. for 
            -- whatever is the first directory before a / in tiled_map_path
            if tileset.image:sub(1, 2) == '..' then
                table.insert(self.tilesets, love.graphics.newImage(tiled_map_path:sub(1, 
                             tiled_map_path:find('/')) .. tileset.image:sub(4, -1)))
            -- Already the full path, just use that as it is
            else table.insert(self.tilesets, love.graphics.newImage(tileset.image)) end
        end

        -- Set tile grid
        self.tile_grid = {}
        for i = 1, self.tiled_data.height do
            self.tile_grid[i] = {}
            for j = 1, self.tiled_data.width do
                self.tile_grid[i][j] = 0
            end
        end
        for _, layer in ipairs(self.tiled_data.layers) do
            if layer.type == 'tilelayer' and layer.properties.collision ~= "true" then
                local width, height = layer.width, layer.height
                for i = 1, height do
                    for j = 1, width do
                        if layer.data[(i-1)*width + j] ~= 0 then
                            self.tile_grid[i][j] = layer.data[(i-1)*width + j]
{'fraction_non_alphanumeric': 0.0971563981042654, 'fraction_numerical': 0.005468465184104995, 'mean_word_length': 2.0483333333333333, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3852992', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1628, 'n_words': 505}