From fdf01e1d1e25041ec817736f45e0d8c0756c5560 Mon Sep 17 00:00:00 2001 From: MrZ626 <1046101471@qq.com> Date: Mon, 14 Dec 2020 17:08:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=83=8F=E4=BF=9D=E5=AD=98=E5=88=9D?= =?UTF-8?q?=E7=89=88=EF=BC=88=E8=AF=BB=E5=8F=96=E5=9B=9E=E6=94=BE=E8=BF=98?= =?UTF-8?q?=E6=B2=A1=E5=81=9A=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.lua | 1 + parts/gametoolfunc.lua | 57 +++++++++++++++++++++++++++++++--- parts/globalTables.lua | 6 ++-- parts/language/lang_en.lua | 1 + parts/language/lang_fr.lua | 1 + parts/language/lang_sp.lua | 1 + parts/language/lang_symbol.lua | 1 + parts/language/lang_zh.lua | 1 + parts/scenes/pause.lua | 15 ++++++--- 9 files changed, 72 insertions(+), 12 deletions(-) diff --git a/main.lua b/main.lua index 5777ed72..c818ac7c 100644 --- a/main.lua +++ b/main.lua @@ -296,6 +296,7 @@ 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/user")then USER=FILE.load("conf/user")end +if fs.getInfo("conf/replay")then REPLAY=FILE.load("conf/replay")end for _,v in next,{ "tech_ultimate.dat", diff --git a/parts/gametoolfunc.lua b/parts/gametoolfunc.lua index 66185df4..c1be630f 100644 --- a/parts/gametoolfunc.lua +++ b/parts/gametoolfunc.lua @@ -1,5 +1,7 @@ local tm=love.timer local data=love.data + +local fs=love.filesystem local int,rnd=math.floor,math.random local sub=string.sub local char,byte=string.char,string.byte @@ -473,6 +475,7 @@ function loadGame(M,ifQuickPlay)--Load a mode and go to game scene freshDate() if legalGameTime()then if MODES[M].score then STAT.lastPlay=M end + GAME.curModeName=M GAME.curMode=MODES[M] GAME.modeEnv=GAME.curMode.env drawableText.modeName:set(text.modes[M][1]) @@ -550,15 +553,16 @@ function resetGameData(replaying) GAME.replaying=1 else GAME.frame=150-SETTING.reTime*15 + GAME.seed=rnd(1046101471,2662622626) GAME.pauseTime=0 GAME.pauseCount=0 - GAME.recording=true - GAME.replaying=false + GAME.saved=false GAME.setting=copyGameSetting() GAME.rep={} + GAME.recording=true + GAME.replaying=false GAME.rank=0 math.randomseed(tm.getTime()) - GAME.seed=rnd(1046101471,2662622626) end destroyPlayers() @@ -653,10 +657,10 @@ function dumpRecording(list,ptr) --Step ptr=ptr+2 end - return data.encode("string","base64",out..buffer) + return out..buffer end function pumpRecording(str,L) - str=data.decode("string","base64",str) + -- str=data.decode("string","base64",str) local len=#str local p=1 @@ -690,4 +694,47 @@ function pumpRecording(str,L) p=p+1 end return list +end + +local noRecList={"custom","solo","round","techmino"} +local function getModList() + local res={} + for k,v in next,GAME.mod do + if v.sel>0 then + ins(res,{v.no,v.sel}) + end + end + return res +end +function saveRecording() + --Filtering modes that cannot be saved + for _,v in next,noRecList do + if GAME.curModeName:find(v)then + LOG.print("Cannot save recording of this mode now!",COLOR.sky) + return + end + end + + --File contents + local fileName="replay/"..os.date("%Y_%m_%d_%a_%H%M%S.rep") + local fileHead= + os.date("%Y/%m/%d_%A_%H:%M:%S\n").. + GAME.curModeName.."\n".. + VERSION_NAME.."\n".. + (USER.username or"Player") + local fileBody= + GAME.seed.."\n".. + json.encode(GAME.setting).."\n".. + json.encode(getModList()).."\n".. + dumpRecording(GAME.rep) + + --Write file + if not fs.getInfo(fileName)then + fs.write(fileName,fileHead.."\n"..data.compress("string","zlib",fileBody)) + ins(REPLAY,fileName) + FILE.save(REPLAY,"conf/replay") + return true + else + LOG.print("Save failed: File already exists") + end end \ No newline at end of file diff --git a/parts/globalTables.lua b/parts/globalTables.lua index 24ec1460..5b08aa5a 100644 --- a/parts/globalTables.lua +++ b/parts/globalTables.lua @@ -204,6 +204,7 @@ GAME={--Global game data frame=0, --Frame count result=false, --Game result (string) + rank=nil, --Rank reached pauseTime=0, --Time paused pauseCount=0, --Pausing count warnLVL0=0, --Warning level @@ -211,6 +212,7 @@ GAME={--Global game data seed=1046101471, --Game seed curMode=nil, --Current gamemode object + mod={}, --List of loaded mods modeEnv=nil, --Current gamemode environment setting={}, --Game settings rep={}, --Recording list, key,time,key,time... @@ -218,9 +220,6 @@ GAME={--Global game data replaying=false, --If replaying saved=false, --If recording saved - mod={}, --List of loaded mods - rank=nil, --Rank reached - prevBG=nil, --Previous background, for restore BG when quit setting page --Data for royale mode @@ -345,3 +344,4 @@ VK_org={--Virtualkey layout, refresh all VKs' position with this before each gam {ava=false, x=1000, y=50, r=80},--addToRight } virtualkey={}for i=1,#VK_org do virtualkey[i]={}end--In-game virtualkey layout +REPLAY={} \ No newline at end of file diff --git a/parts/language/lang_en.lua b/parts/language/lang_en.lua index 6a32f5c1..61d8be41 100644 --- a/parts/language/lang_en.lua +++ b/parts/language/lang_en.lua @@ -237,6 +237,7 @@ return{ pause={ setting="Settings (S)", replay="Replay (P)", + save="Save (O)", resume="Resume (esc)", restart="Retry (R)", quit="Quit (Q)", diff --git a/parts/language/lang_fr.lua b/parts/language/lang_fr.lua index 0e734ab4..6de926e7 100644 --- a/parts/language/lang_fr.lua +++ b/parts/language/lang_fr.lua @@ -216,6 +216,7 @@ return{ pause={ setting="Paramètres (S)", replay="Replay (P)", + -- save="Save (O)", resume="Continuer (esc)", restart="Réessayer (R)", quit="Quitter (Q)", diff --git a/parts/language/lang_sp.lua b/parts/language/lang_sp.lua index 8d014910..161d2588 100644 --- a/parts/language/lang_sp.lua +++ b/parts/language/lang_sp.lua @@ -220,6 +220,7 @@ return{ pause={ setting="Opciones (S)", replay= "Grabación (P)", + -- save="Save (O)", resume= "Resumir (esc)", restart="Reiniciar (R)", quit= "Finalizar (Q)", diff --git a/parts/language/lang_symbol.lua b/parts/language/lang_symbol.lua index 983fd9f0..1eb5a86e 100644 --- a/parts/language/lang_symbol.lua +++ b/parts/language/lang_symbol.lua @@ -127,6 +127,7 @@ return{ pause={ setting="_?_ (S)", replay="## (P)", + save="0101 (O)", resume="!! (esc)", restart="_→_ (R)", quit="X (Q)", diff --git a/parts/language/lang_zh.lua b/parts/language/lang_zh.lua index 7fe0a56b..764e5502 100644 --- a/parts/language/lang_zh.lua +++ b/parts/language/lang_zh.lua @@ -240,6 +240,7 @@ return{ pause={ setting="设置(S)", replay= "回放(P)", + save="保存(O)", resume= "继续(esc)", restart="重新开始(R)", quit= "退出(Q)", diff --git a/parts/scenes/pause.lua b/parts/scenes/pause.lua index 942dfab4..24e4db7e 100644 --- a/parts/scenes/pause.lua +++ b/parts/scenes/pause.lua @@ -140,9 +140,15 @@ function scene.keyDown(key) elseif key=="r"then resetGameData() SCN.swapTo("play","none") - elseif key=="p"and(GAME.result or GAME.replaying)and #PLAYERS==1 then - resetGameData(true) - SCN.swapTo("play","none") + elseif key=="p"then + if(GAME.result or GAME.replaying)and #PLAYERS==1 then + resetGameData(true) + SCN.swapTo("play","none") + end + elseif key=="o"then + if(GAME.result or GAME.replaying)and #PLAYERS==1 and not GAME.saved and saveRecording()then + GAME.saved=true + end end end @@ -300,7 +306,8 @@ end scene.widgetList={ WIDGET.newButton{name="setting", x=1120, y=70, w=240,h=90, color="lBlue", font=35,code=WIDGET.lnk_pressKey("s")}, - WIDGET.newButton{name="replay", x=640, y=250, w=240,h=100,color="lYellow",font=30,code=WIDGET.lnk_pressKey("p"),hide=function()return not(GAME.result or GAME.replaying)or #PLAYERS>1 end}, + WIDGET.newButton{name="replay", x=535, y=250, w=200,h=100,color="lYellow",font=30,code=WIDGET.lnk_pressKey("p"),hide=function()return not(GAME.result or GAME.replaying)or #PLAYERS>1 end}, + WIDGET.newButton{name="save", x=745, y=250, w=200,h=100,color="green", font=30,code=WIDGET.lnk_pressKey("o"),hide=function()return not(GAME.result or GAME.replaying)or #PLAYERS>1 or GAME.saved end}, WIDGET.newButton{name="resume", x=640, y=367, w=240,h=100,color="lGreen", font=30,code=WIDGET.lnk_pressKey("escape")}, WIDGET.newButton{name="restart", x=640, y=483, w=240,h=100,color="lRed", font=35,code=WIDGET.lnk_pressKey("r")}, WIDGET.newButton{name="quit", x=640, y=600, w=240,h=100,font=35,code=WIDGET.lnk_BACK},