FILE.save用法调整

This commit is contained in:
MrZ626
2020-12-06 20:16:54 +08:00
parent 833343cf56
commit c201579f5d
5 changed files with 16 additions and 16 deletions

View File

@@ -26,21 +26,21 @@ function FILE.load(name)
end end
end end
end end
function FILE.save(data,name,mode,luacode) function FILE.save(data,name,mode)
if not mode then mode="m"end if not mode then mode=""end
name=name..".dat" name=name..".dat"
if not luacode then if mode:find("l")then
data=json.encode(data)
if not data then
LOG.print(name.." "..text.saveError.."json error","error")
return
end
else
data=dumpTable(data) data=dumpTable(data)
if not data then if not data then
LOG.print(name.." "..text.saveError.."dump error","error") LOG.print(name.." "..text.saveError.."dump error","error")
return return
end end
else
data=json.encode(data)
if not data then
LOG.print(name.." "..text.saveError.."json error","error")
return
end
end end
local F=fs.newFile(name) local F=fs.newFile(name)
@@ -48,7 +48,7 @@ function FILE.save(data,name,mode,luacode)
local success,mes=F:write(data) local success,mes=F:write(data)
F:flush()F:close() F:flush()F:close()
if success then if success then
if mode:find("m")then if mode:find("q")then
LOG.print(text.saveDone,COLOR.green) LOG.print(text.saveDone,COLOR.green)
end end
else else

View File

@@ -230,7 +230,7 @@ do
end end
S.version=VERSION_CODE S.version=VERSION_CODE
FILE.save(RANKS,"unlock","") FILE.save(RANKS,"unlock","q")
FILE.save(STAT,"data","") FILE.save(STAT,"data")
end end
end end

View File

@@ -1477,7 +1477,7 @@ local function gameOver()--Save record
end end
end end
if needSave then if needSave then
FILE.save(RANKS,"unlock") FILE.save(RANKS,"unlock","q")
end end
local D=M.score(P) local D=M.score(P)
local L=M.records local L=M.records
@@ -1495,7 +1495,7 @@ local function gameOver()--Save record
D.date=os.date("%Y/%m/%d %H:%M") D.date=os.date("%Y/%m/%d %H:%M")
ins(L,p+1,D) ins(L,p+1,D)
if L[11]then L[11]=nil end if L[11]then L[11]=nil end
FILE.save(L,M.name,"",true) FILE.save(L,M.name,"l")
end end
end end
end end

View File

@@ -11,7 +11,7 @@ local function tick_httpREQ_newLogin(task)
LOG.print(text.loginSuccessed) LOG.print(text.loginSuccessed)
ACCOUNT.email=res.email ACCOUNT.email=res.email
ACCOUNT.auth_token=res.auth_token ACCOUNT.auth_token=res.auth_token
FILE.save(ACCOUNT,"account","") FILE.save(ACCOUNT,"account","q")
httpRequest( httpRequest(
TICK.httpREQ_getAccessToken, TICK.httpREQ_getAccessToken,

View File

@@ -10,7 +10,7 @@ function Tick.httpREQ_getAccessToken(task)
if res then if res then
LOG.print(text.accessSuccessed) LOG.print(text.accessSuccessed)
ACCOUNT.access_token=res.access_token ACCOUNT.access_token=res.access_token
FILE.save(ACCOUNT,"account","") FILE.save(ACCOUNT,"account")
SCN.swapTo("netgame") SCN.swapTo("netgame")
else else
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn") LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")