78 lines
2.1 KiB
Lua
78 lines
2.1 KiB
Lua
-- debug
|
|
if os.getenv("LOCAL_LUA_DEBUGGER_VSCODE") == "1" then
|
|
require("lldebugger").start()
|
|
end
|
|
|
|
-- libraries
|
|
Object = require 'lib/classic/classic'
|
|
Baton = require 'lib/baton/baton'
|
|
Timer = require 'lib/hump/timer'
|
|
|
|
-- objects
|
|
Room = require 'obj/Room'
|
|
|
|
function love.load()
|
|
---@type Room|nil
|
|
current_room = nil
|
|
|
|
-- load rooms
|
|
local room_files = {}
|
|
recursiveEnumerate('rooms', room_files)
|
|
requireFiles(room_files)
|
|
|
|
-- load input
|
|
input = Baton.new {
|
|
controls = {
|
|
left = {'key:left', 'key:a'},
|
|
right = {'key:right', 'key:d'},
|
|
up = {'key:up', 'key:w'},
|
|
down = {'key:down', 'key:s'},
|
|
action = {'key:z', 'key:space'}
|
|
},
|
|
pairs = {
|
|
move = {'left', 'right', 'up', 'down'}
|
|
}
|
|
}
|
|
end
|
|
|
|
function love.update(dt)
|
|
input:update(dt)
|
|
if current_room then current_room:update(dt) end
|
|
end
|
|
|
|
function love.draw()
|
|
if current_room then current_room:draw() end
|
|
end
|
|
|
|
---Enumerates files in a folder and inserts them to a provided table.
|
|
---@param folder string path to folder to scan
|
|
---@param file_list table table to be inserted to
|
|
function recursiveEnumerate(folder, file_list)
|
|
local items = love.filesystem.getDirectoryItems(folder)
|
|
for _, item in ipairs(items) do
|
|
local file = folder .. '/' .. item
|
|
---@diagnostic disable-next-line: undefined-field
|
|
if love.filesystem.isFile(file) then
|
|
table.insert(file_list, file)
|
|
---@diagnostic disable-next-line: undefined-field
|
|
elseif love.filesystem.isDirectory(file) then
|
|
recursiveEnumerate(file, file_list)
|
|
end
|
|
end
|
|
end
|
|
|
|
---Load files table as lua modules.
|
|
---@param files table table containing files to be loaded
|
|
function requireFiles(files)
|
|
for _, file in ipairs(files) do
|
|
local file = file:sub(1, -5)
|
|
require(file)
|
|
end
|
|
end
|
|
|
|
---Go to a specific room.
|
|
---@param room_type string the name of the room as registered
|
|
---@param ... any arguments passed to the room constructor
|
|
function gotoRoom(room_type, ...)
|
|
current_room = _G[room_type](...)
|
|
end
|