Rename tileMap to spriteAtlas and update references accordingly
This commit is contained in:
parent
2fc1a92ad1
commit
aec916cd14
@ -5,7 +5,7 @@ local function new(template, size)
|
|||||||
local map = {}
|
local map = {}
|
||||||
-- паттерн-матчинг для самых маленьких
|
-- паттерн-матчинг для самых маленьких
|
||||||
if template == "flower_plains" then
|
if template == "flower_plains" then
|
||||||
local tileMap = require("lib.level.tileMap").load(Tree.assets.files.tiles.grass)
|
local tileMap = require("lib.utils.sprite_atlas").load(Tree.assets.files.tiles.grass)
|
||||||
for y = 0, size.y - 1 do
|
for y = 0, size.y - 1 do
|
||||||
for x = 0, size.x - 1 do
|
for x = 0, size.x - 1 do
|
||||||
local type = tileMap.map["flower_grass"]
|
local type = tileMap.map["flower_grass"]
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
--- @class TileMap
|
--- @class SpriteAtlas
|
||||||
--- @field tileSize integer
|
--- @field tileSize integer
|
||||||
--- @field atlas love.Image
|
--- @field atlas love.Image
|
||||||
--- @field map table<string, love.Quad>
|
--- @field map table<string, love.Quad>
|
||||||
local tileMap = {}
|
local spriteAtlas = {}
|
||||||
tileMap.__index = tileMap
|
spriteAtlas.__index = spriteAtlas
|
||||||
|
|
||||||
--- @param path table
|
--- @param path table
|
||||||
local function load(path)
|
local function load(path)
|
||||||
@ -12,7 +12,7 @@ local function load(path)
|
|||||||
--- @type table
|
--- @type table
|
||||||
local manifest = path.manifest
|
local manifest = path.manifest
|
||||||
|
|
||||||
local _tileMap = {
|
local _spriteAtlas = {
|
||||||
tileSize = manifest.tileSize,
|
tileSize = manifest.tileSize,
|
||||||
atlas = atlas,
|
atlas = atlas,
|
||||||
map = {}
|
map = {}
|
||||||
@ -31,17 +31,17 @@ local function load(path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local cnt = 0
|
local cnt = 0
|
||||||
for y = 0, atlas:getHeight() - 1, _tileMap.tileSize do
|
for y = 0, atlas:getHeight() - 1, _spriteAtlas.tileSize do
|
||||||
for x = 0, atlas:getWidth() - 1, _tileMap.tileSize do
|
for x = 0, atlas:getWidth() - 1, _spriteAtlas.tileSize do
|
||||||
if layout[cnt] then
|
if layout[cnt] then
|
||||||
for _, group in ipairs(layout[cnt]) do
|
for _, group in ipairs(layout[cnt]) do
|
||||||
print(x, y, _tileMap.tileSize, atlas, false)
|
print(x, y, _spriteAtlas.tileSize, atlas, false)
|
||||||
local quad = love.graphics.newQuad(x, y, _tileMap.tileSize, _tileMap.tileSize, atlas)
|
local quad = love.graphics.newQuad(x, y, _spriteAtlas.tileSize, _spriteAtlas.tileSize, atlas)
|
||||||
|
|
||||||
if _tileMap.map[group] then
|
if _spriteAtlas.map[group] then
|
||||||
table.insert(_tileMap.map[group], quad)
|
table.insert(_spriteAtlas.map[group], quad)
|
||||||
else
|
else
|
||||||
_tileMap.map[group] = { quad }
|
_spriteAtlas.map[group] = { quad }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -49,7 +49,7 @@ local function load(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(_tileMap, tileMap)
|
return setmetatable(_spriteAtlas, spriteAtlas)
|
||||||
end
|
end
|
||||||
|
|
||||||
return { load = load }
|
return { load = load }
|
||||||
Loading…
x
Reference in New Issue
Block a user