From d5dcc78acd564966fa28ae54bf549645ab607d5b Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Sun, 13 Dec 2020 23:38:06 +0800 Subject: [PATCH] =?UTF-8?q?FILE=E6=A8=A1=E5=9D=97=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=EF=BC=8C=E5=B9=B6=E5=B0=86=E6=89=80=E6=9C=89=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E6=95=B4=E7=90=86=E6=96=B9=E4=BE=BF=E6=9C=AA?= =?UTF-8?q?=E6=9D=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zframework/file.lua | 3 +-- main.lua | 42 ++++++++++++++++++++++++++-------- parts/player/player.lua | 6 ++--- parts/scenes/calculator.lua | 2 +- parts/scenes/lang.lua | 2 +- parts/scenes/load.lua | 2 +- parts/scenes/login.lua | 2 +- parts/scenes/pause.lua | 2 +- parts/scenes/savedata.lua | 8 +++---- parts/scenes/setting_game.lua | 2 +- parts/scenes/setting_key.lua | 2 +- parts/scenes/setting_sound.lua | 2 +- parts/scenes/setting_touch.lua | 2 +- parts/scenes/setting_video.lua | 2 +- parts/tick.lua | 2 +- 15 files changed, 52 insertions(+), 29 deletions(-) diff --git a/Zframework/file.lua b/Zframework/file.lua index 987f4963..323fc1b3 100644 --- a/Zframework/file.lua +++ b/Zframework/file.lua @@ -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 diff --git a/main.lua b/main.lua index 6328df9c..7312bb04 100644 --- a/main.lua +++ b/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 \ No newline at end of file diff --git a/parts/player/player.lua b/parts/player/player.lua index efdb6ba1..d4ca6a2d 100644 --- a/parts/player/player.lua +++ b/parts/player/player.lua @@ -1498,7 +1498,7 @@ end ---------------------------------------------------- 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 diff --git a/parts/scenes/calculator.lua b/parts/scenes/calculator.lua index 2471fe50..fdc3ff89 100644 --- a/parts/scenes/calculator.lua +++ b/parts/scenes/calculator.lua @@ -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 diff --git a/parts/scenes/lang.lua b/parts/scenes/lang.lua index 5e203021..6c6b7d6e 100644 --- a/parts/scenes/lang.lua +++ b/parts/scenes/lang.lua @@ -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 diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index 946b9d85..a88bc42d 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -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 diff --git a/parts/scenes/login.lua b/parts/scenes/login.lua index 1d76b96f..af7ddf3e 100644 --- a/parts/scenes/login.lua +++ b/parts/scenes/login.lua @@ -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, diff --git a/parts/scenes/pause.lua b/parts/scenes/pause.lua index 60c64757..b965d459 100644 --- a/parts/scenes/pause.lua +++ b/parts/scenes/pause.lua @@ -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 diff --git a/parts/scenes/savedata.lua b/parts/scenes/savedata.lua index 80750c33..024fef85 100644 --- a/parts/scenes/savedata.lua +++ b/parts/scenes/savedata.lua @@ -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 diff --git a/parts/scenes/setting_game.lua b/parts/scenes/setting_game.lua index 8f088142..c685a1b1 100644 --- a/parts/scenes/setting_game.lua +++ b/parts/scenes/setting_game.lua @@ -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() diff --git a/parts/scenes/setting_key.lua b/parts/scenes/setting_key.lua index 086678f1..860f40ad 100644 --- a/parts/scenes/setting_key.lua +++ b/parts/scenes/setting_key.lua @@ -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) diff --git a/parts/scenes/setting_sound.lua b/parts/scenes/setting_sound.lua index 5a42e3d7..c9e7fdd3 100644 --- a/parts/scenes/setting_sound.lua +++ b/parts/scenes/setting_sound.lua @@ -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) diff --git a/parts/scenes/setting_touch.lua b/parts/scenes/setting_touch.lua index aedd6518..e35cffe8 100644 --- a/parts/scenes/setting_touch.lua +++ b/parts/scenes/setting_touch.lua @@ -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) diff --git a/parts/scenes/setting_video.lua b/parts/scenes/setting_video.lua index c463dc46..b7fda7a1 100644 --- a/parts/scenes/setting_video.lua +++ b/parts/scenes/setting_video.lua @@ -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={ diff --git a/parts/tick.lua b/parts/tick.lua index 7e6b7d02..6a431bae 100644 --- a/parts/tick.lua +++ b/parts/tick.lua @@ -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")