FILE模块修改,并将所有文件分类整理方便未来调整
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
local fs=love.filesystem
|
||||
local FILE={}
|
||||
function FILE.load(name)
|
||||
name=name..".dat"
|
||||
local F=fs.newFile(name)
|
||||
if F:open("r")then
|
||||
local s=F:read()
|
||||
@@ -28,7 +27,7 @@ function FILE.load(name)
|
||||
end
|
||||
function FILE.save(data,name,mode)
|
||||
if not mode then mode=""end
|
||||
name=name..".dat"
|
||||
name=name
|
||||
if mode:find("l")then
|
||||
data=dumpTable(data)
|
||||
if not data then
|
||||
|
||||
42
main.lua
42
main.lua
@@ -250,9 +250,33 @@ for _,v in next,fs.getDirectoryItems("parts/scenes")do
|
||||
end
|
||||
end
|
||||
|
||||
--Collect files
|
||||
if fs.getInfo("data.dat")then
|
||||
fs.createDirectory("conf")
|
||||
for _,v in next,{
|
||||
"settings",
|
||||
"unlock",
|
||||
"data",
|
||||
"key",
|
||||
"virtualkey",
|
||||
"account",
|
||||
}do
|
||||
fs.write("conf/"..v,fs.read(v..".dat"))
|
||||
fs.remove(v..".dat")
|
||||
end
|
||||
fs.createDirectory("record")
|
||||
for _,name in next,fs.getDirectoryItems("")do
|
||||
if name:sub(-4)==".dat"then
|
||||
fs.write("record/"..name,fs.read(name))
|
||||
fs.remove(name)
|
||||
end
|
||||
end
|
||||
fs.createDirectory("replay")
|
||||
end
|
||||
|
||||
--Load files
|
||||
if fs.getInfo("settings.dat")then
|
||||
addToTable(FILE.load("settings"),SETTING)
|
||||
if fs.getInfo("conf/settings")then
|
||||
addToTable(FILE.load("conf/settings"),SETTING)
|
||||
else
|
||||
if MOBILE then
|
||||
SETTING.VKSwitch=true
|
||||
@@ -267,11 +291,11 @@ end
|
||||
if SETTING.fullscreen then love.window.setFullscreen(true)end
|
||||
LANG.set(SETTING.lang)
|
||||
|
||||
if fs.getInfo("unlock.dat")then RANKS=FILE.load("unlock")end
|
||||
if fs.getInfo("data.dat")then STAT=FILE.load("data")end
|
||||
if fs.getInfo("key.dat")then keyMap=FILE.load("key")end
|
||||
if fs.getInfo("virtualkey.dat")then VK_org=FILE.load("virtualkey")end
|
||||
if fs.getInfo("account.dat")then ACCOUNT=FILE.load("account")end
|
||||
if fs.getInfo("conf/unlock")then RANKS=FILE.load("conf/unlock")end
|
||||
if fs.getInfo("conf/data")then STAT=FILE.load("conf/data")end
|
||||
if fs.getInfo("conf/key")then keyMap=FILE.load("conf/key")end
|
||||
if fs.getInfo("conf/virtualkey")then VK_org=FILE.load("conf/virtualkey")end
|
||||
if fs.getInfo("conf/account")then ACCOUNT=FILE.load("conf/account")end
|
||||
|
||||
for _,v in next,{
|
||||
"tech_ultimate.dat",
|
||||
@@ -357,7 +381,7 @@ do
|
||||
end
|
||||
|
||||
S.version=VERSION_CODE
|
||||
FILE.save(RANKS,"unlock","q")
|
||||
FILE.save(STAT,"data")
|
||||
FILE.save(RANKS,"conf/unlock","q")
|
||||
FILE.save(STAT,"conf/data")
|
||||
end
|
||||
end
|
||||
@@ -1498,7 +1498,7 @@ end
|
||||
--------------------------<Events>--------------------------
|
||||
local function gameOver()--Save record
|
||||
if GAME.replaying then return end
|
||||
FILE.save(STAT,"data")
|
||||
FILE.save(STAT,"conf/data")
|
||||
local M=GAME.curMode
|
||||
local R=M.getRank
|
||||
if R then
|
||||
@@ -1528,7 +1528,7 @@ local function gameOver()--Save record
|
||||
end
|
||||
end
|
||||
if needSave then
|
||||
FILE.save(RANKS,"unlock","q")
|
||||
FILE.save(RANKS,"conf/unlock","q")
|
||||
end
|
||||
local D=M.score(P)
|
||||
local L=M.records
|
||||
@@ -1546,7 +1546,7 @@ local function gameOver()--Save record
|
||||
D.date=os.date("%Y/%m/%d %H:%M")
|
||||
ins(L,p+1,D)
|
||||
if L[11]then L[11]=nil end
|
||||
FILE.save(L,M.name,"l")
|
||||
FILE.save(L,"record/"..M.name,"l")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -86,7 +86,7 @@ function scene.keyDown(k)
|
||||
RANKS[name]=M.score and 0 or 6
|
||||
end
|
||||
end
|
||||
FILE.save(RANKS,"unlock")
|
||||
FILE.save(RANKS,"conf/unlock")
|
||||
LOG.print("\68\69\86\58\85\78\76\79\67\75\65\76\76","message")
|
||||
SFX.play("clear_2")
|
||||
elseif v%1==0 and v>=8001 and v<=8012 then
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
local scene={}
|
||||
|
||||
function scene.sceneBack()
|
||||
FILE.save(SETTING,"settings")
|
||||
FILE.save(SETTING,"conf/settings")
|
||||
end
|
||||
|
||||
local function setLang(n)return function()SETTING.lang=n LANG.set(n)end end
|
||||
|
||||
@@ -140,7 +140,7 @@ function scene.update()
|
||||
for k,v in next,m do
|
||||
M[k]=v
|
||||
end
|
||||
M.records=FILE.load(m.name)or M.score and{}
|
||||
M.records=FILE.load(m.name..".dat")or M.score and{}
|
||||
-- M.icon=gc.newImage("media/image/modeIcon/"..m.icon..".png")
|
||||
-- M.icon=gc.newImage("media/image/modeIcon/custom.png")
|
||||
elseif phase==8 then
|
||||
|
||||
@@ -11,7 +11,7 @@ local function tick_httpREQ_newLogin(task)
|
||||
LOG.print(text.loginSuccessed)
|
||||
ACCOUNT.email=res.email
|
||||
ACCOUNT.auth_token=res.auth_token
|
||||
FILE.save(ACCOUNT,"account","q")
|
||||
FILE.save(ACCOUNT,"conf/account","q")
|
||||
|
||||
httpRequest(
|
||||
TICK.httpREQ_getAccessToken,
|
||||
|
||||
@@ -127,7 +127,7 @@ function scene.sceneBack()
|
||||
STAT.todayTime=STAT.todayTime+PLAYERS[1].stat.time
|
||||
end
|
||||
if not GAME.result then
|
||||
FILE.save(STAT,"data")
|
||||
FILE.save(STAT,"conf/data")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ scene.widgetList={
|
||||
local D=parseCB()
|
||||
if D then
|
||||
addToTable(D,RANKS)
|
||||
FILE.save(RANKS,"unlock")
|
||||
FILE.save(RANKS,"conf/unlock")
|
||||
else
|
||||
LOG.print(text.importSuccess,COLOR.green)
|
||||
end
|
||||
@@ -57,7 +57,7 @@ scene.widgetList={
|
||||
local D=parseCB()
|
||||
if D then
|
||||
addToTable(D,STAT)
|
||||
FILE.save(STAT,"data")
|
||||
FILE.save(STAT,"conf/data")
|
||||
else
|
||||
LOG.print(text.importSuccess,COLOR.green)
|
||||
end
|
||||
@@ -66,7 +66,7 @@ scene.widgetList={
|
||||
local D=parseCB()
|
||||
if D then
|
||||
addToTable(D,SETTING)
|
||||
FILE.save(SETTING,"settings")
|
||||
FILE.save(SETTING,"conf/settings")
|
||||
else
|
||||
LOG.print(text.importSuccess,COLOR.green)
|
||||
end
|
||||
@@ -75,7 +75,7 @@ scene.widgetList={
|
||||
local D=parseCB()
|
||||
if D then
|
||||
addToTable(D,VK_org)
|
||||
FILE.save(VK_org,"virtualkey")
|
||||
FILE.save(VK_org,"conf/virtualkey")
|
||||
else
|
||||
LOG.print(text.importSuccess,COLOR.green)
|
||||
end
|
||||
|
||||
@@ -9,7 +9,7 @@ function scene.sceneInit()
|
||||
BG.set("space")
|
||||
end
|
||||
function scene.sceneBack()
|
||||
FILE.save(SETTING,"settings")
|
||||
FILE.save(SETTING,"conf/settings")
|
||||
end
|
||||
|
||||
function scene.draw()
|
||||
|
||||
@@ -17,7 +17,7 @@ function scene.sceneInit()
|
||||
kS,jS=false,false
|
||||
end
|
||||
function scene.sceneBack()
|
||||
FILE.save(keyMap,"key")
|
||||
FILE.save(keyMap,"conf/key")
|
||||
end
|
||||
|
||||
function scene.keyDown(key)
|
||||
|
||||
@@ -17,7 +17,7 @@ function scene.sceneInit()
|
||||
BG.set("space")
|
||||
end
|
||||
function scene.sceneBack()
|
||||
FILE.save(SETTING,"settings")
|
||||
FILE.save(SETTING,"conf/settings")
|
||||
end
|
||||
|
||||
function scene.mouseDown(x,y)
|
||||
|
||||
@@ -17,7 +17,7 @@ function scene.sceneInit()
|
||||
select=nil
|
||||
end
|
||||
function scene.sceneBack()
|
||||
FILE.save(VK_org,"virtualkey")
|
||||
FILE.save(VK_org,"conf/virtualkey")
|
||||
end
|
||||
|
||||
local function onVK_org(x,y)
|
||||
|
||||
@@ -4,7 +4,7 @@ function scene.sceneInit()
|
||||
BG.set("space")
|
||||
end
|
||||
function scene.sceneBack()
|
||||
FILE.save(SETTING,"settings")
|
||||
FILE.save(SETTING,"conf/settings")
|
||||
end
|
||||
|
||||
scene.widgetList={
|
||||
|
||||
@@ -10,7 +10,7 @@ function Tick.httpREQ_getAccessToken(task)
|
||||
if res then
|
||||
LOG.print(text.accessSuccessed)
|
||||
ACCOUNT.access_token=res.access_token
|
||||
FILE.save(ACCOUNT,"account")
|
||||
FILE.save(ACCOUNT,"conf/account")
|
||||
SCN.swapTo("netgame")
|
||||
else
|
||||
LOG.print(text.netErrorCode..response.code..": "..res.message,"warn")
|
||||
|
||||
Reference in New Issue
Block a user