optimized tiledata

This commit is contained in:
lustlion 2022-01-29 10:46:49 +01:00
parent a1bf842cef
commit 3e8a907aa2
2 changed files with 162 additions and 168 deletions

View File

@ -114,10 +114,11 @@ end
function InstanceTile(i,j,id) function InstanceTile(i,j,id)
LevelTiles[i][j] = {} LevelTiles[i][j] = {}
local tile = LevelTiles[i][j] local tile = LevelTiles[i][j]
tile.id = id
for _, Properties in pairs(TileData) do tile.id = id
if Properties.id == tile.id then local Properties = TileData[tile.id]
if Properties ~= nil then
if type(Properties.overlay) == "table" then if type(Properties.overlay) == "table" then
tile.display_overlay = Properties.overlay[math.random(#Properties.overlay)] tile.display_overlay = Properties.overlay[math.random(#Properties.overlay)]
else else
@ -131,29 +132,22 @@ function InstanceTile(i,j,id)
end end
end end
end end
end
function TileGetType(tile) function TileGetType(tile)
for _, Properties in pairs(TileData) do if TileData[tile.id] ~= nil then
if Properties.id == tile.id then return TileData[tile.id].type
return Properties.type
end
end end
end end
function TileGetDepth(tile) function TileGetDepth(tile)
for _, Properties in pairs(TileData) do if TileData[tile.id] ~= nil then
if Properties.id == tile.id then return TileData[tile.id].depth
return Properties.depth
end
end end
end end
function TileGetLight(tile) function TileGetLight(tile)
for _, Properties in pairs(TileData) do if TileData[tile.id] ~= nil then
if Properties.id == tile.id then return TileData[tile.id].light
return Properties.light
end
end end
end end
@ -468,6 +462,7 @@ end
function AnimateTiles() function AnimateTiles()
for _, Properties in pairs(TileData) do for _, Properties in pairs(TileData) do
if Properties ~= nil then
if Properties.animation ~= nil then if Properties.animation ~= nil then
-- calculate subimage -- calculate subimage
Properties.current_subimage = Properties.current_subimage + current_dt Properties.current_subimage = Properties.current_subimage + current_dt
@ -483,11 +478,12 @@ function AnimateTiles()
end end
end end
end end
end
function DrawTile(tile,x,y,depth) function DrawTile(tile,x,y,depth)
for _, Properties in pairs(TileData) do local Properties = TileData[tile.id]
if tile.id == Properties.id then
if Properties ~= nil then
if Properties.animation ~= nil then if Properties.animation ~= nil then
if Properties.imgs[Properties.current_image] ~= nil if Properties.imgs[Properties.current_image] ~= nil
and Properties.depth == depth and Properties.depth == depth
@ -499,7 +495,8 @@ function DrawTile(tile,x,y,depth)
0, 0,
tileProperties.scale, tileProperties.scale,
tileProperties.scale tileProperties.scale
) end )
end
elseif Properties.depth == depth then elseif Properties.depth == depth then
if Properties.force ~= nil then if Properties.force ~= nil then
if Properties.force ~= 0 then if Properties.force ~= 0 then
@ -516,7 +513,7 @@ function DrawTile(tile,x,y,depth)
else else
love.graphics.draw( love.graphics.draw(
LevelData.tileset, LevelData.tileset,
TileIndex[Properties.id], TileIndex[tile.id],
x, x,
y, y,
0, 0,
@ -529,8 +526,7 @@ function DrawTile(tile,x,y,depth)
if Properties.overlay ~= nil then if Properties.overlay ~= nil then
if Properties.overlay_depth == depth or Properties.overlay_depth == nil and Properties.depth == depth then if Properties.overlay_depth == depth or Properties.overlay_depth == nil and Properties.depth == depth then
if Properties.overlay_animated then if Properties.overlay_animated then
for _, overlay_properties in pairs(TileData) do local overlay_properties = TileData[Properties.overlay]
if overlay_properties.id == Properties.overlay then
love.graphics.draw( love.graphics.draw(
overlay_properties.tileset, overlay_properties.tileset,
overlay_properties.imgs[overlay_properties.current_image], overlay_properties.imgs[overlay_properties.current_image],
@ -540,8 +536,6 @@ function DrawTile(tile,x,y,depth)
tileProperties.scale, tileProperties.scale,
tileProperties.scale tileProperties.scale
) )
end
end
else else
love.graphics.draw( love.graphics.draw(
LevelData.tileset, LevelData.tileset,
@ -562,4 +556,3 @@ function DrawTile(tile,x,y,depth)
]] ]]
end end
end end
end

View File

@ -1,80 +1,81 @@
return { local properties = {}
{
id = 1, properties[1] = {
type = "whole", type = "whole",
depth = "foreground" depth = "foreground"
}, }
{
id = 2, properties[2] = {
type = "emtpy", type = "emtpy",
depth = "foreground" depth = "foreground"
}, }
{
id = 5, properties[5] = {
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 6, properties[6] = {
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 7, properties[7] = {
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 13, properties[13] = {
type = "whole", type = "whole",
depth = "foreground" depth = "foreground"
}, }
{
id = 25, properties[25] = {
overlay = {17,19,21,23}, overlay = {17,19,21,23},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 26, properties[26] = {
overlay = {18,20,22,24}, overlay = {18,20,22,24},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 37, properties[37] = {
overlay = {29,31,33,35,42,44,46,48}, overlay = {29,31,33,35,41,43,45,47},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 38, properties[38] = {
overlay = {30,32,34,36,41,43,45,47}, overlay = {30,32,34,36,42,44,46,48},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 49, properties[49] = {
overlay = {53,55,57,59}, overlay = {53,55,57,59},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 50, properties[50] = {
overlay = {54,56,58,60}, overlay = {54,56,58,60},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
}, }
{
id = 61, properties[61] = {
overlay = {1},
type = "emtpy",
depth = "background"
},
{
id = 62,
overlay = {1}, overlay = {1},
type = "emtpy", type = "emtpy",
depth = "background" depth = "background"
} }
properties[62] = {
overlay = {1},
type = "emtpy",
depth = "background"
} }
return properties