tile struct initial
This commit is contained in:
parent
7d4c856832
commit
9a2398df8d
@ -1,199 +0,0 @@
|
||||
return {
|
||||
flower_grass = {
|
||||
flower_grass1 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c8c90]],
|
||||
flower_grass2 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9c8850]],
|
||||
flower_grass3 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9c7240]],
|
||||
flower_grass4 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c7358]],
|
||||
flower_grass5 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 128,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c7438]],
|
||||
flower_grass6 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 128,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9bb9e8]],
|
||||
flower_grass7 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 128,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9bba60]],
|
||||
flower_grass8 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 128,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9bbb40]],
|
||||
flower_grass9 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 160,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c9088]],
|
||||
flower_grass10 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 160,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9c92c0]],
|
||||
flower_grass11 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 160,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9bb8f0]],
|
||||
flower_grass12 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 160,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c5500]],
|
||||
flower_grass13 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 192,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c55e0]],
|
||||
flower_grass14 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 192,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9c56c0]],
|
||||
flower_grass15 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 192,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9c57a0]],
|
||||
flower_grass16 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 192,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c7f80]]
|
||||
} --[[table: 0x7f4aca9c8be0]],
|
||||
grass = {
|
||||
grass1 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 0,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9ca818]],
|
||||
grass2 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 0,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9caa18]],
|
||||
grass3 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 0,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9c7a20]],
|
||||
grass4 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 0,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c7da8]],
|
||||
grass5 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 32,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c7780]],
|
||||
grass6 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 32,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9c5060]],
|
||||
grass7 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 32,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9cf078]],
|
||||
grass8 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 32,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c96e8]],
|
||||
grass9 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 64,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c7ad8]],
|
||||
grass10 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 64,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9c5318]],
|
||||
grass11 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 64,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9ca900]],
|
||||
grass12 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 64,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9cab58]],
|
||||
grass13 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 0
|
||||
} --[[table: 0x7f4aca9c5e60]],
|
||||
grass14 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 32
|
||||
} --[[table: 0x7f4aca9caba0]],
|
||||
grass15 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 64
|
||||
} --[[table: 0x7f4aca9c6e90]],
|
||||
grass16 = {
|
||||
h = 32,
|
||||
w = 32,
|
||||
x = 96,
|
||||
y = 96
|
||||
} --[[table: 0x7f4aca9c8b30]]
|
||||
} --[[table: 0x7f4aca9c5240]],
|
||||
tileSize = 32
|
||||
} --[[table: 0x7f4aca9c93e0]]
|
||||
@ -5,7 +5,7 @@ local function new(template, size)
|
||||
local map = {}
|
||||
-- паттерн-матчинг для самых маленьких
|
||||
if template == "flower_plains" then
|
||||
local tileMap = require("lib.level.tile").load(Tree.assets.files.tiles.grass)
|
||||
local tileMap = require("lib.level.tileMap").load(Tree.assets.files.tiles.grass)
|
||||
map.atlas = tileMap.atlas
|
||||
for y = 0, size.y - 1 do
|
||||
map[y] = {}
|
||||
|
||||
@ -1,51 +1,30 @@
|
||||
--- @class TileMap
|
||||
--- @field tileSize integer
|
||||
--- @field atlas love.Image
|
||||
local tileMap = {}
|
||||
tileMap.__index = tileMap
|
||||
--- @class Tile
|
||||
--- @field isClip boolean
|
||||
--- @field quad love.Quad
|
||||
local tile = {}
|
||||
tile.__index = tile
|
||||
|
||||
--- @param path table
|
||||
local function load(path)
|
||||
--- @type love.Image
|
||||
local atlas = path.atlas
|
||||
--- @type table
|
||||
local manifest = path.manifest
|
||||
|
||||
--- @type TileMap
|
||||
local tiles = {
|
||||
tileSize = manifest.tileSize,
|
||||
atlas = atlas
|
||||
}
|
||||
manifest.tileSize = nil
|
||||
|
||||
local layout = {}
|
||||
for group, ids in pairs(manifest) do
|
||||
for _, id in ipairs(ids) do
|
||||
if layout[id] then
|
||||
table.insert(layout[id], group)
|
||||
else
|
||||
layout[id] = { group }
|
||||
end
|
||||
end
|
||||
--- TODO: сделать как love.graphics.draw несколько сигнатур у функции
|
||||
--- @param x number
|
||||
--- @param y number
|
||||
--- @param tileSize number
|
||||
--- @param atlas love.Image
|
||||
--- @param isClip boolean
|
||||
local function new(x, y, tileSize, atlas, isClip)
|
||||
local quad = love.graphics.newQuad(x, y, tileSize, tileSize, atlas)
|
||||
return setmetatable({
|
||||
isClip = isClip,
|
||||
quad = quad
|
||||
})
|
||||
end
|
||||
|
||||
local cnt = 0
|
||||
for y = 0, atlas:getHeight() - 1, tiles.tileSize do
|
||||
for x = 0, atlas:getWidth() - 1, tiles.tileSize do
|
||||
if layout[cnt] then
|
||||
for _, group in ipairs(layout[cnt]) do
|
||||
if tiles[group] then
|
||||
table.insert(tiles[group], love.graphics.newQuad(x, y, tiles.tileSize, tiles.tileSize, atlas))
|
||||
else
|
||||
tiles[group] = { love.graphics.newQuad(x, y, tiles.tileSize, tiles.tileSize, atlas) }
|
||||
end
|
||||
end
|
||||
end
|
||||
cnt = cnt + 1
|
||||
end
|
||||
--- @param quad love.Quad
|
||||
--- @param isClip boolean
|
||||
local function fromQuad(quad, isClip)
|
||||
return setmetatable({
|
||||
isClip = isClip,
|
||||
quad = quad
|
||||
})
|
||||
end
|
||||
|
||||
return setmetatable(tiles, tileMap)
|
||||
end
|
||||
|
||||
return { load = load }
|
||||
return { new = new }
|
||||
|
||||
52
lib/level/tileMap.lua
Normal file
52
lib/level/tileMap.lua
Normal file
@ -0,0 +1,52 @@
|
||||
--- @class TileMap
|
||||
--- @field tileSize integer
|
||||
--- @field atlas love.Image
|
||||
--- @field map Tile[]
|
||||
local tileMap = {}
|
||||
tileMap.__index = tileMap
|
||||
|
||||
--- @param path table
|
||||
local function load(path)
|
||||
--- @type love.Image
|
||||
local atlas = path.atlas
|
||||
--- @type table
|
||||
local manifest = path.manifest
|
||||
|
||||
local tiles = {
|
||||
tileSize = manifest.tileSize,
|
||||
atlas = atlas
|
||||
}
|
||||
manifest.tileSize = nil
|
||||
|
||||
local layout = {}
|
||||
for group, ids in pairs(manifest) do
|
||||
for _, id in ipairs(ids) do
|
||||
if layout[id] then
|
||||
table.insert(layout[id], group)
|
||||
else
|
||||
layout[id] = { group }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local cnt = 0
|
||||
for y = 0, atlas:getHeight() - 1, tiles.tileSize do
|
||||
for x = 0, atlas:getWidth() - 1, tiles.tileSize do
|
||||
if layout[cnt] then
|
||||
for _, group in ipairs(layout[cnt]) do
|
||||
local tile = require('lib.level.tile').new(x, y, tiles.tileSize, atlas, false)
|
||||
if tiles.map[group] then
|
||||
table.insert(tiles.map[group], tile)
|
||||
else
|
||||
tiles.map[group] = { tile }
|
||||
end
|
||||
end
|
||||
end
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
|
||||
return setmetatable(tiles, tileMap)
|
||||
end
|
||||
|
||||
return { load = load }
|
||||
Loading…
x
Reference in New Issue
Block a user