task模块再升级,修复bgm模块没跟上task模块更新的bug
This commit is contained in:
@@ -1,9 +1,8 @@
|
|||||||
local min=math.min
|
local min=math.min
|
||||||
|
|
||||||
local function fadeOut(id)
|
local function fadeOut(src)
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
local src=BGM.list[id]
|
|
||||||
local v=src:getVolume()-.025*SETTING.bgm
|
local v=src:getVolume()-.025*SETTING.bgm
|
||||||
src:setVolume(v>0 and v or 0)
|
src:setVolume(v>0 and v or 0)
|
||||||
if v<=0 then
|
if v<=0 then
|
||||||
@@ -12,10 +11,9 @@ local function fadeOut(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local function fadeIn(id)
|
local function fadeIn(src)
|
||||||
while true do
|
while true do
|
||||||
coroutine.yield()
|
coroutine.yield()
|
||||||
local src=BGM.list[id]
|
|
||||||
local v=SETTING.bgm
|
local v=SETTING.bgm
|
||||||
v=min(v,src:getVolume()+.025*v)
|
v=min(v,src:getVolume()+.025*v)
|
||||||
src:setVolume(v)
|
src:setVolume(v)
|
||||||
@@ -24,10 +22,12 @@ local function fadeIn(id)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local function removeCurFadeOut(task,code,src)
|
||||||
|
return task.code==code and task.args[1]==src
|
||||||
|
end
|
||||||
|
|
||||||
local BGM={
|
local BGM={
|
||||||
--nowPlay=[str:playing ID]
|
--nowPlay=[str:playing ID]
|
||||||
--suspend=[str:pausing ID]
|
|
||||||
--playing=[src:playing SRC]
|
--playing=[src:playing SRC]
|
||||||
}
|
}
|
||||||
function BGM.set(L)
|
function BGM.set(L)
|
||||||
@@ -52,19 +52,17 @@ function BGM.loadAll()
|
|||||||
end
|
end
|
||||||
function BGM.play(s)
|
function BGM.play(s)
|
||||||
if SETTING.bgm==0 then
|
if SETTING.bgm==0 then
|
||||||
|
BGM.nowPlay=s
|
||||||
BGM.playing=BGM.list[s]
|
BGM.playing=BGM.list[s]
|
||||||
BGM.suspend,BGM.nowPlay=s
|
|
||||||
return
|
|
||||||
elseif not(s and BGM.list[s])then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if BGM.nowPlay~=s then
|
if s and BGM.list[s]and BGM.nowPlay~=s then
|
||||||
if BGM.nowPlay then TASK.new(fadeOut,BGM.nowPlay)end
|
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
|
||||||
TASK.changeCode(fadeIn,fadeOut)
|
TASK.removeTask_iterate(removeCurFadeOut,fadeOut,BGM.list[s])
|
||||||
TASK.removeTask_data(s)
|
TASK.removeTask_code(fadeIn)
|
||||||
|
|
||||||
BGM.nowPlay,BGM.suspend=s
|
TASK.new(fadeIn,BGM.list[s])
|
||||||
TASK.new(fadeIn,s)
|
BGM.nowPlay=s
|
||||||
BGM.playing=BGM.list[s]
|
BGM.playing=BGM.list[s]
|
||||||
BGM.playing:play()
|
BGM.playing:play()
|
||||||
end
|
end
|
||||||
@@ -74,23 +72,15 @@ function BGM.freshVolume()
|
|||||||
local v=SETTING.bgm
|
local v=SETTING.bgm
|
||||||
if v>0 then
|
if v>0 then
|
||||||
BGM.playing:setVolume(v)
|
BGM.playing:setVolume(v)
|
||||||
if BGM.suspend then
|
BGM.playing:play()
|
||||||
BGM.playing:play()
|
elseif BGM.nowPlay then
|
||||||
BGM.nowPlay,BGM.suspend=BGM.suspend
|
BGM.playing:pause()
|
||||||
end
|
|
||||||
else
|
|
||||||
if BGM.nowPlay then
|
|
||||||
BGM.playing:pause()
|
|
||||||
BGM.suspend,BGM.nowPlay=BGM.nowPlay
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function BGM.stop()
|
function BGM.stop()
|
||||||
if BGM.nowPlay then
|
TASK.removeTask_code(fadeIn)
|
||||||
TASK.new(fadeOut,BGM.nowPlay)
|
if BGM.nowPlay then TASK.new(fadeOut,BGM.nowPlay)end
|
||||||
end
|
BGM.nowPlay,BGM.playing=nil
|
||||||
TASK.changeCode(fadeIn,fadeOut)
|
|
||||||
BGM.playing,BGM.nowPlay=nil
|
|
||||||
end
|
end
|
||||||
return BGM
|
return BGM
|
||||||
@@ -28,6 +28,7 @@ function TASK.new(code,...)
|
|||||||
tasks[#tasks+1]={
|
tasks[#tasks+1]={
|
||||||
thread=thread,
|
thread=thread,
|
||||||
code=code,
|
code=code,
|
||||||
|
args={...},
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -38,17 +39,11 @@ function TASK.newNet(code,...)
|
|||||||
tasks[#tasks+1]={
|
tasks[#tasks+1]={
|
||||||
thread=thread,
|
thread=thread,
|
||||||
code=code,
|
code=code,
|
||||||
|
args={...},
|
||||||
net=true,
|
net=true,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function TASK.changeCode(c1,c2)
|
|
||||||
for i=#tasks,1,-1 do
|
|
||||||
if tasks[i].thread==c1 then
|
|
||||||
tasks[i].thread=c2
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
function TASK.removeTask_code(code)
|
function TASK.removeTask_code(code)
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
if tasks[i].code==code then
|
if tasks[i].code==code then
|
||||||
@@ -56,9 +51,9 @@ function TASK.removeTask_code(code)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
function TASK.removeTask_data(data)
|
function TASK.removeTask_iterate(func,...)
|
||||||
for i=#tasks,1,-1 do
|
for i=#tasks,1,-1 do
|
||||||
if tasks[i].data==data then
|
if func(tasks[i],...)then
|
||||||
rem(tasks,i)
|
rem(tasks,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -35,10 +35,8 @@ function scene.keyDown(key)
|
|||||||
end
|
end
|
||||||
elseif key=="return"or key=="space"then
|
elseif key=="return"or key=="space"then
|
||||||
if BGM.nowPlay~=BGM.list[S]then
|
if BGM.nowPlay~=BGM.list[S]then
|
||||||
if SETTING.bgm>0 then
|
BGM.play(BGM.list[S])
|
||||||
SFX.play("click")
|
if SETTING.bgm>0 then SFX.play("click")end
|
||||||
BGM.play(BGM.list[S])
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
BGM.stop()
|
BGM.stop()
|
||||||
end
|
end
|
||||||
@@ -79,7 +77,7 @@ scene.widgetList={
|
|||||||
WIDGET.newText{name="now", x=700, y=500,font=50,align="R",hide=function()return not BGM.nowPlay end},
|
WIDGET.newText{name="now", x=700, y=500,font=50,align="R",hide=function()return not BGM.nowPlay end},
|
||||||
WIDGET.newSlider{name="bgm", x=760, y=80,w=400, font=35,disp=WIDGET.lnk_SETval("bgm"),code=function(v)SETTING.bgm=v BGM.freshVolume()end},
|
WIDGET.newSlider{name="bgm", x=760, y=80,w=400, font=35,disp=WIDGET.lnk_SETval("bgm"),code=function(v)SETTING.bgm=v BGM.freshVolume()end},
|
||||||
WIDGET.newButton{name="up", x=200, y=250,w=120, font=55,code=WIDGET.lnk_pressKey("up"),hide=function()return sceneTemp==1 end},
|
WIDGET.newButton{name="up", x=200, y=250,w=120, font=55,code=WIDGET.lnk_pressKey("up"),hide=function()return sceneTemp==1 end},
|
||||||
WIDGET.newButton{name="play", x=200, y=390,w=120, font=35,code=WIDGET.lnk_pressKey("space"),hide=function()return SETTING.bgm==0 end},
|
WIDGET.newButton{name="play", x=200, y=390,w=120, font=35,code=WIDGET.lnk_pressKey("space")},
|
||||||
WIDGET.newButton{name="down", x=200, y=530,w=120, font=55,code=WIDGET.lnk_pressKey("down"),hide=function()return sceneTemp==BGM.len end},
|
WIDGET.newButton{name="down", x=200, y=530,w=120, font=55,code=WIDGET.lnk_pressKey("down"),hide=function()return sceneTemp==BGM.len end},
|
||||||
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80, font=40,code=WIDGET.lnk_BACK},
|
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80, font=40,code=WIDGET.lnk_BACK},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user