78 lines
2.1 KiB
Lua
78 lines
2.1 KiB
Lua
local files = require "modules.files"
|
|
local json = require "modules.json"
|
|
local data = love.filesystem.getSaveDirectory()
|
|
local font = love.graphics.newFont("fonts/Phantomuff.ttf", 35)
|
|
|
|
|
|
return function ()
|
|
---@type engine.state
|
|
local state = {}
|
|
|
|
local settings = {}
|
|
local username = ""
|
|
local key = ""
|
|
|
|
local onkey = false
|
|
local message
|
|
|
|
function state.load()
|
|
love.window.setTitle("TaggedEngine: GameJolt Login")
|
|
|
|
local bg = Image("images/menuBG.png")
|
|
bg.layer = -5
|
|
|
|
local stringsettings = files.read_file(data.."/Settings.json")
|
|
|
|
settings = json.parse(stringsettings)
|
|
end
|
|
|
|
function state.draw()
|
|
render.drawSprites()
|
|
|
|
if message then
|
|
love.graphics.print(message, font, 640 - font:getWidth(message) / 2, 360)
|
|
else
|
|
local message = string.format(onkey and "Your GameJolt GameKey: %s" or "Your GameJolt Username: %s", onkey and key or username)
|
|
love.graphics.print({{0,0,0}, message}, font, 640 - font:getWidth(message) / 2, 360)
|
|
end
|
|
end
|
|
|
|
function state.keypressed(okey)
|
|
if okey == "backspace" then
|
|
if onkey then
|
|
key = ""
|
|
else
|
|
username = ""
|
|
end
|
|
elseif okey == "escape" then
|
|
state.changeState("menustate")
|
|
elseif okey == "return" then
|
|
if onkey then
|
|
local looged = gamejolt.authUser(username, key)
|
|
gamejolt.openSession()
|
|
gamejolt.giveTrophy(278482)
|
|
|
|
message = looged and "Logged in" or "Failed to log in."
|
|
|
|
if looged then
|
|
settings.user = {}
|
|
|
|
settings.user.name = username
|
|
settings.user.key = key
|
|
|
|
files.write_file(data.."/Settings.json", json.stringify(settings))
|
|
end
|
|
else
|
|
onkey = true
|
|
end
|
|
else
|
|
if onkey then
|
|
key = key..okey
|
|
else
|
|
username = username..okey
|
|
end
|
|
end
|
|
end
|
|
|
|
return state
|
|
end |