几个多媒体模块支持重载资源

This commit is contained in:
MrZ626
2020-12-10 14:53:27 +08:00
parent aa3826ed8d
commit ddbe1d9c97
4 changed files with 46 additions and 60 deletions

View File

@@ -4,10 +4,10 @@ local BGM={
play=NULL,
freshVolume=NULL,
stop=NULL,
reload=NULL,
--nowPlay=[str:playing ID]
--playing=[src:playing SRC]
}
function BGM.init(list)
BGM.init=nil
local min=math.min
@@ -39,9 +39,7 @@ function BGM.init(list)
local function removeCurFadeOut(task,code,src)
return task.code==code and task.args[1]==src
end
BGM.loadOne=coroutine.wrap(function(skip)
BGM.loadAll=nil
local function load(skip)
for i=1,count do
local file="media/BGM/"..list[i]..".ogg"
if love.filesystem.getInfo(file)then
@@ -90,9 +88,8 @@ function BGM.init(list)
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
BGM.nowPlay,BGM.playing=nil
end
end)
function BGM.loadAll()
BGM.loadOne(true)
end
BGM.loadOne=coroutine.wrap(load)
function BGM.loadAll()load(true)end
end
return BGM

View File

@@ -7,9 +7,7 @@ function IMG.init(list)
IMG[k]=v
end
function IMG.getCount()return count end
IMG.loadOne=coroutine.wrap(function(skip)
IMG.loadAll=nil
local function load(skip)
for k,v in next,list do
IMG[k]=love.graphics.newImage("media/image/"..v)
if not skip and i~=count then
@@ -17,12 +15,8 @@ function IMG.init(list)
end
end
IMG.loadOne=nil
end)
function IMG.loadAll()
for i=1,count do
IMG.loadOne(i)
end
end
IMG.loadOne=coroutine.wrap(load)
function IMG.loadAll()load(true)end
end
return IMG

View File

@@ -4,6 +4,7 @@ local SFX={
play=NULL,
fplay=NULL,
reset=NULL,
reload=NULL,
}
function SFX.init(list)
SFX.init=nil
@@ -11,10 +12,7 @@ function SFX.init(list)
local Sources={}
local count=#list function SFX.getCount()return count end
SFX.loadOne=coroutine.wrap(function(skip)
SFX.loadAll=nil
local function load(skip)
for i=1,count do
local N="media/SFX/"..list[i]..".ogg"
if love.filesystem.getInfo(N)then
@@ -91,9 +89,9 @@ function SFX.init(list)
end
end
end
end)
function SFX.loadAll()
SFX.loadOne(true)
end
SFX.loadOne=coroutine.wrap(load)
function SFX.loadAll()load(true)end
end
return SFX

View File

@@ -4,8 +4,8 @@ local VOC={
getFreeChannel=NULL,
play=NULL,
update=NULL,
reload=NULL,
}
function VOC.init(list)
VOC.init=nil
local rnd=math.random
@@ -37,9 +37,7 @@ function VOC.init(list)
return L[n]
--Load voice with string
end
VOC.loadOne=coroutine.wrap(function(skip)
VOC.loadAll=nil
local function load(skip)
for i=1,count do
Source[list[i]]={}
@@ -85,44 +83,43 @@ function VOC.init(list)
end
end
end
end)
function VOC.loadAll()
VOC.loadOne(true)
end
function VOC.update()
for i=#voiceQueue,1,-1 do
local Q=voiceQueue[i]
if Q.s==0 then--Free channel, auto delete when >3
if i>3 then
rem(voiceQueue,i)
end
elseif Q.s==1 then--Waiting load source
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]:setVolume(SETTING.voc)
Q[2]:play()
Q.s=3
end
elseif Q.s==3 then--Playing 12 same time
if not Q[1]:isPlaying()then
for j=1,#Q do
Q[j]=Q[j+1]
function VOC.update()
for i=#voiceQueue,1,-1 do
local Q=voiceQueue[i]
if Q.s==0 then--Free channel, auto delete when >3
if i>3 then
rem(voiceQueue,i)
end
elseif Q.s==1 then--Waiting load source
Q[1]=getVoice(Q[1])
Q[1]:setVolume(SETTING.voc)
Q[1]:play()
Q.s=Q[2]and 2 or 4
end
elseif Q.s==4 then--Playing last
if not Q[1].isPlaying(Q[1])then
Q[1]=nil
Q.s=0
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]:setVolume(SETTING.voc)
Q[2]:play()
Q.s=3
end
elseif Q.s==3 then--Playing 12 same time
if not Q[1]:isPlaying()then
for j=1,#Q do
Q[j]=Q[j+1]
end
Q.s=Q[2]and 2 or 4
end
elseif Q.s==4 then--Playing last
if not Q[1].isPlaying(Q[1])then
Q[1]=nil
Q.s=0
end
end
end
end
end
VOC.loadOne=coroutine.wrap(load)
function VOC.loadAll()load(true)end
end
return VOC