Create new class TileSheet
This commit is contained in:
5
mods/CORE/TileSheet/init.lua
Normal file
5
mods/CORE/TileSheet/init.lua
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
local TileSheet = Mod:new()
|
||||||
|
|
||||||
|
TileSheet.Class = TileSheet.require('TileSheet')
|
||||||
|
|
||||||
|
Api.addModToGlobalSpace(TileSheet, 'Core.TileSheet')
|
||||||
2
mods/CORE/TileSheet/mod.conf
Normal file
2
mods/CORE/TileSheet/mod.conf
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = smc__core__tilesheet
|
||||||
|
depends = smc__api__system
|
||||||
39
mods/CORE/TileSheet/src/TileSheet.lua
Normal file
39
mods/CORE/TileSheet/src/TileSheet.lua
Normal 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
|
||||||
Reference in New Issue
Block a user