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

@@ -25,7 +25,7 @@ function BGM.init(list)
local count=#simpList
function BGM.getCount()return count end
local function load(name)
local function _load(name)
if type(Sources[name])=='string'then
if love.filesystem.getInfo(Sources[name])then
Sources[name]=love.audio.newSource(Sources[name],'stream')
@@ -41,8 +41,8 @@ function BGM.init(list)
MES.new('warn',"No BGM: "..name,5)
end
end
function BGM.loadAll()for name in next,Sources do load(name)end end
local function fadeOut(src)
function BGM.loadAll()for name in next,Sources do _load(name)end end
local function task_fadeOut(src)
while true do
coroutine.yield()
local v=src:getVolume()-.025*SETTING.bgm
@@ -53,7 +53,7 @@ function BGM.init(list)
end
end
end
local function fadeIn(src)
local function task_fadeIn(src)
while true do
coroutine.yield()
local v=SETTING.bgm
@@ -64,12 +64,12 @@ function BGM.init(list)
end
end
end
local function removeCurFadeOut(task,code,src)
local function check_curFadeOut(task,code,src)
return task.code==code and task.args[1]==src
end
function BGM.play(name)
if not name then name=BGM.default end
if not load(name)then return end
if not _load(name)then return end
if SETTING.bgm==0 then
BGM.nowPlay=name
BGM.playing=Sources[name]
@@ -77,11 +77,11 @@ function BGM.init(list)
end
if name and Sources[name]then
if BGM.nowPlay~=name then
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
TASK.removeTask_iterate(removeCurFadeOut,fadeOut,Sources[name])
TASK.removeTask_code(fadeIn)
if BGM.nowPlay then TASK.new(task_fadeOut,BGM.playing)end
TASK.removeTask_iterate(check_curFadeOut,task_fadeOut,Sources[name])
TASK.removeTask_code(task_fadeIn)
TASK.new(fadeIn,Sources[name])
TASK.new(task_fadeIn,Sources[name])
BGM.nowPlay=name
BGM.playing=Sources[name]
BGM.playing:play()
@@ -101,8 +101,8 @@ function BGM.init(list)
end
end
function BGM.stop()
TASK.removeTask_code(fadeIn)
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
TASK.removeTask_code(task_fadeIn)
if BGM.nowPlay then TASK.new(task_fadeOut,BGM.playing)end
BGM.nowPlay,BGM.playing=nil
end
end

View File

@@ -1,10 +1,10 @@
local LANG={}
function LANG.init(langList,publicText)--Attention, calling this will destory all initializing methods, create a LANG.set()!
local function langFallback(T0,T)
local function _langFallback(T0,T)
for k,v in next,T0 do
if type(v)=='table'and not v.refuseCopy then--refuseCopy: just copy pointer, not contents
if not T[k]then T[k]={}end
if type(T[k])=='table'then langFallback(v,T[k])end
if type(T[k])=='table'then _langFallback(v,T[k])end
elseif not T[k]then
T[k]=v
end
@@ -22,7 +22,7 @@ function LANG.init(langList,publicText)--Attention, calling this will destory al
--Fallback to other language, default zh
if i>1 then
langFallback(langList[L.fallback or 1],L)
_langFallback(langList[L.fallback or 1],L)
end
--Metatable:__call for table:getTip

View File

@@ -9,7 +9,7 @@ local ins,rem=table.insert,table.remove
local fx={}
local function normUpdate(S,dt)
local function _normUpdate(S,dt)
S.t=S.t+dt*S.rate
return S.t>1
end
@@ -28,11 +28,11 @@ function FXupdate.badge(S,dt)
end
return S.t>=1
end
FXupdate.attack=normUpdate
FXupdate.tap=normUpdate
FXupdate.ripple=normUpdate
FXupdate.rectRipple=normUpdate
FXupdate.shade=normUpdate
FXupdate.attack=_normUpdate
FXupdate.tap=_normUpdate
FXupdate.ripple=_normUpdate
FXupdate.rectRipple=_normUpdate
FXupdate.shade=_normUpdate
function FXupdate.cell(S,dt)
if S.vx then
S.x=S.x+S.vx*S.rate
@@ -45,7 +45,7 @@ function FXupdate.cell(S,dt)
S.t=S.t+dt*S.rate
return S.t>1
end
FXupdate.line=normUpdate
FXupdate.line=_normUpdate
local FXdraw={}
function FXdraw.badge(S)

View File

@@ -15,7 +15,7 @@ function VOC.init(list)
local Source={}
local count=#list function VOC.getCount()return count end
local function loadVoiceFile(N,vocName)
local function _loadVoiceFile(N,vocName)
local fileName='media/VOICE/'..SETTING.cv..'/'..vocName..'.ogg'
if love.filesystem.getInfo(fileName)then
bank[vocName]={love.audio.newSource(fileName,'stream')}
@@ -23,7 +23,7 @@ function VOC.init(list)
return true
end
end
local function getVoice(str)
local function _getVoice(str)
local L=bank[str]
local n=1
while L[n]:isPlaying()do
@@ -42,10 +42,10 @@ function VOC.init(list)
Source[list[i]]={}
local n=0
repeat n=n+1 until not loadVoiceFile(list[i],list[i]..'_'..n)
repeat n=n+1 until not _loadVoiceFile(list[i],list[i]..'_'..n)
if n==1 then
if not loadVoiceFile(list[i],list[i])then
if not _loadVoiceFile(list[i],list[i])then
MES.new('warn',"No VOICE file: "..list[i],.1)
end
end
@@ -87,13 +87,13 @@ function VOC.init(list)
rem(voiceQueue,i)
end
elseif Q.s==1 then--Waiting load source
Q[1]=getVoice(Q[1])
Q[1]=_getVoice(Q[1])
Q[1]:setVolume(SETTING.voc)
Q[1]:play()
Q.s=Q[2]and 2 or 4
elseif Q.s==2 then--Playing 1,ready 2
if Q[1]:getDuration()-Q[1]:tell()<.08 then
Q[2]=getVoice(Q[2])
Q[2]=_getVoice(Q[2])
Q[2]:setVolume(SETTING.voc)
Q[2]:play()
Q.s=3

View File

@@ -40,7 +40,7 @@ local largerThen=GC.DO{20,20,
}
local STW,STH--stencil-wid/hei
local function rectangleStencil()
local function _rectangleStencil()
gc.rectangle('fill',1,1,STW-2,STH-2)
end
@@ -1026,7 +1026,7 @@ function textBox:draw()
gc_setStencilTest('equal',1)
STW,STH=w,h
gc_stencil(rectangleStencil)
gc_stencil(_rectangleStencil)
gc_translate(0,-(scrollPos%lineH))
local pos=int(scrollPos/lineH)
for i=pos+1,min(pos+cap+1,#texts)do
@@ -1186,7 +1186,7 @@ function listBox:draw()
--List
gc_setStencilTest('equal',1)
STW,STH=w,h
gc_stencil(rectangleStencil)
gc_stencil(_rectangleStencil)
local pos=int(scrollPos/lineH)
gc_translate(0,-(scrollPos%lineH))
for i=pos+1,min(pos+cap+1,#list)do