录像保存初版(读取回放还没做)
This commit is contained in:
1
main.lua
1
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",
|
||||
|
||||
@@ -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
|
||||
@@ -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={}
|
||||
@@ -237,6 +237,7 @@ return{
|
||||
pause={
|
||||
setting="Settings (S)",
|
||||
replay="Replay (P)",
|
||||
save="Save (O)",
|
||||
resume="Resume (esc)",
|
||||
restart="Retry (R)",
|
||||
quit="Quit (Q)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -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)",
|
||||
|
||||
@@ -127,6 +127,7 @@ return{
|
||||
pause={
|
||||
setting="_?_ (S)",
|
||||
replay="## (P)",
|
||||
save="0101 (O)",
|
||||
resume="!! (esc)",
|
||||
restart="_→_ (R)",
|
||||
quit="X (Q)",
|
||||
|
||||
@@ -240,6 +240,7 @@ return{
|
||||
pause={
|
||||
setting="设置(S)",
|
||||
replay= "回放(P)",
|
||||
save="保存(O)",
|
||||
resume= "继续(esc)",
|
||||
restart="重新开始(R)",
|
||||
quit= "退出(Q)",
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user