整理操作GAME变量的代码,新增录像回放菜单(需要后续测试)

This commit is contained in:
MrZ626
2021-06-27 02:51:45 +08:00
parent 563d820fbe
commit 0f3c234ca0
10 changed files with 175 additions and 10 deletions

View File

@@ -224,26 +224,29 @@ function applyCustomGame()--Apply CUSTOMENV, BAG, MISSION
GAME.modeEnv.mission=nil
end
end
function loadGame(M,ifQuickPlay,ifNet)--Load a mode and go to game scene
function loadGame(mode,ifQuickPlay,ifNet)--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]
if MODES[mode].score then STAT.lastPlay=mode end
GAME.curModeName=mode
GAME.curMode=MODES[mode]
GAME.modeEnv=GAME.curMode.env
GAME.init=true
GAME.net=ifNet
if ifNet then
SCN.go('net_game','swipeD')
else
drawableText.modeName:set((text.modes[M][1]or M).." "..(text.modes[M][2]or""))
drawableText.modeName:set((text.modes[mode][1]or mode).." "..(text.modes[mode][2]or""))
SCN.go('game',ifQuickPlay and'swipeD'or'fade_togame')
SFX.play('enter')
end
end
end
function gameOver()--Save record
if GAME.replaying then return end
if GAME.replaying then
local R=GAME.curMode.getRank(PLAYERS[1])
if R>0 then GAME.rank=R end
end
trySave()
local M=GAME.curMode
@@ -446,6 +449,7 @@ do--function resetGameData(args)
trySave()
GAME.result=false
GAME.rank=0
GAME.warnLVL0=0
GAME.warnLVL=0
if args:find'r'then
@@ -463,7 +467,6 @@ do--function resetGameData(args)
GAME.recording=true
GAME.statSaved=false
GAME.replaying=false
GAME.rank=0
math.randomseed(TIME())
end

View File

@@ -159,7 +159,7 @@ GAME={--Global game data
net=false, --If play net game
result=false, --Game result (string)
rank=false, --Rank reached
rank=0, --Rank reached
pauseTime=0, --Time paused
pauseCount=0, --Pausing count
warnLVL0=0, --Warning level

View File

@@ -71,6 +71,8 @@ return{
highScore="Personal Bests",
newRecord="New Record!",
replayBroken="Cannot load replay",
getNoticeFail="Failed fetching announcements...",
oldVersion="Version $1 is now available!",
needUpdate="Newer version required!",

View File

@@ -69,6 +69,8 @@ return{
highScore="Mejores puntajes",
newRecord="¡Nuevo Récord!",
-- replayBroken="Cannot load replay",
getNoticeFail="Error al buscar novedades.",
oldVersion="¡Está disponible la nueva versión $1!",
versionNotMatch="¡Las versiones no coinciden!",

View File

@@ -70,6 +70,8 @@ return{
highScore="Records personnels",
newRecord="Nouveau record !",
-- replayBroken="Cannot load replay",
getNoticeFail="Echec de l'obtention de la notice",
oldVersion="La version $1 est disponible !",
-- versionNotMatch="Version do not match!",

View File

@@ -70,6 +70,8 @@ return{
highScore="Melhor pessoal",
newRecord="Novo recorde",
-- replayBroken="Cannot load replay",
getNoticeFail="Não conseguiu ter anúncios",
oldVersion="Versão $1 esta disponível agora!",
-- versionNotMatch="Version do not match!",

View File

@@ -54,6 +54,8 @@ return{
highScore="__&:",
newRecord="^!!!^",
replayBroken=">x.",
errorMsg="An e??o? h@s occ^__ed @nd Techmino n__ds to r_st@rt.\n&**o* in#o h@$ b==n cre@ted, @nd y0u c@n $&nd it to the @uth0r.",
pauseStat={

View File

@@ -71,6 +71,8 @@ return{
highScore="最佳成绩",
newRecord="打破纪录",
replayBroken="无法加载该录像",
getNoticeFail="拉取公告失败",
oldVersion="最新版本$1可以下载了!",
needUpdate="请更新游戏!",

View File

@@ -310,7 +310,7 @@ end
scene.widgetList={
WIDGET.newButton{name="setting", x=1120,y=70,w=240,h=90, color='lB',code=pressKey"s"},
WIDGET.newButton{name="replay", x=535,y=250,w=200,h=100,color='lY',code=pressKey"p",hideF=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='G',code=pressKey"o",hideF=function()return not(GAME.result or GAME.replaying)or #PLAYERS>1 or GAME.saved end},
WIDGET.newButton{name="save", x=745,y=250,w=200,h=100,color='lP',code=pressKey"o",hideF=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='lG',code=pressKey"escape"},
WIDGET.newButton{name="restart", x=640,y=483,w=240,h=100,color='lR',code=pressKey"r"},
WIDGET.newButton{name="quit", x=640,y=600,w=240,h=100,font=35,code=backScene},

View File

@@ -1,15 +1,165 @@
local gc=love.graphics
local gc_setColor=gc.setColor
local gc_draw,gc_rectangle=gc.draw,gc.rectangle
local gc_print,gc_printf=gc.print,gc.printf
local setFont=setFont
local listBox=WIDGET.newListBox{name="list",x=50,y=50,w=1200,h=520,lineH=40,drawF=function(rep,id,ifSel)
if ifSel then
gc_setColor(1,1,1,.3)
gc_rectangle('fill',0,0,1200,40)
end
setFont(30)
gc_setColor(.8,.8,.8)
gc_print(id,10,-2)
if rep.available then
gc_setColor(.9,.9,1)
gc_print(rep.modeName,405,-2)
setFont(20)
gc_setColor(1,1,.8)
gc_print(rep.date,80,6)
gc_setColor(1,.4,.4,.6)
gc_printf(rep.version,0,6,1190,'right')
gc_setColor(1,1,1)
gc_printf(rep.player,0,6,960,'right')
else
gc_setColor(.6,.6,.6)
gc_print(rep.fileName,80,-2)
end
end}
local scene={}
local sure
local function readLine(str)
local p=str:find("\n")
return str:sub(1,p-1),str:sub(p+1)
end
local function replay(rep)
if not rep.available then
MES.new('error',text.replayBroken)
elseif MODES[rep.mode]then
local data=love.data.decompress('string','zlib',rep.data)
local seed,setting,mod
seed,data=readLine(data)
GAME.seed=tonumber(seed)
setting,data=readLine(data)
GAME.setting=JSON.decode(setting)
mod,data=readLine(data)
GAME.mod=JSON.decode(mod)
GAME.rep={}
DATA.pumpRecording(data,GAME.rep)
loadGame(rep.mode,true)
resetGameData('r')
GAME.init=false
GAME.saved=true
else
MES.new('error',("No mode id: [%s]"):format(rep.mode))
end
end
function scene.sceneInit()
sure=0
local repList={}
for i=#REPLAY,1,-1 do
local file=love.filesystem.newFile(REPLAY[i])
if file:open('r')then
local metadata=""
local enter=0
while true do
local b,len=file:read(1)
if len==0 then
file:close()
repList[i]={
fileName=REPLAY[i],
available=false,
}
break
end
metadata=metadata..b
if b=="\n"then
enter=enter+1
if enter==4 then
metadata=STRING.split(metadata,'\n')
local mode=text.modes[metadata[2]]or{"["..metadata[2].."]",""}
repList[i]={
fileName=REPLAY[i],
available=true,
date=metadata[1],
mode=metadata[2],
modeName=("%s %s"):format(mode[1],mode[2]),
version=metadata[3],
player=metadata[4],
data=file:read(),
}
file:close()
break
end
end
end
else
repList[i]={
fileName=REPLAY[i],
available=false,
}
end
end
listBox:setList(repList)
end
function scene.keyDown(key)
if key=="return"then
replay(listBox:getSel())
elseif key=="escape"then
SCN.back()
elseif key=="delete"then
if sure>20 then
local rep=listBox:getSel()
if rep then
sure=0
listBox:remove()
love.filesystem.remove(rep.fileName)
local i=TABLE.find(REPLAY,rep.fileName)
if i then table.remove(REPLAY,i)end
FILE.save(REPLAY,'conf/replay')
SFX.play('finesseError',.7)
end
else
sure=50
end
else
WIDGET.keyPressed(key)
end
end
function scene.update()
if sure>0 then sure=sure-1 end
end
function scene.draw()
--Confirm delete
if sure>0 then
gc_setColor(1,1,1,sure*.02)
gc_draw(TEXTURE.sure,910,610)
end
end
scene.widgetList={
WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
listBox,
WIDGET.newButton{name="play",x=700,y=640,w=170,h=80,color='lY',code=pressKey"return",hideF=function()return listBox:getLen()==0 end,fText=DOGC{50,50,{'fPoly',10,0,49,24,10,49}}},
WIDGET.newButton{name="delete",x=850,y=640,w=80,h=80,color='lR',code=pressKey"delete",hideF=function()return listBox:getLen()==0 end,fText=DOGC{50,50,{'setLW',8},{'line',5,5,45,45},{'line',5,45,45,5}}},
WIDGET.newButton{name="back",x=1140,y=640,w=170,h=80,fText=TEXTURE.back,code=backScene},
}
return scene