Save table to file
This commit is contained in:
@@ -3,6 +3,7 @@ local fs=love.filesystem
|
|||||||
local files={
|
local files={
|
||||||
data= fs.newFile("data.dat"),
|
data= fs.newFile("data.dat"),
|
||||||
setting=fs.newFile("settings.dat"),
|
setting=fs.newFile("settings.dat"),
|
||||||
|
network=fs.newFile("network.dat"),
|
||||||
VK= fs.newFile("virtualkey.dat"),
|
VK= fs.newFile("virtualkey.dat"),
|
||||||
keyMap= fs.newFile("key.dat"),
|
keyMap= fs.newFile("key.dat"),
|
||||||
unlock= fs.newFile("unlock.dat"),
|
unlock= fs.newFile("unlock.dat"),
|
||||||
@@ -109,6 +110,28 @@ function FILE.saveSetting()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function FILE.loadNetwork()
|
||||||
|
local F=files.setting
|
||||||
|
if F:open("r")then
|
||||||
|
local s=F:read()
|
||||||
|
if s:sub(1,6)~="return"then
|
||||||
|
s="return{"..s:gsub("\n",",").."}"
|
||||||
|
end
|
||||||
|
s=loadstring(s)
|
||||||
|
F:close()
|
||||||
|
if s then
|
||||||
|
setfenv(s,{})
|
||||||
|
addToTable(s(),NETWORK)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
function FILE.saveNetwork()
|
||||||
|
local F=files.setting
|
||||||
|
F:open("w")
|
||||||
|
F:write(dumpTable(NETWORK))
|
||||||
|
F:flush()F:close()
|
||||||
|
end
|
||||||
|
|
||||||
function FILE.loadKeyMap()
|
function FILE.loadKeyMap()
|
||||||
local F=files.keyMap
|
local F=files.keyMap
|
||||||
if F:open("r")then
|
if F:open("r")then
|
||||||
|
|||||||
@@ -299,6 +299,15 @@ for i=1,25 do
|
|||||||
STAT.spin[i]={0,0,0,0,0,0,0}
|
STAT.spin[i]={0,0,0,0,0,0,0}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
NETWORK={
|
||||||
|
id=nil,
|
||||||
|
username=nil,
|
||||||
|
motto=nil,
|
||||||
|
avatar=nil,
|
||||||
|
auth_token=nil,
|
||||||
|
access_token=nil
|
||||||
|
}
|
||||||
|
|
||||||
keyMap={
|
keyMap={
|
||||||
{"left","right","x","z","c","up","down","space","tab","r"},{},
|
{"left","right","x","z","c","up","down","space","tab","r"},{},
|
||||||
--Keyboard
|
--Keyboard
|
||||||
|
|||||||
@@ -156,8 +156,10 @@ function Tick.httpREQ_login(data)
|
|||||||
local success,content=json.decode(response.body)
|
local success,content=json.decode(response.body)
|
||||||
if success then
|
if success then
|
||||||
LOG.print(text.loginSuccessed..": "..content.message)
|
LOG.print(text.loginSuccessed..": "..content.message)
|
||||||
-- TODO: save {content.token} to storage and a global variable
|
NETWORK.id=content.id
|
||||||
-- TODO: save {content.id} to a global variable
|
NETWORK.username=content.username
|
||||||
|
NETWORK.auth_token=content.auth_token
|
||||||
|
FILE.saveNetwork()
|
||||||
else
|
else
|
||||||
LOG.print(text.jsonError,"warn")
|
LOG.print(text.jsonError,"warn")
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user