141 lines
2.9 KiB
Lua
141 lines
2.9 KiB
Lua
-- STATE HANDLER
|
|
local gamePath = love.filesystem.getSourceBaseDirectory() -- Assuming it's always in fused mode.
|
|
-- love TaggedEngine.love --fused
|
|
|
|
local mounted = love.filesystem.mount(gamePath, "") -- Mounting the game directory, should be accessible like if normal.
|
|
|
|
require("modules.loveanimate")
|
|
print("y")
|
|
require("modules.types")
|
|
require("modules.math")
|
|
|
|
---@class engine.state
|
|
local StateClass = {}
|
|
|
|
function StateClass.load()
|
|
end
|
|
function StateClass.draw()
|
|
end
|
|
---@param key love.KeyConstant
|
|
function StateClass.keypressed(key)
|
|
end
|
|
---@param delta number
|
|
function StateClass.update(delta)
|
|
end
|
|
---@param x number
|
|
---@param y number
|
|
---@param button number
|
|
---@param presses number
|
|
---@param istouch boolean
|
|
function StateClass.mousepressed(x,y,button,istouch,presses)
|
|
end
|
|
---@param x number
|
|
---@param y number
|
|
---@param button number
|
|
---@param presses number
|
|
---@param istouch boolean
|
|
function StateClass.mousereleased(x,y,button,istouch,presses)
|
|
end
|
|
---@param x number
|
|
---@param y number
|
|
---@param dx number
|
|
---@param dy number
|
|
---@param istouch boolean
|
|
function StateClass.mousemoved(x,y,dx,dy,istouch)
|
|
end
|
|
---@param x number
|
|
---@param y number
|
|
function StateClass.wheelmoved(x,y)
|
|
end
|
|
|
|
curChar = "bf"
|
|
|
|
|
|
assert(mounted, "Couldn't mount the game directory.")
|
|
|
|
local curState
|
|
local stateLoaded = false
|
|
|
|
local setState
|
|
|
|
function setState(name, ...)
|
|
if curState then
|
|
curState.quit()
|
|
end
|
|
|
|
curState = require(string.format("states.%s", name))(...)
|
|
|
|
curState.quit = function(accuracy, score)
|
|
curState = nil
|
|
stateLoaded = false
|
|
buttons.clearButtons()
|
|
render.destroyAllSprites()
|
|
setState("freeplaystate")
|
|
end
|
|
|
|
curState.restart = function(...)
|
|
local lastStateName = curState.name
|
|
curState = nil
|
|
stateLoaded = false
|
|
buttons.clearButtons()
|
|
render.destroyAllSprites()
|
|
|
|
setState(lastStateName, ...)
|
|
end
|
|
|
|
curState.changeState = function(...)
|
|
curState = nil
|
|
stateLoaded = false
|
|
render.destroyAllSprites()
|
|
buttons.clearButtons()
|
|
setState(...)
|
|
end
|
|
|
|
curState.load()
|
|
end
|
|
|
|
function love.draw()
|
|
if curState and curState.draw then
|
|
curState.draw()
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
if curState and curState.update then
|
|
curState.update(dt)
|
|
end
|
|
end
|
|
|
|
function love.keypressed(...)
|
|
if curState and curState.keypressed then
|
|
curState.keypressed(...)
|
|
end
|
|
end
|
|
|
|
function love.load()
|
|
setState("menustate")
|
|
end
|
|
|
|
function love.mousemoved(...)
|
|
if curState and curState.mousemoved then
|
|
curState.mousemoved(...)
|
|
end
|
|
end
|
|
|
|
function love.mousepressed(...)
|
|
if curState and curState.mousepressed then
|
|
curState.mousepressed(...)
|
|
end
|
|
end
|
|
|
|
function love.mousereleased(...)
|
|
if curState and curState.mousereleased then
|
|
curState.mousereleased(...)
|
|
end
|
|
end
|
|
|
|
function love.wheelmoved(...)
|
|
if curState and curState.wheelmoved then
|
|
curState.wheelmoved(...)
|
|
end
|
|
end |