-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
В клиент на Love2d добавлена библиотека states.lua.
- Loading branch information
1 parent
e2a6221
commit 53448ea
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
local states = {} | ||
|
||
local stateFiles = {} | ||
|
||
local currentState = "default" | ||
|
||
local love2dCallbacksList = | ||
{ | ||
"keypressed", | ||
"keyreleased", | ||
"filedropped", | ||
"directorydropped", | ||
"draw", | ||
"update", | ||
"wheelmoved", | ||
"mousepressed", | ||
"mousemoved", | ||
"mousereleased", | ||
"textinput", | ||
"focus", | ||
"lowmemory", | ||
"mousefocus", | ||
"resize", | ||
"quit", | ||
"threaderror", | ||
"enter", | ||
"visible" | ||
} | ||
|
||
local function defaultInitialize(stateFile) | ||
for _,callback in pairs(love2dCallbacksList) do | ||
stateFile[callback] = stateFile[callback] or function() end | ||
stateFile.open = stateFile.open or function() end | ||
end | ||
end | ||
|
||
local function add(stateName) | ||
stateFiles[stateName] = require("states/"..stateName) | ||
defaultInitialize(stateFiles[stateName]) | ||
end | ||
|
||
function states.setup() | ||
for _,callback in pairs(love2dCallbacksList) do | ||
states[callback] = | ||
function(...) | ||
stateFiles[currentState][callback](unpack({...})) | ||
end | ||
love[callback] = love[callback] or states[callback] | ||
end | ||
end | ||
|
||
function states.switch(newState,params) | ||
if not stateFiles[newState] then | ||
add(newState) | ||
end | ||
|
||
currentState = newState | ||
local params = type(params)=="table" and params or {} | ||
stateFiles[newState].open(params) | ||
end | ||
|
||
return states |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.