Create new class TileSheet

This commit is contained in:
Van
2025-09-24 18:25:26 +00:00
parent b63f905174
commit 24b49cfd2a
3 changed files with 46 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
local TileSheet = Mod:new()
TileSheet.Class = TileSheet.require('TileSheet')
Api.addModToGlobalSpace(TileSheet, 'Core.TileSheet')

View File

@@ -0,0 +1,2 @@
name = smc__core__tilesheet
depends = smc__api__system

View File

@@ -0,0 +1,39 @@
---@class TileSheet
---@field image string Name of texture
---@field width number Number of tiles in the table horizontally
---@field height number Number of tiles in the table vertically
local TileSheet = {}
---@param image string Name of texture
---@param width number Number of tiles in the table horizontally
---@param height number Number of tiles in the table vertically
---@return TileSheet
function TileSheet:new(image, width, height)
local instance = setmetatable({
image = image,
width = width,
height = height,
}, {__index = self})
return instance
end
---Returns the texture from the tilesheet located at coordinates x, y
---@param x number
---@param y number
---@return string
function TileSheet:getTextureName(x, y)
local textureName = self.image .. "^[sheet:".. self.width .. "x" .. self.height .. ":" .. x .. "," .. y
return textureName
end
---Aleas for `TileSheet:getTextureName`.
---@param x number
---@param y number
---@return string
function TileSheet:t(x, y)
return self:getTextureName(x, y)
end
return TileSheet