整理代码,较复杂的单行if-then-end拆成多行

This commit is contained in:
MrZ626
2021-09-03 00:28:08 +08:00
parent 827d0cdf5a
commit 57497dbd74
66 changed files with 703 additions and 261 deletions

View File

@@ -69,7 +69,9 @@ end
local function checkBoard(b)
for i=4,1,-1 do
for j=1,4 do
if b[i][j]~=4*i+j-4 then return false end
if b[i][j]~=4*i+j-4 then
return false
end
end
end
return true

View File

@@ -119,7 +119,9 @@ local function newTile()
end
local function freshMaxTile()
maxTile=maxTile+1
if maxTile==12 then skipper.cd=0 end
if maxTile==12 then
skipper.cd=0
end
SFX.play('reach')
ins(progress,("%s - %.3fs"):format(tileName[maxTile],TIME()-startTime))
end

View File

@@ -233,7 +233,9 @@ end
function scene.mouseDown(x,y)
scene.mouseMove(x,y)
if curX then place(curX,curx)end
if curX then
place(curX,curx)
end
end
scene.widgetList={

View File

@@ -7,6 +7,14 @@ local reg--register
local val--result value
local sym--symbol
local function _autoReturn()
if reg and sym then
scene.keyDown("return")
else
reg=false
end
end
function scene.sceneInit()
BG.set('none')
BGM.stop()
@@ -27,7 +35,9 @@ function scene.keyDown(key)
val=key
else
if #val<14 then
if val=="0"then val=""end
if val=="0"then
val=""
end
val=val..key
end
end
@@ -60,19 +70,25 @@ function scene.keyDown(key)
else
val=val:sub(1,-2)
end
if val==""then val="0"end
if val==""then
val="0"
end
elseif key=="+"or key=="="and kb.isDown("lshift","rshift")then
if reg and sym then scene.keyDown("return")else reg=false end sym="+"
_autoReturn()
sym="+"
elseif key=="*"or key=="8"and kb.isDown("lshift","rshift")then
if reg and sym then scene.keyDown("return")else reg=false end sym="*"
_autoReturn()
sym="*"
elseif key=="-"then
if reg and sym then scene.keyDown("return")else reg=false end sym="-"
_autoReturn()
sym="-"
elseif key=="/"then
if reg and sym then scene.keyDown("return")else reg=false end sym="/"
_autoReturn()
sym="/"
elseif key=="return"then
if val:sub(-1)=="e"then val=val:sub(1,-2)end
val=val:gsub("e","")
if sym and reg then
if reg:sub(-1)=="e"then reg=reg:sub(1,-2)end
reg=reg:gsub("e","")
val=
sym=="+"and tostring((tonumber(reg)or 0)+tonumber(val))or
sym=="-"and tostring((tonumber(reg)or 0)-tonumber(val))or

View File

@@ -189,7 +189,9 @@ local commands={}do
commands.del={
code=function(name)
local recursive=name:sub(1,3)=="-s "
if recursive then name=name:sub(4)end
if recursive then
name=name:sub(4)
end
if name~=""then
local info=love.filesystem.getInfo(name)
@@ -240,20 +242,35 @@ local commands={}do
--Check file exist
local info
info=love.filesystem.getInfo(arg[1])
if not(info and info.type=='file')then log{C.R,("'%s' is not a file!"):format(arg[1])}return end
if not(info and info.type=='file')then
log{C.R,("'%s' is not a file!"):format(arg[1])}
return
end
info=love.filesystem.getInfo(arg[2])
if info then log{C.R,("'%s' already exists!"):format(arg[2])}return end
if info then
log{C.R,("'%s' already exists!"):format(arg[2])}
return
end
--Read file
local data,err1=love.filesystem.read('data',arg[1])
if not data then log{C.R,("Failed to read file '%s': "):format(arg[1],err1 or"Unknown error")}return end
if not data then
log{C.R,("Failed to read file '%s': "):format(arg[1],err1 or"Unknown error")}
return
end
--Write file
local res,err2=love.filesystem.write(arg[2],data)
if not res then log{C.R,("Failed to write file: "):format(err2 or"Unknown error")}return end
if not res then
log{C.R,("Failed to write file: "):format(err2 or"Unknown error")}
return
end
--Delete file
if not love.filesystem.remove(arg[1])then log{C.R,("Failed to delete old file ''"):format(arg[1])}return end
if not love.filesystem.remove(arg[1])then
log{C.R,("Failed to delete old file ''"):format(arg[1])}
return
end
log{C.Y,("Succesfully renamed file '%s' to '%s'"):format(arg[1],arg[2])}
end,
@@ -701,7 +718,9 @@ local commands={}do
if bool=="sure"then
for name,M in next,MODES do
if type(name)=='string'and not RANKS[name]and M.x then
if M.x then RANKS[name]=0 end
if M.x then
RANKS[name]=0
end
end
end
saveProgress()
@@ -896,7 +915,10 @@ local fleg={
second_box="Coming soon",
}setmetatable(fleg,{__tostring=function()return"The fl\97g."end})
function userG.the_box(k)
if k~=first_key then log"Usage:"log"*The box is locked*"return end
if k~=first_key then
log"Usage:"log"*The box is locked*"
return
end
log"*Breaking sound*"
userG.the_box,userG.the_key=nil,nil
return fleg
@@ -923,7 +945,9 @@ function scene.keyDown(key)
--Write History
ins(history,input)
if history[27]then rem(history,1)end
if history[27]then
rem(history,1)
end
hisPtr=nil
--Execute
@@ -1026,7 +1050,9 @@ function scene.keyDown(key)
SCN.back()
end
else
if not WIDGET.isFocus(inputBox)then WIDGET.focus(inputBox)end
if not WIDGET.isFocus(inputBox)then
WIDGET.focus(inputBox)
end
WIDGET.keyPressed(key)
end
end

View File

@@ -179,22 +179,30 @@ function scene.update(dt)
life1=life1*.7+life*.3
if play then
if inv>0 then inv=inv-1 end
if inv>0 then
inv=inv-1
end
score=score+dt*.04+life*.0004
life=min(life+dt*.04,1000)
if score>1000*level then
if speed<3 then speed=speed+.2 end
if speed<3 then
speed=speed+.2
end
level=level+1
SFX.play('blip_1')
end
sunH=sunH+.01
elseif menu==1 then
ct=ct+1
if ct==60 then menu=false end
if ct==60 then
menu=false
end
elseif menu==-1 then
for i=1,3 do color[i]=near(color[i],cubeColor[1][i])end
for i=1,40 do cubesY[i]=cubesY[i]-(70-ct)*.003 end
if sunH>0 then sunH=max(sunH*.85-1,0)end
if sunH>0 then
sunH=max(sunH*.85-1,0)
end
ct=ct-1
if ct==0 then
score=0

View File

@@ -86,8 +86,12 @@ function scene.update()
P.vy=P.vy*.5
end
else
if kb.isDown(P==p1 and"w"or"up")then P.vy=max(P.vy-1,-8)end
if kb.isDown(P==p1 and"s"or"down")then P.vy=min(P.vy+1,8)end
if kb.isDown(P==p1 and"w"or"up")then
P.vy=max(P.vy-1,-8)
end
if kb.isDown(P==p1 and"s"or"down")then
P.vy=min(P.vy+1,8)
end
P.y=P.y+P.vy
P.vy=P.vy*.9
if P.y>650 then

View File

@@ -36,7 +36,9 @@ function scene.update()
local v=0
for i=2,40 do v=v+i*(i-1)*.075/(t-keyTime[i])end
speed=speed*.99+v*.01
if speed>maxSpeed then maxSpeed=speed end
if speed>maxSpeed then
maxSpeed=speed
end
end
function scene.draw()

View File

@@ -161,7 +161,9 @@ function scene.keyDown(key,isRep)
end
function scene.mouseMove(x,y)
cx,cy=int((x-192)/128),int((y+88)/128)
if cx<1 or cx>5 or cy<1 or cy>5 then cx,cy=false end
if cx<1 or cx>5 or cy<1 or cy>5 then
cx,cy=false
end
end
function scene.mouseDown(x,y)
scene.mouseMove(x,y)

View File

@@ -125,7 +125,9 @@ function scene.mouseMove(x,y)
local sx,sy=int((x-200)/30)+1,20-int((y-60)/30)
if sx>=1 and sx<=10 and sy>=1 and sy<=20 then
penX,penY=sx,sy
if curPen then _pTouch(sx,sy)end
if curPen then
_pTouch(sx,sy)
end
else
penX,penY=nil
end
@@ -256,7 +258,9 @@ function scene.keyUp(key)
end
function scene.update(dt)
if sure>0 then sure=sure-dt end
if sure>0 then
sure=sure-dt
end
end
function scene.draw()

View File

@@ -117,7 +117,9 @@ function scene.keyDown(key)
end
function scene.update(dt)
if sure>0 then sure=sure-dt end
if sure>0 then
sure=sure-dt
end
end
function scene.draw()

View File

@@ -120,7 +120,9 @@ function scene.keyDown(key)
end
function scene.update(dt)
if sure>0 then sure=sure-dt end
if sure>0 then
sure=sure-dt
end
end
function scene.draw()

View File

@@ -16,7 +16,9 @@ function scene.sceneInit()
NET.wsclose_user()
NET.wsclose_play()
NET.wsclose_stream()
if SETTING then SFX.fplay('error',SETTING.voc*.8 or 0)end
if SETTING then
SFX.fplay('error',SETTING.voc*.8 or 0)
end
end
function scene.draw()

View File

@@ -194,7 +194,9 @@ end
function scene.keyDown(key,isRep)
if replaying then
if key=="space"then
if not isRep then gameRate=gameRate==0 and 1 or 0 end
if not isRep then
gameRate=gameRate==0 and 1 or 0
end
_updateRepButtons()
elseif key=="left"then
if not isRep then
@@ -215,7 +217,9 @@ function scene.keyDown(key,isRep)
elseif _checkGameKeyDown(key)then
if GAME.tasUsed then
if key=="f1"then
if not isRep then gameRate=gameRate==0 and .125 or 0 end
if not isRep then
gameRate=gameRate==0 and .125 or 0
end
_updateRepButtons()
elseif key=='f2'then
if not isRep then
@@ -307,7 +311,9 @@ function scene.update(dt)
floatGameRate=floatGameRate+gameRate
while floatGameRate>=1 do
floatGameRate=floatGameRate-1
if GAME.replaying then _update_replay(GAME.replaying)end
if GAME.replaying then
_update_replay(GAME.replaying)
end
_update_common(dt)
end
end

View File

@@ -7,7 +7,9 @@ local function _modComp(a,b)
end
local function _remMod(M)
local i=TABLE.find(GAME.mod,M)
if i then rem(GAME.mod,i)end
if i then
rem(GAME.mod,i)
end
end
local function _toggleMod(M,back)
if M.sel==0 then

View File

@@ -48,7 +48,9 @@ function scene.keyDown(key,isRep)
if key=="return"or key=="space"then
if BGM.nowPlay~=bgmList[S]then
BGM.play(bgmList[S])
if SETTING.bgm>0 then SFX.play('click')end
if SETTING.bgm>0 then
SFX.play('click')
end
else
BGM.stop()
end
@@ -66,11 +68,19 @@ function scene.draw()
setFont(50)
gc.print(bgmList[selected],320,355)
setFont(35)
if selected>1 then gc.print(bgmList[selected-1],320,350-30)end
if selected<#bgmList then gc.print(bgmList[selected+1],320,350+65)end
if selected>1 then
gc.print(bgmList[selected-1],320,350-30)
end
if selected<#bgmList then
gc.print(bgmList[selected+1],320,350+65)
end
setFont(20)
if selected>2 then gc.print(bgmList[selected-2],320,350-50)end
if selected<#bgmList-1 then gc.print(bgmList[selected+2],320,350+110)end
if selected>2 then
gc.print(bgmList[selected-2],320,350-50)
end
if selected<#bgmList-1 then
gc.print(bgmList[selected+2],320,350+110)
end
gc.draw(TEXTURE.title,840,220,nil,.5,nil,580,118)
if BGM.nowPlay then

View File

@@ -68,7 +68,9 @@ function scene.sceneInit(org)
upstreamProgress=1
newMessageTimer=0
if org=='setting_game'then NET.changeConfig()end
if org=='setting_game'then
NET.changeConfig()
end
if GAME.prevBG then
BG.set(GAME.prevBG)
GAME.prevBG=false
@@ -311,8 +313,12 @@ function scene.draw()
gc_printf(NET.roomState.roomInfo.name,0,685,1270,'right')
setFont(40)
gc_print(netPLY.getCount().."/"..NET.roomState.capacity,70,655)
if NET.roomState.private then gc_draw(IMG.lock,30,668)end
if NET.roomState.start then gc_setColor(0,1,0)gc_print(text.started,230,655)end
if NET.roomState.private then
gc_draw(IMG.lock,30,668)
end
if NET.roomState.start then
gc_setColor(0,1,0)gc_print(text.started,230,655)
end
--Profile
drawSelfProfile()

View File

@@ -29,7 +29,9 @@ local function _createRoom()
local pw=passwordBox.value
if pw==""then pw=nil end
local roomname=STRING.trim(roomNameBox.value)
if #roomname==0 then roomname=(USERS.getUsername(USER.uid)or"Anonymous").."'s room"end
if #roomname==0 then
roomname=(USERS.getUsername(USER.uid)or"Anonymous").."'s room"
end
NET.createRoom(
roomname,
descriptionBox.value,

View File

@@ -16,7 +16,9 @@ local roomList=WIDGET.newListBox{name="roomList",x=50,y=50,w=800,h=440,lineH=40,
gc_rectangle('fill',0,0,800,40)
end
gc_setColor(1,1,1)
if item.private then gc_draw(IMG.lock,10,5)end
if item.private then
gc_draw(IMG.lock,10,5)
end
gc_print(item.count.."/"..item.capacity,670,-4)
gc_setColor(.9,.9,1)

View File

@@ -73,8 +73,13 @@ function scene.sceneInit(org)
end
local f=1
for i=1,6 do
if val[i]>.5 then f=2 end
if val[i]>1 then f=3 break end
if val[i]>.5 then
f=2
end
if val[i]>1 then
f=3
break
end
end
if f==1 then chartColor,f={.4,.9,.5},1.25--Vegetable
elseif f==2 then chartColor,f={.4,.7,.9},1 --Normal
@@ -177,8 +182,12 @@ function scene.update(dt)
if not(GAME.result or GAME.replaying)then
GAME.pauseTime=GAME.pauseTime+dt
end
if timer1<50 then timer1=timer1+1 end
if timer2<25 then timer2=timer2+1 end
if timer1<50 then
timer1=timer1+1
end
if timer2<25 then
timer2=timer2+1
end
end
local hexList={1,0,.5,1.732*.5,-.5,1.732*.5}
@@ -189,7 +198,9 @@ local tasText=gc.newText(getFont(100),"TAS")
function scene.draw()
local T=timer1*.02
local T2=timer2*.04
if T<1 or GAME.result then SCN.scenes.game.draw()end
if T<1 or GAME.result then
SCN.scenes.game.draw()
end
--Dark BG
local _=T

View File

@@ -142,7 +142,9 @@ function scene.keyDown(key)
end
function scene.update(dt)
if sure>0 then sure=sure-dt end
if sure>0 then
sure=sure-dt
end
end
function scene.draw()

View File

@@ -43,7 +43,9 @@ function scene.touchDown(x,y)
end
function scene.update()
if jump>0 then jump=jump-1 end
if jump>0 then
jump=jump-1
end
end
function scene.draw()
@@ -83,7 +85,9 @@ scene.widgetList={
WIDGET.newKey{name="mute", x=1160,y=180,w=80,color='lR',fText=TEXTURE.mute,
code=function()
if SETTING.sfx+SETTING.sfx_spawn+SETTING.sfx_warn+SETTING.bgm+SETTING.vib+SETTING.voc==0 then
if not soundBeforeMute then soundBeforeMute={1,0,.4,.7,0,0}end
if not soundBeforeMute then
soundBeforeMute={1,0,.4,.7,0,0}
end
SETTING.sfx,SETTING.sfx_spawn,SETTING.sfx_warn,SETTING.bgm,SETTING.vib,SETTING.voc=unpack(soundBeforeMute)
soundBeforeMute=false
else

View File

@@ -56,7 +56,9 @@ local function _onVK_org(x,y)
return nearest
end
function scene.mouseDown(x,y,k)
if k==1 then scene.touchDown(x,y)end
if k==1 then
scene.touchDown(x,y)
end
end
function scene.mouseUp()
scene.touchUp()

View File

@@ -22,15 +22,23 @@ function scene.keyDown(key,isRep)
pc=not pc
elseif type(key)=='number'then
local CHN=VOC.getFreeChannel()
if mini then VOC.play('mini',CHN)end
if b2b then VOC.play('b2b',CHN)
elseif b3b then VOC.play('b3b',CHN)
if mini then
VOC.play('mini',CHN)
end
if b2b then
VOC.play('b2b',CHN)
elseif b3b then
VOC.play('b3b',CHN)
end
if key>=10 then
VOC.play(blockName[math.floor(key/10)].."spin",CHN)
end
if lineCount[key%10]then VOC.play(lineCount[key%10],CHN)end
if pc then VOC.play('perfect_clear',CHN)end
if lineCount[key%10]then
VOC.play(lineCount[key%10],CHN)
end
if pc then
VOC.play('perfect_clear',CHN)
end
elseif key=="tab"then
SCN.swapTo('music','none')
elseif key=="escape"then

View File

@@ -96,7 +96,9 @@ function scene.draw()
end
mDraw(TEXTURE.title_color,640,800-T,nil,.6)
mDraw(TEXTURE.title_color,640,2160-T,nil,.6)
if time>50 then gc.print("CLICK ME →",50,550,-.5)end
if time>50 then
gc.print("CLICK ME →",50,550,-.5)
end
end
scene.widgetList={