Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions src/Core/State/BaseState.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
--!strict

local BaseState = {}
BaseState.__index = BaseState

-------------------------------------------------------------------------------------------------------------------------

-- selene: allow(unused_variable)
local DEFAULT_EVENTS = {
Preloading = function()
return
end,
Loading = function()
return
end,
Postloading = function()
return
end,
Updating = function(Delta: number)
return
end,
Destroying = function()
return
end,
}

-------------------------------------------------------------------------------------------------------------------------

export type BaseState = setmetatable<{
_Events: typeof(DEFAULT_EVENTS),
}, typeof(BaseState)>

-------------------------------------------------------------------------------------------------------------------------

--[[
Creates a new base state with default events.

@return A new base state with default events.
]]
function BaseState.new(): BaseState
return setmetatable({
_Events = table.clone(DEFAULT_EVENTS),
}, BaseState) :: BaseState
end

-------------------------------------------------------------------------------------------------------------------------

--[[
Gets called before the state starts loading.
]]
function BaseState.Preloading(self: BaseState, Callback: () -> ()): ()
self._Events.Preloading = Callback
end

--[[
Gets called when the state starts loading.
]]
function BaseState.Loading(self: BaseState, Callback: () -> ()): ()
self._Events.Loading = Callback
end

--[[
Gets called after the state finishes loading.
]]
function BaseState.Postloading(self: BaseState, Callback: () -> ()): ()
self._Events.Postloading = Callback
end

--[[
Gets called every frame.

@param Delta -- The time in seconds since the last frame.
]]
function BaseState.Updating(self: BaseState, Callback: (Delta: number) -> ()): ()
self._Events.Updating = Callback
end

--[[
Gets called before the state is destroyed.
]]
function BaseState.Destroying(self: BaseState, Callback: () -> ()): ()
self._Events.Destroying = Callback
end

-------------------------------------------------------------------------------------------------------------------------

return BaseState
12 changes: 12 additions & 0 deletions src/Core/State/init.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--!strict

--[[
State manager for Junta.
By @Cayla & @Entar
]]

-------------------------------------------------------------------------------------------------------------------------

return {
BaseState = require("@self/BaseState"),
}