From 8f9182baff36d33c07c5eb8df795e3cfcd5307a5 Mon Sep 17 00:00:00 2001 From: cursed22bc Date: Sun, 1 Mar 2026 11:17:23 +0200 Subject: improved tileset and load --- tilemap.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'tilemap.lua') diff --git a/tilemap.lua b/tilemap.lua index 64ca520..4780cfe 100644 --- a/tilemap.lua +++ b/tilemap.lua @@ -39,7 +39,7 @@ local function objectToEntity(obj) return entity end -function Tilemap:new(map) +function Tilemap:new(mapPath, tilesetPath) local self = setmetatable({}, Tilemap) self.entitiesTiles = {} @@ -55,7 +55,7 @@ function Tilemap:new(map) self.tilesetImage = nil self.tileQuads = {} - local mapData = loadMapData(map) + local mapData = loadMapData(mapPath) self.mapData = mapData self.tileWidth = mapData and (mapData.tilewidth or 16) or 16 @@ -63,10 +63,8 @@ function Tilemap:new(map) self.mapWidth = (mapData and mapData.width or 0) * self.tileWidth self.mapHeight = (mapData and mapData.height or 0) * self.tileHeight - if type(map) == "string" then - local basePath = map:gsub("%.lua$", ""):gsub("%.tmx$", "") - local imagePath = basePath .. ".png" - local ok, img = pcall(love.graphics.newImage, imagePath) + if type(tilesetPath) == "string" and tilesetPath ~= "" then + local ok, img = pcall(love.graphics.newImage, tilesetPath) if ok and img then self.tilesetImage = img local firstGid = (mapData.tilesets and mapData.tilesets[1] and mapData.tilesets[1].firstgid) or 1 @@ -121,8 +119,6 @@ function Tilemap:getEntitiesCameraBorders() return self.entitiesCameraBorders end --- Returns minX, maxX, minY, maxY from camera_border entities for use with Camera:setLimits. --- Returns nil, nil, nil, nil if there are no camera border entities. function Tilemap:getCameraLimits() local borders = self.entitiesCameraBorders if not borders or #borders == 0 then -- cgit v1.2.3