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

View File

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