整理代码,较复杂的单行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

@@ -30,7 +30,7 @@ function BG.setDefault(bg)
BG.default=bg
end
function BG.set(background)
if not background then background=BG.default end
background=background or BG.default
if not BGs[background]or not SETTING.bg then return end
if background~=BG.cur then
BG.discard()

View File

@@ -72,7 +72,7 @@ function BGM.init(list)
return task.code==code and task.args[1]==src
end
function BGM.play(name)
if not name then name=BGM.default end
name=name or BGM.default
if not _load(name)then return end
if SETTING.bgm==0 then
BGM.nowPlay=name
@@ -81,7 +81,9 @@ function BGM.init(list)
end
if name and Sources[name]then
if BGM.nowPlay~=name then
if BGM.nowPlay then TASK.new(task_fadeOut,BGM.playing)end
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)
@@ -107,7 +109,9 @@ function BGM.init(list)
end
function BGM.stop()
TASK.removeTask_code(task_fadeIn)
if BGM.nowPlay then TASK.new(task_fadeOut,BGM.playing)end
if BGM.nowPlay then
TASK.new(task_fadeOut,BGM.playing)
end
BGM.nowPlay,BGM.playing=nil
end
end

View File

@@ -60,31 +60,33 @@ function FILE.save(data,name,mode)
end
end
function FILE.clear(path)
if fs.getRealDirectory(path)~=SAVEDIR or fs.getInfo(path).type~='directory'then return end
for _,name in next,fs.getDirectoryItems(path)do
name=path..'/'..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
if fs.getRealDirectory(path)==SAVEDIR and fs.getInfo(path).type=='directory'then
for _,name in next,fs.getDirectoryItems(path)do
name=path..'/'..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
end
end
end
end
end
function FILE.clear_s(path)
if path~=''and(fs.getRealDirectory(path)~=SAVEDIR or fs.getInfo(path).type~='directory')then return end
for _,name in next,fs.getDirectoryItems(path)do
name=path..'/'..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
elseif t=='directory'then
FILE.clear_s(name)
fs.remove(name)
if path==''or (fs.getRealDirectory(path)==SAVEDIR and fs.getInfo(path).type=='directory')then
for _,name in next,fs.getDirectoryItems(path)do
name=path..'/'..name
if fs.getRealDirectory(name)==SAVEDIR then
local t=fs.getInfo(name).type
if t=='file'then
fs.remove(name)
elseif t=='directory'then
FILE.clear_s(name)
fs.remove(name)
end
end
end
fs.remove(path)
end
fs.remove(path)
end
return FILE

View File

@@ -145,7 +145,9 @@ do--function GC.DO(L)
end
if type(cmd)=='string'then
local func=cmds[cmd]
if type(func)=='string'then func=gc[func]end
if type(func)=='string'then
func=gc[func]
end
if func then
func(unpack(L[i],2))
else

View File

@@ -4,7 +4,9 @@ function LANG.init(langList,publicText)--Attention, calling this will destory al
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

View File

@@ -86,7 +86,9 @@ function SCN.init(s,org)
SCN.socketRead=S.socketRead
SCN.update=S.update
SCN.draw=S.draw
if S.sceneInit then S.sceneInit(org)end
if S.sceneInit then
S.sceneInit(org)
end
end
function SCN.push(tar,style)
if not SCN.swapping then
@@ -140,7 +142,7 @@ local swap={
function SCN.swapTo(tar,style)--Parallel scene swapping, cannot back
if scenes[tar]then
if not SCN.swapping and tar~=SCN.cur then
if not style then style='fade'end
style=style or'fade'
SCN.swapping=true
local S=SCN.stat
S.tar,S.style=tar,style
@@ -164,7 +166,9 @@ function SCN.back()
if SCN.swapping then return end
--Leave scene
if SCN.sceneBack then SCN.sceneBack()end
if SCN.sceneBack then
SCN.sceneBack()
end
--Poll&Back to previous Scene
local m=#SCN.stack

View File

@@ -22,14 +22,18 @@ end
function textFX.stretch(t)
gc_push('transform')
gc_translate(t.x,t.y)
if t.c<.3 then gc_scale((.3-t.c)*1.6+1,1)end
if t.c<.3 then
gc_scale((.3-t.c)*1.6+1,1)
end
mStr(t.text,0,-t.font*.7)
gc_pop()
end
function textFX.drive(t)
gc_push('transform')
gc_translate(t.x,t.y)
if t.c<.3 then gc_shear((.3-t.c)*2,0)end
if t.c<.3 then
gc_shear((.3-t.c)*2,0)
end
mStr(t.text,0,-t.font*.7)
gc_pop()
end
@@ -102,7 +106,9 @@ function TEXT.getText(text,x,y,font,style,spd,stop)--Another version of TEXT.sho
}
end
function TEXT.update(list)
if not list then list=texts end
if not list then
list=texts
end
for i=#list,1,-1 do
local t=list[i]
t.c=t.c+t.spd
@@ -117,7 +123,9 @@ function TEXT.update(list)
end
end
function TEXT.draw(list)
if not list then list=texts end
if not list then
list=texts
end
for i=1,#list do
local t=list[i]
local p=t.c

View File

@@ -7,7 +7,9 @@ local themeColor={
}
function THEME.calculate(Y,M,D)
if not Y then Y,M,D=os.date('%Y'),os.date('%m'),os.date('%d')end
if not Y then
Y,M,D=os.date('%Y'),os.date('%m'),os.date('%d')
end
--Festival calculate within one statement
return
--Christmas
@@ -90,7 +92,9 @@ function THEME.set(theme)
end
function THEME.getThemeColor(theme)
if not theme then theme=THEME.cur end
if not theme then
theme=THEME.cur
end
return themeColor[theme]
end

View File

@@ -49,7 +49,9 @@ function VOC.init(list)
MES.new('warn',"No VOICE file: "..list[i],.1)
end
end
if not Source[list[i]][1]then Source[list[i]]=nil end
if not Source[list[i]][1]then
Source[list[i]]=nil
end
end
function VOC.getQueueCount()

View File

@@ -220,7 +220,9 @@ function button:press(_,_,k)
self.w+2*ATV,
self.h+2*ATV
)
if self.sound then SFX.play('button')end
if self.sound then
SFX.play('button')
end
end
function WIDGET.newButton(D)--name,x,y,w[,h][,fText][,color][,font=30][,sound=true][,align='M'][,edge=0],code[,hideF][,hide]
if not D.h then D.h=D.w end
@@ -332,7 +334,9 @@ function key:getInfo()
end
function key:press(_,_,k)
self.code(k)
if self.sound then SFX.play('key')end
if self.sound then
SFX.play('key')
end
end
function WIDGET.newKey(D)--name,x,y,w[,h][,fText][,fShade][,noFrame][,color][,font=30][,sound=true][,align='M'][,edge=0],code[,hideF][,hide]
if not D.h then D.h=D.w end
@@ -387,12 +391,16 @@ function switch:getCenter()
end
function switch:update()
local atv=self.ATV
if WIDGET.sel==self then if atv<8 then self.ATV=atv+1 end
else if atv>0 then self.ATV=atv-.5 end
if WIDGET.sel==self then
if atv<8 then self.ATV=atv+1 end
else
if atv>0 then self.ATV=atv-.5 end
end
local chk=self.CHK
if self:disp()then if chk<6 then self.CHK=chk+1 end
else if chk>0 then self.CHK=chk-1 end
if self:disp()then
if chk<6 then self.CHK=chk+1 end
else
if chk>0 then self.CHK=chk-1 end
end
end
function switch:draw()
@@ -424,7 +432,9 @@ function switch:getInfo()
end
function switch:press()
self.code()
if self.sound then SFX.play('move')end
if self.sound then
SFX.play('move')
end
end
function WIDGET.newSwitch(D)--name,x,y[,fText][,color][,font=30][,sound=true][,disp],code[,hideF][,hide]
local _={
@@ -736,7 +746,9 @@ function selector:press(x)
self.code(self.list[s])
self.select=s
self.selText=self.list[s]
if self.sound then SFX.play('prerotate')end
if self.sound then
SFX.play('prerotate')
end
end
end
end
@@ -754,7 +766,9 @@ function selector:scroll(n)
self.code(self.list[s])
self.select=s
self.selText=self.list[s]
if self.sound then SFX.play('prerotate')end
if self.sound then
SFX.play('prerotate')
end
end
function selector:arrowKey(k)
self:scroll((k=="left"or k=="up")and -1 or 1)
@@ -1385,13 +1399,13 @@ function WIDGET.keyPressed(k,isRep)
local tar
local minDist=1e99
local swap_xy=k=="up"or k=="down"
if swap_xy then WX,WY=WY,WX end -- note that we do not swap them back later
if swap_xy then WX,WY=WY,WX end--note that we do not swap them back later
for _,W1 in ipairs(WIDGET.active)do
if W~=W1 and W1.resCtr and not W1.hide then
local L=W1.resCtr
for j=1,#L,2 do
local x,y=L[j],L[j+1]
if swap_xy then x,y=y,x end -- note that we do not swap them back later
if swap_xy then x,y=y,x end--note that we do not swap them back later
local dist=(x-WX)*dir
if dist>10 then
dist=dist+abs(y-WY)*6.26