整理代码,删掉多个goto

This commit is contained in:
MrZ626
2021-03-25 02:15:49 +08:00
parent ea0d699e1b
commit 390d2a42b8
4 changed files with 97 additions and 105 deletions

View File

@@ -198,12 +198,12 @@ function love.touchreleased(id,x,y)
end
end
function love.keypressed(i)
mouseShow=false
if devMode then
if i=="f1"then PROFILE.switch()
elseif i=="f2"then LOG.print(string.format("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s",SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num))
elseif i=="f3"then
local function noDevkeyPressed(key)
if key=="f1"then
PROFILE.switch()
elseif key=="f2"then
LOG.print(string.format("System:%s[%s]\nluaVer:%s\njitVer:%s\njitVerNum:%s",SYSTEM,jit.arch,_VERSION,jit.version,jit.version_num))
elseif key=="f3"then
for _=1,8 do
local P=PLAYERS.alive[rnd(#PLAYERS.alive)]
if P~=PLAYERS[1]then
@@ -211,50 +211,54 @@ function love.keypressed(i)
P:lose()
end
end
elseif i=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
elseif i=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end
elseif i=="f6"then for k,v in next,_G do DBP(k,v)end
elseif i=="f7"then if love._openConsole then love._openConsole()end
elseif i=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow)
elseif i=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow)
elseif i=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow)
elseif i=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow)
elseif i=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow)
elseif i=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
elseif key=="f4"then if not kb.isDown("lalt","ralt")then LOG.copy()end
elseif key=="f5"then if WIDGET.sel then DBP(WIDGET.sel)end
elseif key=="f6"then for k,v in next,_G do DBP(k,v)end
elseif key=="f7"then if love._openConsole then love._openConsole()end
elseif key=="f8"then devMode=nil LOG.print("DEBUG OFF",COLOR.yellow)
elseif key=="f9"then devMode=1 LOG.print("DEBUG 1",COLOR.yellow)
elseif key=="f10"then devMode=2 LOG.print("DEBUG 2",COLOR.yellow)
elseif key=="f11"then devMode=3 LOG.print("DEBUG 3",COLOR.yellow)
elseif key=="f12"then devMode=4 LOG.print("DEBUG 4",COLOR.yellow)
elseif key=="\\"then _G["\100\114\97\119\70\87\77"]=NULL
elseif devMode==2 then
if WIDGET.sel then
local W=WIDGET.sel
if i=="left"then W.x=W.x-10
elseif i=="right"then W.x=W.x+10
elseif i=="up"then W.y=W.y-10
elseif i=="down"then W.y=W.y+10
elseif i==","then W.w=W.w-10
elseif i=="."then W.w=W.w+10
elseif i=="/"then W.h=W.h-10
elseif i=="'"then W.h=W.h+10
elseif i=="["then W.font=W.font-1
elseif i=="]"then W.font=W.font+1
else goto NORMAL
if key=="left"then W.x=W.x-10
elseif key=="right"then W.x=W.x+10
elseif key=="up"then W.y=W.y-10
elseif key=="down"then W.y=W.y+10
elseif key==","then W.w=W.w-10
elseif key=="."then W.w=W.w+10
elseif key=="/"then W.h=W.h-10
elseif key=="'"then W.h=W.h+10
elseif key=="["then W.font=W.font-1
elseif key=="]"then W.font=W.font+1
else return true
end
else
goto NORMAL
return true
end
else
goto NORMAL
return true
end
end
function love.keypressed(key)
mouseShow=false
if devMode and not noDevkeyPressed(key)then
return
end
::NORMAL::
if i=="f8"then
elseif key=="f8"then
devMode=1
LOG.print("DEBUG ON",COLOR.yellow)
elseif i=="f11"then
elseif key=="f11"then
switchFullscreen()
elseif not SCN.swapping then
if SCN.keyDown then
SCN.keyDown(key)
elseif key=="escape"then
SCN.back()
else
if SCN.swapping then return end
if SCN.keyDown then SCN.keyDown(i)
elseif i=="escape"then SCN.back()
else WIDGET.keyPressed(i)
WIDGET.keyPressed(key)
end
end
end

View File

@@ -224,8 +224,7 @@ return{
else
bn=P.holdQueue[1]and P.holdQueue[1].id or P.nextQueue[1]and P.nextQueue[1].id
end
if not bn then goto continue end
if bn then
for dir=0,dirCount[bn]do--Each dir
local cb=BLOCKS[bn][dir]
for cx=1,11-#cb[1]do--Each pos
@@ -254,7 +253,7 @@ return{
resetField(field_org,Tfield,cy)
end
end
::continue::
end
end
if not best.bn then return 1 end

View File

@@ -79,14 +79,14 @@ local loadingThread=coroutine.create(function()
{"rect","fill",10,4,-2,23},
{"poly","fill",10,4,24,10,10,16.5},
{"rect","fill",4,24,10,3},
}
}YIELD()
modeIcons.tsd=DOGC{64,64,
{"rect","fill",7,7,16,16},
{"rect","fill",7,41,16,16},
{"rect","fill",41,41,16,16},
{"move",.5,.5},
{"poly","line",7,24,56,24,56,39,39,39,39,56,24,56,24,39,7,39},
}
}YIELD()
modeIcons.infinite=DOGC{64,64,
{"wid",4},
{"circ","line",32,32,28},
@@ -97,7 +97,7 @@ local loadingThread=coroutine.create(function()
{"rect","fill",7,30,4,4},
{"rect","fill",52,30,4,4},
{"rect","fill",30,52,4,4},
}
}YIELD()
modeIcons.t49=DOGC{64,64,
{"wid",2},
{"rect","line",05,05,10,20},{"rect","line",49,05,10,20},
@@ -105,7 +105,7 @@ local loadingThread=coroutine.create(function()
{"rect","line",20,10,23,43},
{"rgb",1,1,1,.7},
{"rect","fill",20,10,23,43},
}
}YIELD()
modeIcons.t99=DOGC{64,64,
{"wid",2},
{"rect","line",02,02,6,12},{"rect","line",11,02,6,12},
@@ -119,7 +119,7 @@ local loadingThread=coroutine.create(function()
{"rect","line",20,10,23,43},
{"rgb",1,1,1,.7},
{"rect","fill",20,10,23,43},
}
}YIELD()
upFloor()
for i=1,#MODES do
@@ -248,19 +248,10 @@ function scene.update(dt)
if not locked then
if progress<25 then
local p=progress
::again::
if loadingThread then
repeat
assert(coroutine.resume(loadingThread))
else
return
end
if skip>0 then
if progress==p then
goto again
else
skip=skip-1
end
end
until not loadingThread or skip<=0 or progress~=p
if skip>0 then skip=skip-1 end
else
openTime=openTime+dt
if skip>0 then

View File

@@ -194,6 +194,15 @@ local baseRankColor={
{.85,.8,.3,.3},
{.4,.7,.4,.3},
}
local function drawModeShape(M,S,drawType)
if M.shape==1 then--Rectangle
gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S)
elseif M.shape==2 then--Diamond
gc.circle(drawType,M.x,M.y,S+12,4)
elseif M.shape==3 then--Octagon
gc.circle(drawType,M.x,M.y,S+6,8)
end
end
function scene.draw()
local _
gc.push("transform")
@@ -225,22 +234,11 @@ function scene.draw()
local rank=R[name]
local S=M.size
--Frame & fill
--Draw shapes on map
gc.setColor(baseRankColor[rank])
local drawType="fill"
::again::
if M.shape==1 then--Rectangle
gc.rectangle(drawType,M.x-S,M.y-S,2*S,2*S)
elseif M.shape==2 then--Diamond
gc.circle(drawType,M.x,M.y,S+12,4)
elseif M.shape==3 then--Octagon
gc.circle(drawType,M.x,M.y,S+6,8)
end
if drawType=="fill"then
drawModeShape(M,S,"fill")
gc.setColor(1,1,sel==name and 0 or 1)
drawType="line"
goto again
end
drawModeShape(M,S,"line")
--Icon
local icon=M.icon