整理代码,调整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

@@ -60,7 +60,7 @@ local gridLines do
end
local LDmarks=gc.newSpriteBatch(GC.DO{14,5,{'fRect',0,0,14,5,3}},15,'static')
for i=0,14 do LDmarks:add(3+20*i,615)end
local function boardTransform(mode)
local function _boardTransform(mode)
if mode then
if mode=="U-D"then
gc_translate(0,590)
@@ -74,8 +74,8 @@ local function boardTransform(mode)
end
end
end
local function stencilBoard()gc_rectangle('fill',0,-10,300,610)end
local function applyField(P)
local function _stencilBoard()gc_rectangle('fill',0,-10,300,610)end
local function _applyField(P)
gc_push('transform')
--Apply fieldOffset
@@ -90,21 +90,21 @@ local function applyField(P)
end
--Apply stencil
gc_stencil(stencilBoard)
gc_stencil(_stencilBoard)
gc_setStencilTest('equal',1)
--Move camera
gc_push('transform')
boardTransform(P.gameEnv.flipBoard)
_boardTransform(P.gameEnv.flipBoard)
gc_translate(0,P.fieldBeneath+P.fieldUp)
end
local function cancelField()
local function _cancelField()
gc_setStencilTest()
gc_pop()
gc_pop()
end
local function drawRow(texture,h,V,L,showInvis)
local function _drawRow(texture,h,V,L,showInvis)
local t=TIME()*4
for i=1,10 do
if L[i]>0 then
@@ -118,7 +118,7 @@ local function drawRow(texture,h,V,L,showInvis)
end
end
end
local function drawField(P,showInvis)
local function _drawField(P,showInvis)
local ENV=P.gameEnv
local V,F=P.visTime,P.field
local start=int((P.fieldBeneath+P.fieldUp)/30+1)
@@ -128,14 +128,14 @@ local function drawField(P,showInvis)
gc_setShader(shader_lighter)
gc_translate(0,-4)
--<drawRow>
for j=start,min(start+21,#F)do drawRow(texture,j,V[j],F[j])end
for j=start,min(start+21,#F)do _drawRow(texture,j,V[j],F[j])end
--</drawRow>
gc_setShader(shader_fieldSatur)
gc_translate(0,4)
end
--<drawRow>
for j=start,min(start+21,#F)do drawRow(texture,j,V[j],F[j],showInvis)end
for j=start,min(start+21,#F)do _drawRow(texture,j,V[j],F[j],showInvis)end
--</drawRow>
else--With falling animation
local stepY=ENV.smooth and(P.falling/(ENV.fall+1))^1.6*30 or 30
@@ -151,7 +151,7 @@ local function drawField(P,showInvis)
h=h+1
gc_translate(0,-stepY)
end
drawRow(texture,j,V[j],F[j])
_drawRow(texture,j,V[j],F[j])
end
--</drawRow>
gc_setShader(shader_fieldSatur)
@@ -168,14 +168,14 @@ local function drawField(P,showInvis)
gc_setColor(1,1,1,alpha)
gc_rectangle('fill',0,30-30*j,300,stepY)
end
drawRow(texture,j,V[j],F[j],showInvis)
_drawRow(texture,j,V[j],F[j],showInvis)
end
--</drawRow>
gc_pop()
end
gc_setShader()
end
local function drawFXs(P)
local function _drawFXs(P)
--LockFX
for i=1,#P.lockFX do
local S=P.lockFX[i]
@@ -268,7 +268,7 @@ local drawGhost={
end end
end,
}
local function drawBlockOutline(CB,curX,curY,texture,trans)
local function _drawBlockOutline(CB,curX,curY,texture,trans)
shader_alpha:send('a',trans)
gc_setShader(shader_alpha)
for i=1,#CB do for j=1,#CB[1]do
@@ -283,7 +283,7 @@ local function drawBlockOutline(CB,curX,curY,texture,trans)
end end
gc_setShader()
end
local function drawBlockShade(CB,curX,curY,alpha)
local function _drawBlockShade(CB,curX,curY,alpha)
gc_setColor(1,1,1,alpha)
for i=1,#CB do for j=1,#CB[1]do
if CB[i][j]then
@@ -291,7 +291,7 @@ local function drawBlockShade(CB,curX,curY,alpha)
end
end end
end
local function drawBlock(CB,curX,curY,texture)
local function _drawBlock(CB,curX,curY,texture)
gc_setColor(1,1,1)
gc_setShader(shader_blockSatur)
for i=1,#CB do for j=1,#CB[1]do
@@ -301,7 +301,7 @@ local function drawBlock(CB,curX,curY,texture)
end end
gc_setShader()
end
local function drawNextPreview(B,fieldH,fieldBeneath)
local function _drawNextPreview(B,fieldH,fieldBeneath)
gc_setColor(1,1,1,.8)
local y=int(fieldH+1-modf(B.rs.centerPos[B.id][B.dir][1]))+ceil(fieldBeneath/30)
B=B.bk
@@ -313,7 +313,7 @@ local function drawNextPreview(B,fieldH,fieldBeneath)
end
end end
end
local function drawBuffer(atkBuffer,bufferWarn,atkBufferSum1,atkBufferSum)
local function _drawBuffer(atkBuffer,bufferWarn,atkBufferSum1,atkBufferSum)
local h=0
for i=1,#atkBuffer do
local A=atkBuffer[i]
@@ -368,7 +368,7 @@ local function drawBuffer(atkBuffer,bufferWarn,atkBufferSum1,atkBufferSum)
end
end
end
local function drawB2Bbar(b2b,b2b1)
local function _drawB2Bbar(b2b,b2b1)
local a,b=b2b,b2b1
if a>b then a,b=b,a end
if b>0 then
@@ -382,7 +382,7 @@ local function drawB2Bbar(b2b,b2b1)
end
end
end
local function drawLDI(easyFresh,length,freshTime)--Lock Delay Indicator
local function _drawLDI(easyFresh,length,freshTime)--Lock Delay Indicator
if easyFresh then
gc_setColor(.97,.97,.97)
else
@@ -396,7 +396,7 @@ local function drawLDI(easyFresh,length,freshTime)--Lock Delay Indicator
gc_draw(LDmarks)
end
end
local function drawHold(holdQueue,holdCount,holdTime,skinLib)
local function _drawHold(holdQueue,holdCount,holdTime,skinLib)
local N=holdCount*72
gc_push('transform')
gc_translate(12,20)
@@ -425,7 +425,7 @@ local function drawHold(holdQueue,holdCount,holdTime,skinLib)
gc_pop()
gc_pop()
end
local function drawDial(x,y,speed)
local function _drawDial(x,y,speed)
gc_setColor(1,1,1,.7)
gc_draw(dialFrame,x,y)
gc_setColor(1,1,1,.3)
@@ -433,7 +433,7 @@ local function drawDial(x,y,speed)
gc_setColor(.9,.9,.91)
setFont(30)mStr(int(speed),x+40,y+19)
end
local function drawFinesseCombo_norm(P)
local function _drawFinesseCombo_norm(P)
if P.finesseCombo>2 then
local S=P.stat
local t=P.finesseComboTime
@@ -454,7 +454,7 @@ local function drawFinesseCombo_norm(P)
gc_print(str,20,600,nil,1+t*.08,nil,0,30)
end
end
local function drawFinesseCombo_remote(P)
local function _drawFinesseCombo_remote(P)
if P.finesseCombo>2 then
local S=P.stat
if S.finesseRate==5*S.piece then
@@ -467,7 +467,7 @@ local function drawFinesseCombo_remote(P)
gc_print(P.finesseCombo.."x",20,570)
end
end
local function drawLife(life)
local function _drawLife(life)
gc_setColor(.97,.97,.97)
gc_draw(IMG.lifeIcon,475,595,nil,.8)
if life>3 then
@@ -478,7 +478,7 @@ local function drawLife(life)
if life>2 then gc_draw(IMG.lifeIcon,525,595,nil,.8)end
end
end
local function drawMission(curMission,L,missionkill)
local function _drawMission(curMission,L,missionkill)
--Draw current mission
setFont(35)
if missionkill then
@@ -500,7 +500,7 @@ local function drawMission(curMission,L,missionkill)
end
end
end
local function drawStartCounter(time)
local function _drawStartCounter(time)
time=179-time
gc_push('transform')
gc_translate(300,300)
@@ -524,8 +524,8 @@ end
local draw={}
draw.drawGhost=drawGhost
draw.applyField=applyField
draw.cancelField=cancelField
draw.applyField=_applyField
draw.cancelField=_cancelField
function draw.drawNext_norm(P,repMode)
local ENV=P.gameEnv
local texture=P.skinLib
@@ -653,11 +653,11 @@ function draw.drawTargetLine(P,r)
if r<=20+(P.fieldBeneath+P.fieldUp+10)/30 and r>0 then
gc_setLineWidth(3)
gc_setColor(1,r>10 and 0 or .2+.8*rnd(),.5)
applyField(P)
_applyField(P)
r=600-30*r
if P.falling~=-1 then r=r-#P.clearingRow*(P.gameEnv.smooth and(P.falling/(P.gameEnv.fall+1))^1.6*30 or 30)end
gc_line(0,r,300,r)
cancelField()
_cancelField()
end
end
function draw.drawProgress(s1,s2)
@@ -699,13 +699,13 @@ function draw.norm(P,repMode)
--Draw HUD
P:drawNext(repMode)
if P.curMission then drawMission(P.curMission,ENV.mission,ENV.missionKill)end
if ENV.holdCount>0 then drawHold(P.holdQueue,ENV.holdCount,P.holdTime,P.skinLib)end
drawDial(499,505,P.dropSpeed)
if P.life>0 then drawLife(P.life)end
if P.curMission then _drawMission(P.curMission,ENV.mission,ENV.missionKill)end
if ENV.holdCount>0 then _drawHold(P.holdQueue,ENV.holdCount,P.holdTime,P.skinLib)end
_drawDial(499,505,P.dropSpeed)
if P.life>0 then _drawLife(P.life)end
--Field-related things
applyField(P)
_applyField(P)
--Fill field
gc_setColor(0,0,0,.6)
gc_rectangle('fill',0,-10-camDY,300,610)
@@ -727,7 +727,7 @@ function draw.norm(P,repMode)
end
--Draw field
drawField(P,repMode)
_drawField(P,repMode)
--Draw line number
if ENV.fieldH>20 and ENV.lineNum then
@@ -756,7 +756,7 @@ function draw.norm(P,repMode)
gc_rectangle('fill',0,-ENV.heightLimit*30-FBN-2,300,4)
--Draw FXs
drawFXs(P)
_drawFXs(P)
--Draw current block
if P.cur and P.waiting==-1 then
@@ -783,21 +783,21 @@ function draw.norm(P,repMode)
gc_translate(0,-dy)
--Draw block & rotation center
if ENV.block then
drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],trans)
drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
_drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],trans)
_drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
if centerDisp then
gc_setColor(1,1,1,ENV.center)
gc_draw(C.rs.centerTex,centerX,-30*(P.curY+centerPos[1])+10)
end
elseif repMode then
drawBlockShade(P.cur.bk,P.curX,P.curY,trans*.3)
_drawBlockShade(P.cur.bk,P.curX,P.curY,trans*.3)
end
gc_translate(0,dy)
end
--Draw next preview
if ENV.nextPos and P.nextQueue[1]then
drawNextPreview(P.nextQueue[1],ENV.fieldH,P.fieldBeneath)
_drawNextPreview(P.nextQueue[1],ENV.fieldH,P.fieldBeneath)
end
--Draw AI's drop destination
@@ -833,9 +833,9 @@ function draw.norm(P,repMode)
--Draw Frame and buffers
gc_setColor(P.frameColor)
gc_draw(playerBoarder,-17,-12)
drawBuffer(P.atkBuffer,ENV.bufferWarn,P.atkBufferSum1,P.atkBufferSum)
drawB2Bbar(P.b2b,P.b2b1)
drawLDI(ENV.easyFresh,P.lockDelay/ENV.lock,P.freshTime)
_drawBuffer(P.atkBuffer,ENV.bufferWarn,P.atkBufferSum1,P.atkBufferSum)
_drawB2Bbar(P.b2b,P.b2b1)
_drawLDI(ENV.easyFresh,P.lockDelay/ENV.lock,P.freshTime)
--Draw target selecting pad
if GAME.modeEnv.royaleMode then
@@ -888,7 +888,7 @@ function draw.norm(P,repMode)
gc_print(tm,20,540)
--FinesseCombo
;(P.type=='remote'and drawFinesseCombo_remote or drawFinesseCombo_norm)(P)
;(P.type=='remote'and _drawFinesseCombo_remote or _drawFinesseCombo_norm)(P)
--Mode informations
if GAME.curMode.mesDisp then
@@ -896,7 +896,7 @@ function draw.norm(P,repMode)
GAME.curMode.mesDisp(P,repMode)
end
if P.frameRun<180 then drawStartCounter(P.frameRun)end
if P.frameRun<180 then _drawStartCounter(P.frameRun)end
gc_pop()
end
function draw.small(P)
@@ -963,21 +963,21 @@ function draw.demo(P)
gc_scale(P.size)
gc_translate(-150,0)
applyField(P)
_applyField(P)
gc_setStencilTest()
gc_setColor(0,0,0,.6)
gc_rectangle('fill',0,0,300,600,3)
gc_push('transform')
gc_translate(0,600)
drawField(P)
drawFXs(P)
_drawField(P)
_drawFXs(P)
if P.cur and P.waiting==-1 then
if ENV.ghost then drawGhost[ENV.ghostType](P.cur.bk,P.curX,P.ghoY,ENV.ghost,P.skinLib,curColor)end
if ENV.block then
local dy=ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0
gc_translate(0,-dy)
drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],P.lockDelay/ENV.lock)
drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
_drawBlockOutline(P.cur.bk,P.curX,P.curY,P.skinLib[curColor],P.lockDelay/ENV.lock)
_drawBlock(P.cur.bk,P.curX,P.curY,P.skinLib[curColor])
gc_translate(0,dy)
end
end

View File

@@ -17,7 +17,7 @@ local modeDataMeta do
__newindex=function(self,k,v)rawset(self,k,v)end,
}
end
local function getNewStatTable()
local function _getNewStatTable()
local T={
time=0,frame=0,score=0,
key=0,rotate=0,hold=0,
@@ -37,17 +37,17 @@ local function getNewStatTable()
end
return T
end
local function pressKey(P,keyID)
local function _pressKey(P,keyID)
if P.keyAvailable[keyID]and P.alive then
P.keyPressing[keyID]=true
P.actList[keyID](P)
P.stat.key=P.stat.key+1
end
end
local function releaseKey(P,keyID)
local function _releaseKey(P,keyID)
P.keyPressing[keyID]=false
end
local function pressKey_Rec(P,keyID)
local function _pressKey_Rec(P,keyID)
if P.keyAvailable[keyID]and P.alive then
local L=GAME.rep
ins(L,P.frameRun)
@@ -57,13 +57,13 @@ local function pressKey_Rec(P,keyID)
P.stat.key=P.stat.key+1
end
end
local function releaseKey_Rec(P,keyID)
local function _releaseKey_Rec(P,keyID)
local L=GAME.rep
ins(L,P.frameRun)
ins(L,32+keyID)
P.keyPressing[keyID]=false
end
local function newEmptyPlayer(id,mini)
local function _newEmptyPlayer(id,mini)
local P={id=id}
PLAYERS[id]=P
PLY_ALIVE[id]=P
@@ -73,11 +73,11 @@ local function newEmptyPlayer(id,mini)
--Set key/timer event
if P.id==1 and GAME.recording then
P.pressKey=pressKey_Rec
P.releaseKey=releaseKey_Rec
P.pressKey=_pressKey_Rec
P.releaseKey=_releaseKey_Rec
else
P.pressKey=pressKey
P.releaseKey=releaseKey
P.pressKey=_pressKey
P.releaseKey=_releaseKey
end
P.update=ply_update.alive
@@ -112,7 +112,7 @@ local function newEmptyPlayer(id,mini)
P.control=false
P.timing=false
P.result=false--String: 'finish'|'win'|'lose'
P.stat=getNewStatTable()
P.stat=_getNewStatTable()
P.modeData=setmetatable({},modeDataMeta)--Data use by mode
P.keyPressing={}for i=1,12 do P.keyPressing[i]=false end
P.clearingRow,P.clearedRow={},{}--Clearing animation height,cleared row mark
@@ -208,7 +208,7 @@ local function newEmptyPlayer(id,mini)
}
return P
end
local function loadGameEnv(P)--Load gameEnv
local function _loadGameEnv(P)--Load gameEnv
P.gameEnv={}--Current game setting environment
local ENV=P.gameEnv
local GAME,SETTING=GAME,SETTING
@@ -238,7 +238,7 @@ local function loadGameEnv(P)--Load gameEnv
end
end
end
local function loadRemoteEnv(P,confStr)--Load gameEnv
local function _loadRemoteEnv(P,confStr)--Load gameEnv
confStr=JSON.decode(confStr)
if not confStr then
confStr={}
@@ -264,7 +264,7 @@ local function loadRemoteEnv(P,confStr)--Load gameEnv
end
end
end
local function applyGameEnv(P)--Finish gameEnv processing
local function _applyGameEnv(P)--Finish gameEnv processing
local ENV=P.gameEnv
P._20G=ENV.drop==0
@@ -364,7 +364,7 @@ local DemoEnv={
fine=false,
}
function PLY.newDemoPlayer(id)
local P=newEmptyPlayer(id)
local P=_newEmptyPlayer(id)
P.type='computer'
P.sound=true
P.demo=true
@@ -373,8 +373,8 @@ function PLY.newDemoPlayer(id)
P.draw=ply_draw.demo
P.control=true
GAME.modeEnv=DemoEnv
loadGameEnv(P)
applyGameEnv(P)
_loadGameEnv(P)
_applyGameEnv(P)
P:loadAI{
type='CC',
next=5,
@@ -386,7 +386,7 @@ function PLY.newDemoPlayer(id)
P:popNext()
end
function PLY.newRemotePlayer(id,mini,ply)
local P=newEmptyPlayer(id,mini)
local P=_newEmptyPlayer(id,mini)
P.type='remote'
P.update=ply_update.remote_alive
@@ -400,30 +400,30 @@ function PLY.newRemotePlayer(id,mini,ply)
P.username=ply.username
P.sid=ply.sid
loadRemoteEnv(P,ply.config)
applyGameEnv(P)
_loadRemoteEnv(P,ply.config)
_applyGameEnv(P)
end
function PLY.newAIPlayer(id,AIdata,mini)
local P=newEmptyPlayer(id,mini)
local P=_newEmptyPlayer(id,mini)
P.type='computer'
loadGameEnv(P)
_loadGameEnv(P)
local ENV=P.gameEnv
ENV.face={0,0,0,0,0,0,0}
ENV.skin={1,7,11,3,14,4,9}
applyGameEnv(P)
_applyGameEnv(P)
P:loadAI(AIdata)
end
function PLY.newPlayer(id,mini)
local P=newEmptyPlayer(id,mini)
local P=_newEmptyPlayer(id,mini)
P.type='human'
P.sound=true
P.uid=USER.uid
P.username=USERS.getUsername(USER.uid)
loadGameEnv(P)
applyGameEnv(P)
_loadGameEnv(P)
_applyGameEnv(P)
end
--------------------------</Public>--------------------------
return PLY

View File

@@ -218,11 +218,11 @@ do--function Player:movePosition(x,y,size)
end
end
end
local function checkPlayer(obj,Ptar)
local function check_player(obj,Ptar)
return obj.args[1]==Ptar
end
function Player:movePosition(x,y,size)
TASK.removeTask_iterate(checkPlayer,self)
TASK.removeTask_iterate(check_player,self)
TASK.new(task_movePosition,self,x,y,size or self.size)
end
end
@@ -1539,7 +1539,7 @@ end
--------------------------</Methods>--------------------------
--------------------------<Ticks>--------------------------
local function tick_throwBadge(ifAI,sender,time)
local function task_throwBadge(ifAI,sender,time)
while true do
yield()
time=time-1
@@ -1567,7 +1567,7 @@ local function tick_throwBadge(ifAI,sender,time)
if time<=0 then return end
end
end
local function tick_finish(self)
local function task_finish(self)
while true do
yield()
self.endCounter=self.endCounter+1
@@ -1581,7 +1581,7 @@ local function tick_finish(self)
end
end
end
local function tick_lose(self)
local function task_lose(self)
while true do
yield()
self.endCounter=self.endCounter+1
@@ -1613,7 +1613,7 @@ local function tick_lose(self)
end
end
end
local function tick_autoPause()
local function task_autoPause()
local time=0
while true do
yield()
@@ -1705,9 +1705,9 @@ function Player:win(result)
end
if self.type=='human'then
gameOver()
TASK.new(tick_autoPause)
TASK.new(task_autoPause)
end
self:newTask(tick_finish)
self:newTask(task_finish)
end
function Player:lose(force)
if self.result then return end
@@ -1740,7 +1740,7 @@ function Player:lose(force)
end
self.lastRecv=A
if self.id==1 or A.id==1 then
TASK.new(tick_throwBadge,not A.type=='human',self,max(3,self.badge)*4)
TASK.new(task_throwBadge,not A.type=='human',self,max(3,self.badge)*4)
end
end
else
@@ -1764,14 +1764,14 @@ function Player:lose(force)
BGM.play('end')
end
gameOver()
self:newTask(#PLAYERS>1 and tick_lose or tick_finish)
self:newTask(#PLAYERS>1 and task_lose or task_finish)
if GAME.net and not NET.spectate then
NET.signal_die()
else
TASK.new(tick_autoPause)
TASK.new(task_autoPause)
end
else
self:newTask(tick_lose)
self:newTask(task_lose)
end
if #PLY_ALIVE==1 then
PLY_ALIVE[1]:win()

View File

@@ -53,7 +53,7 @@ local seqGenerators={
local poolLen=5*len
local droughtTimes=TABLE.new(len,len)--Drought times of seq0
local pool={}for i=1,len do for _=1,5 do ins(pool,i)end end--5 times indexes of seq0
local function poolPick()
local function _poolPick()
local r=rndGen:random(poolLen)
local res=pool[r]
@@ -87,7 +87,7 @@ local seqGenerators={
--Pick a mino from pool
local tryTime=0
::REPEAT_pickAgain::
local r=poolPick()--Random mino-index in pool
local r=_poolPick()--Random mino-index in pool
for i=1,len do
if r==history[i]then
tryTime=tryTime+1

View File

@@ -6,7 +6,7 @@ local assert,resume,status=assert,coroutine.resume,coroutine.status
local TEXT,GAME=TEXT,GAME
local PLY_ALIVE=PLY_ALIVE
local function update_misc(P,dt)
local function _updateMisc(P,dt)
--Finesse combo animation
if P.finesseComboTime>0 then
P.finesseComboTime=P.finesseComboTime-1
@@ -363,7 +363,7 @@ function update.alive(P,dt)
end
--Others
update_misc(P,dt)
_updateMisc(P,dt)
-- P:setPosition(640-150-(30*(P.curX+P.cur.sc[2])-15),30*(P.curY+P.cur.sc[1])+15-300+(ENV.smooth and P.ghoY~=P.curY and(P.dropDelay/ENV.drop-1)*30 or 0))
end
function update.dead(P,dt)
@@ -387,7 +387,7 @@ function update.dead(P,dt)
if P.b2b1>0 then
P.b2b1=max(0,P.b2b1*.92-1)
end
update_misc(P,dt)
_updateMisc(P,dt)
end
function update.remote_alive(P,dt)
local frameRate=(P.stream[#P.stream-1]or 0)-P.frameRun