Skip to content

Commit

Permalink
В клиент на Love2d добавлена библиотека states.lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
devapromix committed Jan 19, 2023
1 parent e2a6221 commit 53448ea
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
62 changes: 62 additions & 0 deletions client/libraries/states.lua
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
5 changes: 3 additions & 2 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
utf8 = require("utf8")

username = "serg"
userpass = ""
userpass = "4444"
world = "elvion"

server = "http://lizardry.pp.ua/"
Expand All @@ -12,7 +12,8 @@ response = ""

http = require("socket.http")
md5 = require('libraries.md5')
json = require "libraries.json"
json = require("libraries.json")
states = require("libraries.states")
assets = require('libraries.cargo').init('resources')

resources = {
Expand Down
Binary file modified client/resources/fonts/main_font.ttf
Binary file not shown.

0 comments on commit 53448ea

Please sign in to comment.