整理代码,调整local函数名规范(较边缘的代码不必遵守,比如外部的库和小程序):

特别临时性的用全大写字母缩写或者单字母
TASK模块用到的任务函数和检查函数开头分别为task_和check_
其他函数开头添加下划线作为指示
This commit is contained in:
MrZ626
2021-08-25 02:40:01 +08:00
parent ee55055385
commit 8f910f95f4
40 changed files with 470 additions and 466 deletions

View File

@@ -14,7 +14,7 @@ local repRateStrings={[0]="pause",[.125]="0.125x",[.5]="0.5x",[1]="1x",[2]="2x",
local scene={}
local function updateMenuButtons()
local function _updateMenuButtons()
WIDGET.active.restart.hide=replaying
local pos=(tasMode or replaying)and'right'or SETTING.menuPos
@@ -32,7 +32,7 @@ local function updateMenuButtons()
modeTextPos=1200-drawableText.modeName:getWidth()
end
end
local function updateRepButtons()
local function _updateRepButtons()
local L=scene.widgetList
if replaying or tasMode then
for i=1,6 do L[i].hide=false end L[7].hide=true
@@ -54,64 +54,64 @@ local function updateRepButtons()
for i=1,7 do L[i].hide=true end
end
end
local function speedUp()
local function _speedUp()
if gameRate==.125 then gameRate=.5
elseif gameRate==.5 then gameRate=1
elseif gameRate==1 then gameRate=2
elseif gameRate==2 then gameRate=5
end
updateRepButtons()
_updateRepButtons()
end
local function speedDown()
local function _speedDown()
if gameRate==.5 then gameRate=.125
elseif gameRate==1 then gameRate=.5
elseif gameRate==2 then gameRate=1
elseif gameRate==5 then gameRate=2
end
updateRepButtons()
_updateRepButtons()
end
local function _rep0()
scene.widgetList[1].hide=true
scene.widgetList[7].hide=false
gameRate=0
updateRepButtons()
_updateRepButtons()
end
local function _repP8()
scene.widgetList[2].hide=true
gameRate=.125
updateRepButtons()
_updateRepButtons()
end
local function _repP2()
scene.widgetList[3].hide=true
gameRate=.5
updateRepButtons()
_updateRepButtons()
end
local function _rep1()
scene.widgetList[4].hide=true
gameRate=1
updateRepButtons()
_updateRepButtons()
end
local function _rep2()
scene.widgetList[5].hide=true
gameRate=2
updateRepButtons()
_updateRepButtons()
end
local function _rep5()
scene.widgetList[6].hide=true
gameRate=5
updateRepButtons()
_updateRepButtons()
end
local function _step()floatGameRate=floatGameRate+1 end
local function restart()
local function _restart()
resetGameData(PLAYERS[1].frameRun<240 and'q')
noKey=replaying
noTouch=replaying
tasMode=false
floatGameRate,gameRate=0,1
updateRepButtons()
_updateRepButtons()
end
local function checkGameKeyDown(key)
local function _checkGameKeyDown(key)
local k=keyMap.keyboard[key]
if k then
if k>0 then
@@ -120,7 +120,7 @@ local function checkGameKeyDown(key)
VK.press(k)
return
elseif not GAME.fromRepMenu then
restart()
_restart()
return
end
end
@@ -148,8 +148,8 @@ function scene.sceneInit(org)
end
end
updateRepButtons()
updateMenuButtons()
_updateRepButtons()
_updateMenuButtons()
end
scene.mouseDown=NULL
@@ -198,16 +198,16 @@ function scene.keyDown(key,isRep)
if replaying then
if key=="space"then
if not isRep then gameRate=gameRate==0 and 1 or 0 end
updateRepButtons()
_updateRepButtons()
elseif key=="left"then
if not isRep then
speedDown()
_speedDown()
end
elseif key=="right"then
if gameRate==0 then
_step()
elseif not isRep then
speedUp()
_speedUp()
end
elseif key=="escape"then
pauseGame()
@@ -215,20 +215,20 @@ function scene.keyDown(key,isRep)
else
if isRep then
return
elseif checkGameKeyDown(key)then
elseif _checkGameKeyDown(key)then
if tasMode then
if key=="f1"then
if not isRep then gameRate=gameRate==0 and .125 or 0 end
updateRepButtons()
_updateRepButtons()
elseif key=='f2'then
if not isRep then
speedDown()
_speedDown()
end
elseif key=='f3'then
if gameRate==0 then
_step()
elseif not isRep then
speedUp()
_speedUp()
end
end
end
@@ -256,7 +256,7 @@ function scene.gamepadDown(key)
PLAYERS[1]:pressKey(k)
VK.press(k)
else
restart()
_restart()
end
elseif key=="back"then
pauseGame()
@@ -273,7 +273,7 @@ function scene.gamepadUp(key)
end
end
local function update_replay(repPtr)
local function _update_replay(repPtr)
local P1=PLAYERS[1]
local L=GAME.rep
while P1.frameRun==L[repPtr]do
@@ -290,7 +290,7 @@ local function update_replay(repPtr)
end
GAME.replaying=repPtr
end
local function update_common(dt)
local function _update_common(dt)
--Update control
touchMoveLastFrame=false
VK.update()
@@ -310,13 +310,13 @@ function scene.update(dt)
floatGameRate=floatGameRate+gameRate
while floatGameRate>=1 do
floatGameRate=floatGameRate-1
if GAME.replaying then update_replay(GAME.replaying)end
update_common(dt)
if GAME.replaying then _update_replay(GAME.replaying)end
_update_common(dt)
end
end
local tasText=gc.newText(getFont(100),"TAS")
local function drawAtkPointer(x,y)
local function _drawAtkPointer(x,y)
local t=TIME()
local a=t*3%1*.8
t=sin(t*20)
@@ -358,12 +358,12 @@ function scene.draw()
end
if P.atkMode~=4 then
if P.atking then
drawAtkPointer(P.atking.centerX,P.atking.centerY)
_drawAtkPointer(P.atking.centerX,P.atking.centerY)
end
else
for i=1,#P.atker do
local p=P.atker[i]
drawAtkPointer(p.centerX,p.centerY)
_drawAtkPointer(p.centerX,p.centerY)
end
end
end
@@ -393,7 +393,7 @@ scene.widgetList={
WIDGET.newKey{name="rep2", x=300,y=50,w=60,code=_rep2,fText=TEXTURE.rep.rep2},
WIDGET.newKey{name="rep5", x=365,y=50,w=60,code=_rep5,fText=TEXTURE.rep.rep5},
WIDGET.newKey{name="step", x=430,y=50,w=60,code=_step,fText=TEXTURE.rep.step},
WIDGET.newKey{name="restart", x=0,y=45,w=60,code=restart,fText=TEXTURE.game.restart},
WIDGET.newKey{name="restart", x=0,y=45,w=60,code=_restart,fText=TEXTURE.game.restart},
WIDGET.newKey{name="pause", x=0,y=45,w=60,code=pauseGame,fText=TEXTURE.game.pause},
}