somewhat kinda got things working again
This commit is contained in:
parent
e8cef497d4
commit
fa4b2c86b5
@ -1,7 +1,51 @@
|
|||||||
-- pieces of levels
|
-- pieces of levels
|
||||||
|
|
||||||
Chunk = {}
|
Chunk = {all = {}}
|
||||||
Chunk.__index = Chunk
|
Chunk.__index = Chunk
|
||||||
|
|
||||||
function Chunk:new(file, rect)
|
-- CLASS METHODS
|
||||||
|
|
||||||
|
-- box == nil for global chunks
|
||||||
|
function Chunk:new(filename, box)
|
||||||
|
local o = { filename = filename, box = box }
|
||||||
|
setmetatable(o, self)
|
||||||
|
self.all[o] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Chunk:getExportList()
|
||||||
|
local r = {}
|
||||||
|
for chunk in pairs(self.all) do
|
||||||
|
table.insert(r, chunk)
|
||||||
|
end
|
||||||
|
return r
|
||||||
|
end
|
||||||
|
|
||||||
|
-- INSTANCE METHODS
|
||||||
|
|
||||||
|
function Chunk:containsPoint(pt)
|
||||||
|
return self.box == nil or self.box:containsPoint(pt)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Chunk:load()
|
||||||
|
if self.loaded then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
logPrint("loading chunk "..self.filename)
|
||||||
|
self.data = dofile(level_current.."/chunks/"..self.filename)
|
||||||
|
self.loaded = { rooms = {}, collisions = {} }
|
||||||
|
LevelTiles = self.data.tiles
|
||||||
|
indexLevelTiles()
|
||||||
|
optimizeTileObjects(self.loaded.collisions)
|
||||||
|
|
||||||
|
for _, v in ipairs(self.data.rooms or {}) do
|
||||||
|
local room = Collision:new(v[1],v[2],v[3],v[4])
|
||||||
|
table.insert(self.data.rooms, room)
|
||||||
|
table.insert(LoadedObjects.Rooms, room)
|
||||||
|
end
|
||||||
|
logPrint("loaded chunk with "..#self.loaded.collisions.." collisions")
|
||||||
|
end
|
||||||
|
|
||||||
|
function Chunk:save(chunkdir)
|
||||||
|
love.filesystem.write(chunkdir.."/chunks/"..self.filename, "return "..serialize_lua_data(self.data))
|
||||||
|
end
|
||||||
|
|
||||||
|
@ -17,22 +17,30 @@ function exportLevel(levelname, dirname)
|
|||||||
exportTable.name = levelname
|
exportTable.name = levelname
|
||||||
exportTable.tileset = "library"
|
exportTable.tileset = "library"
|
||||||
exportTable.properties = LevelData.properties
|
exportTable.properties = LevelData.properties
|
||||||
exportTable.tiles = LevelTiles
|
--exportTable.tiles = LevelTiles
|
||||||
logPrint("- objects")
|
--logPrint("- objects")
|
||||||
exportTable.objects = { spawns = {}, rooms = {} }
|
--exportTable.objects = { spawns = {}, rooms = {} }
|
||||||
logPrint(" - spawns")
|
--logPrint(" - spawns")
|
||||||
for i, v in ipairs(LoadedObjects.Spawns) do
|
--for i, v in ipairs(LoadedObjects.Spawns) do
|
||||||
--exportTable.objects.spawns = {v.archetype.name,{},v.args}
|
--exportTable.objects.spawns = {v.archetype.name,{},v.args}
|
||||||
end
|
--end
|
||||||
|
|
||||||
logPrint(" - rooms")
|
--logPrint(" - rooms")
|
||||||
|
|
||||||
for i, room in ipairs(LoadedObjects.Rooms) do
|
--for i, room in ipairs(LoadedObjects.Rooms) do
|
||||||
table.insert(exportTable.objects.rooms,{room:asRect():getCoords()})
|
--- table.insert(exportTable.objects.rooms,{room:asRect():getCoords()})
|
||||||
end
|
--end
|
||||||
|
exportTable.chunks = Chunk:getExportList()
|
||||||
logPrint("Writing to file...")
|
logPrint("Writing to file...")
|
||||||
local ok, err = love.filesystem.write(dirname.."/level.lua", "return "..serialize_lua_value(exportTable))
|
local ok, err = love.filesystem.write(dirname.."/level.lua", "return "..serialize_lua_value(exportTable))
|
||||||
|
|
||||||
if ok then
|
if ok then
|
||||||
|
logPrint("Saving chunks...")
|
||||||
|
local chunkdir = dirname.."/chunks"
|
||||||
|
love.filesystem.createDirectory(chunkdir)
|
||||||
|
for chunk in Chunk.all do
|
||||||
|
chunk:save(chunkdir)
|
||||||
|
end
|
||||||
logPrint("Exporting complete.")
|
logPrint("Exporting complete.")
|
||||||
else
|
else
|
||||||
logPrint("Exporting failed: "..err)
|
logPrint("Exporting failed: "..err)
|
||||||
|
@ -1,12 +1,25 @@
|
|||||||
function loadLevelTiles()
|
function loadLevelTiles()
|
||||||
math.randomseed(3)
|
math.randomseed(3)
|
||||||
LevelData = dofile( love.filesystem.getSaveDirectory().."/export/unnamed_level/level.lua")
|
level_current = love.filesystem.getSaveDirectory().."/export/test1"
|
||||||
|
LevelData = dofile(level_current.."/level.lua")
|
||||||
|
LoadedObjects.Collisions = {}
|
||||||
|
LoadedObjects.Platforms = {}
|
||||||
|
LoadedObjects.Ladders = {}
|
||||||
|
LoadedObjects.Hazards = {}
|
||||||
if type(LevelData.tileset) == "string" then
|
if type(LevelData.tileset) == "string" then
|
||||||
LevelData.tileset_name = LevelData.tileset
|
LevelData.tileset_name = LevelData.tileset
|
||||||
end
|
end
|
||||||
LevelData.tileset = tileset[LevelData.tileset_name]
|
LevelData.tileset = tileset[LevelData.tileset_name]
|
||||||
--dofile("data/levels/"..level_current)
|
|
||||||
|
|
||||||
|
getLevelTileData()
|
||||||
|
|
||||||
|
for _, v in ipairs(LevelData.chunks) do
|
||||||
|
Chunk:new(v[1], v[2])
|
||||||
|
end
|
||||||
|
local global_chunk = next(Chunk.all)
|
||||||
|
global_chunk:load()
|
||||||
|
LoadedObjects.Collisions = global_chunk.loaded.collisions
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
on level format:
|
on level format:
|
||||||
|
|
||||||
@ -17,11 +30,11 @@ function loadLevelTiles()
|
|||||||
overlay_depth = foreground/background overlay depth
|
overlay_depth = foreground/background overlay depth
|
||||||
type = collision type
|
type = collision type
|
||||||
]]
|
]]
|
||||||
getLevelTileData()
|
|
||||||
LevelTiles = LevelData.tiles
|
LevelTiles = LevelData.tiles
|
||||||
updateLevelDimensions()
|
updateLevelDimensions()
|
||||||
indexLevelTiles()
|
--
|
||||||
createTileObjects()
|
--createTileObjects()
|
||||||
createRoomObjects()
|
createRoomObjects()
|
||||||
getSpawns()
|
getSpawns()
|
||||||
end
|
end
|
||||||
@ -263,7 +276,7 @@ function drawGridDisplay()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function optimizeTileObjects()
|
function optimizeTileObjects(dest)
|
||||||
logPrint("Optimizing Objects...")
|
logPrint("Optimizing Objects...")
|
||||||
local unoptimized = 0
|
local unoptimized = 0
|
||||||
local isTileOptimized = {}
|
local isTileOptimized = {}
|
||||||
@ -343,22 +356,20 @@ function optimizeTileObjects()
|
|||||||
base_x + tile_properties.width * tile_properties.scale * n,
|
base_x + tile_properties.width * tile_properties.scale * n,
|
||||||
base_y + tile_properties.height * tile_properties.scale * m
|
base_y + tile_properties.height * tile_properties.scale * m
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Collisions,col)
|
table.insert(dest,col)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
|
--logPrint("collisions optimized from " .. unoptimized .. " to " .. #LoadedObjects.Collisions)
|
||||||
end
|
end
|
||||||
|
|
||||||
function createTileObjects()
|
-- currently broken
|
||||||
LoadedObjects.Collisions = {}
|
function createTileObjects(dest)
|
||||||
LoadedObjects.Platforms = {}
|
|
||||||
LoadedObjects.Ladders = {}
|
|
||||||
LoadedObjects.Hazards = {}
|
|
||||||
|
|
||||||
optimizeTileObjects()
|
|
||||||
|
optimizeTileObjects(dest.collisions)
|
||||||
|
|
||||||
for i = 1, #LevelTiles do
|
for i = 1, #LevelTiles do
|
||||||
for j = 1, #LevelTiles[i] do
|
for j = 1, #LevelTiles[i] do
|
||||||
@ -378,6 +389,9 @@ function createTileObjects()
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local col
|
||||||
|
local list = dest.collisions
|
||||||
|
|
||||||
-- wholes are handled in optimization now
|
-- wholes are handled in optimization now
|
||||||
--[[if type == "whole" then
|
--[[if type == "whole" then
|
||||||
local col = Collision:new(
|
local col = Collision:new(
|
||||||
@ -389,33 +403,33 @@ function createTileObjects()
|
|||||||
table.insert(LoadedObjects.Collisions,col)
|
table.insert(LoadedObjects.Collisions,col)
|
||||||
else]]if type == "half_bottom" then
|
else]]if type == "half_bottom" then
|
||||||
|
|
||||||
local col = Collision:new(
|
col = Collision:new(
|
||||||
base_x,
|
base_x,
|
||||||
base_y + tile_properties.height/2 * tile_properties.scale,
|
base_y + tile_properties.height/2 * tile_properties.scale,
|
||||||
base_x + tile_properties.width * tile_properties.scale,
|
base_x + tile_properties.width * tile_properties.scale,
|
||||||
base_y + tile_properties.height * tile_properties.scale
|
base_y + tile_properties.height * tile_properties.scale
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Collisions,col)
|
|
||||||
|
|
||||||
elseif type == "half_top" then
|
elseif type == "half_top" then
|
||||||
|
|
||||||
local col = Collision:new(
|
col = Collision:new(
|
||||||
base_x,
|
base_x,
|
||||||
base_y ,
|
base_y ,
|
||||||
base_x + tile_properties.width * tile_properties.scale,
|
base_x + tile_properties.width * tile_properties.scale,
|
||||||
base_y + tile_properties.height/2 * tile_properties.scale
|
base_y + tile_properties.height/2 * tile_properties.scale
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Collisions,col)
|
|
||||||
|
|
||||||
elseif type == "half_right" then
|
elseif type == "half_right" then
|
||||||
|
|
||||||
local col = Collision:new(
|
col = Collision:new(
|
||||||
base_x + tile_properties.height/2 * tile_properties.scale,
|
base_x + tile_properties.height/2 * tile_properties.scale,
|
||||||
base_y,
|
base_y,
|
||||||
base_x + tile_properties.width * tile_properties.scale,
|
base_x + tile_properties.width * tile_properties.scale,
|
||||||
base_y + tile_properties.height * tile_properties.scale
|
base_y + tile_properties.height * tile_properties.scale
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Collisions,col)
|
|
||||||
|
|
||||||
elseif type == "half_left" then
|
elseif type == "half_left" then
|
||||||
|
|
||||||
@ -586,7 +600,8 @@ function createTileObjects()
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif type == "ladder_right" then
|
-- TODO: fix ladders
|
||||||
|
--[[elseif type == "ladder_right" then
|
||||||
|
|
||||||
local ladder = Collision:new(
|
local ladder = Collision:new(
|
||||||
base_x + (tile_properties.width-4)* tile_properties.scale,
|
base_x + (tile_properties.width-4)* tile_properties.scale,
|
||||||
@ -644,7 +659,7 @@ function createTileObjects()
|
|||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Platforms,plat)
|
table.insert(LoadedObjects.Platforms,plat)
|
||||||
|
|
||||||
elseif type == "bottom_hazard" then
|
]]elseif type == "bottom_hazard" then
|
||||||
|
|
||||||
|
|
||||||
local hazard = Collision:new(
|
local hazard = Collision:new(
|
||||||
@ -653,9 +668,10 @@ function createTileObjects()
|
|||||||
base_x + tile_properties.width * tile_properties.scale,
|
base_x + tile_properties.width * tile_properties.scale,
|
||||||
base_y + tile_properties.height * tile_properties.scale
|
base_y + tile_properties.height * tile_properties.scale
|
||||||
)
|
)
|
||||||
table.insert(LoadedObjects.Hazards,hazard)
|
list = dest.hazards
|
||||||
|
|
||||||
end
|
end
|
||||||
|
table.insert(list, col)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -16,6 +16,7 @@ require "code/in_out"
|
|||||||
-- classes
|
-- classes
|
||||||
require "code/point"
|
require "code/point"
|
||||||
require "code/rect"
|
require "code/rect"
|
||||||
|
require "code/chunk"
|
||||||
require "code/objects"
|
require "code/objects"
|
||||||
require "code/level"
|
require "code/level"
|
||||||
require "code/camera"
|
require "code/camera"
|
||||||
|
Loading…
Reference in New Issue
Block a user