多媒体模块全体高度封装大型升级

This commit is contained in:
MrZ626
2020-12-10 10:34:44 +08:00
parent 4eba28fa96
commit 3fb6cfb1be
9 changed files with 341 additions and 311 deletions

View File

@@ -1,86 +1,93 @@
local min=math.min
local function fadeOut(src)
while true do
coroutine.yield()
local v=src:getVolume()-.025*SETTING.bgm
src:setVolume(v>0 and v or 0)
if v<=0 then
src:stop()
return true
end
end
end
local function fadeIn(src)
while true do
coroutine.yield()
local v=SETTING.bgm
v=min(v,src:getVolume()+.025*v)
src:setVolume(v)
if v>=SETTING.bgm then
return true
end
end
end
local function removeCurFadeOut(task,code,src)
return task.code==code and task.args[1]==src
end
local BGM={
--nowPlay=[str:playing ID]
--playing=[src:playing SRC]
}
function BGM.set(L)
BGM.list=L
BGM.len=#L
end
function BGM.loadOne(N)
N=BGM.list[N]
local file="media/BGM/"..N..".ogg"
if love.filesystem.getInfo(file)then
BGM.list[N]=love.audio.newSource(file,"stream")
BGM.list[N]:setLooping(true)
BGM.list[N]:setVolume(0)
else
LOG.print("No BGM file: "..N,5,COLOR.orange)
end
end
function BGM.loadAll()
for i=1,#BGM.list do
BGM.loadOne(i)
end
end
function BGM.play(s)
if SETTING.bgm==0 then
BGM.nowPlay=s
BGM.playing=BGM.list[s]
return
end
if s and BGM.list[s]and BGM.nowPlay~=s then
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
TASK.removeTask_iterate(removeCurFadeOut,fadeOut,BGM.list[s])
TASK.removeTask_code(fadeIn)
TASK.new(fadeIn,BGM.list[s])
BGM.nowPlay=s
BGM.playing=BGM.list[s]
BGM.playing:play()
end
end
function BGM.freshVolume()
if BGM.playing then
local v=SETTING.bgm
if v>0 then
BGM.playing:setVolume(v)
BGM.playing:play()
elseif BGM.nowPlay then
BGM.playing:pause()
function BGM.init(list)
BGM.init=nil
local min=math.min
local Sources={}function BGM.getList()return Sources end
local count=#list function BGM.getCount()return count end
local function fadeOut(src)
while true do
coroutine.yield()
local v=src:getVolume()-.025*SETTING.bgm
src:setVolume(v>0 and v or 0)
if v<=0 then
src:stop()
return true
end
end
end
end
function BGM.stop()
TASK.removeTask_code(fadeIn)
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
BGM.nowPlay,BGM.playing=nil
local function fadeIn(src)
while true do
coroutine.yield()
local v=SETTING.bgm
v=min(v,src:getVolume()+.025*v)
src:setVolume(v)
if v>=SETTING.bgm then
return true
end
end
end
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
for i=1,count do
local file="media/BGM/"..list[i]..".ogg"
if love.filesystem.getInfo(file)then
Sources[list[i]]=love.audio.newSource(file,"stream")
Sources[list[i]]:setLooping(true)
Sources[list[i]]:setVolume(0)
else
LOG.print("No BGM file: "..list[i],5,COLOR.orange)
end
if not skip and i~=count then
coroutine.yield()
end
end
BGM.loadOne=nil
function BGM.play(s)
if SETTING.bgm==0 then
BGM.nowPlay=s
BGM.playing=Sources[s]
return
end
if s and Sources[s]and BGM.nowPlay~=s then
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
TASK.removeTask_iterate(removeCurFadeOut,fadeOut,Sources[s])
TASK.removeTask_code(fadeIn)
TASK.new(fadeIn,Sources[s])
BGM.nowPlay=s
BGM.playing=Sources[s]
BGM.playing:play()
end
end
function BGM.freshVolume()
if BGM.playing then
local v=SETTING.bgm
if v>0 then
BGM.playing:setVolume(v)
BGM.playing:play()
elseif BGM.nowPlay then
BGM.playing:pause()
end
end
end
function BGM.stop()
TASK.removeTask_code(fadeIn)
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
BGM.nowPlay,BGM.playing=nil
end
end)
function BGM.loadAll()
BGM.loadOne(true)
end
end
return BGM

View File

@@ -1,42 +1,26 @@
local IMG={
batteryImage="/mess/power.png",
title="mess/title.png",
title_color="mess/title_colored.png",
dialCircle="mess/dialCircle.png",
dialNeedle="mess/dialNeedle.png",
lifeIcon="mess/life.png",
badgeIcon="mess/badge.png",
spinCenter="mess/spinCenter.png",
ctrlSpeedLimit="mess/ctrlSpeedLimit.png",
speedLimit="mess/speedLimit.png",
pay1="mess/pay1.png",
pay2="mess/pay2.png",
local IMG={}
function IMG.init(list)
IMG.init=nil
local count=0
for k,v in next,list do
count=count+1
IMG[k]=v
end
function IMG.getCount()return count end
miyaCH="miya/ch.png",
miyaF1="miya/f1.png",
miyaF2="miya/f2.png",
miyaF3="miya/f3.png",
miyaF4="miya/f4.png",
IMG.loadOne=coroutine.wrap(function()
IMG.loadAll=nil
for k,v in next,list do
IMG[k]=love.graphics.newImage("media/image/"..v)
coroutine.yield()
end
IMG.loadOne=nil
end)
electric="mess/electric.png",
hbm="mess/hbm.png",
}
local list={}
local count=0
for k,_ in next,IMG do
count=count+1
list[count]=k
end
function IMG.getCount()
return count
end
function IMG.loadOne(_)
local N=list[_]
IMG[N]=love.graphics.newImage("media/image/"..IMG[N])
end
function IMG.loadAll()
for i=1,count do
IMG.loadOne(i)
function IMG.loadAll()
for i=1,count do
IMG.loadOne(i)
end
end
end
return IMG

View File

@@ -1,85 +1,93 @@
local rem=table.remove
local SFX={}
function SFX.set(L)
SFX.list=L
SFX.len=#L
end
function SFX.loadOne(_)
_,SFX.list[_]=SFX.list[_]
local N="media/SFX/".._..".ogg"
if love.filesystem.getInfo(N)then
SFX.list[_]={love.audio.newSource(N,"static")}
else
LOG.print("No SFX file: "..N,5,COLOR.orange)
end
end
function SFX.loadAll()
for i=1,#SFX.list do
SFX.loadOne(i)
end
end
function SFX.fieldPlay(s,v,P)
SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15)
end
function SFX.play(s,vol,pos)
if SETTING.sfx==0 then return end
local S=SFX.list[s]--Source list
if not S then return end
local n=1
while S[n]:isPlaying()do
n=n+1
if not S[n]then
S[n]=S[1]:clone()
S[n]:seek(0)
break
function SFX.init(list)
SFX.init=nil
local rem=table.remove
local Sources={}
local count=#list function SFX.getCount()return count end
SFX.loadOne=coroutine.wrap(function(skip)
SFX.loadAll=nil
for i=1,count do
local N="media/SFX/"..list[i]..".ogg"
if love.filesystem.getInfo(N)then
Sources[list[i]]={love.audio.newSource(N,"static")}
else
LOG.print("No SFX file: "..N,5,COLOR.orange)
end
if not skip and i~=count then
coroutine.yield()
end
end
end
S=S[n]--AU_SRC
if S:getChannelCount()==1 then
if pos then
pos=pos*SETTING.stereo
S:setPosition(pos,1-pos^2,0)
else
S:setPosition(0,0,0)
SFX.loadOne=nil
function SFX.fieldPlay(s,v,P)
SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15)
end
end
S:setVolume(((vol or 1)*SETTING.sfx)^1.626)
S:play()
end
function SFX.fplay(s,vol,pos)
local S=SFX.list[s]--Source list
if not S then return end
local n=1
while S[n]:isPlaying()do
n=n+1
if not S[n]then
S[n]=S[1]:clone()
S[n]:seek(0)
break
function SFX.play(s,vol,pos)
if SETTING.sfx==0 then return end
local S=Sources[s]--Source list
if not S then return end
local n=1
while S[n]:isPlaying()do
n=n+1
if not S[n]then
S[n]=S[1]:clone()
S[n]:seek(0)
break
end
end
S=S[n]--AU_SRC
if S:getChannelCount()==1 then
if pos then
pos=pos*SETTING.stereo
S:setPosition(pos,1-pos^2,0)
else
S:setPosition(0,0,0)
end
end
S:setVolume(((vol or 1)*SETTING.sfx)^1.626)
S:play()
end
end
S=S[n]--AU_SRC
if S:getChannelCount()==1 then
if pos then
pos=pos*SETTING.stereo
S:setPosition(pos,1-pos^2,0)
else
S:setPosition(0,0,0)
function SFX.fplay(s,vol,pos)
local S=Sources[s]--Source list
if not S then return end
local n=1
while S[n]:isPlaying()do
n=n+1
if not S[n]then
S[n]=S[1]:clone()
S[n]:seek(0)
break
end
end
S=S[n]--AU_SRC
if S:getChannelCount()==1 then
if pos then
pos=pos*SETTING.stereo
S:setPosition(pos,1-pos^2,0)
else
S:setPosition(0,0,0)
end
end
S:setVolume(vol^1.626)
S:play()
end
end
S:setVolume(vol^1.626)
S:play()
end
function SFX.reset()
for _,L in next,SFX.list do
if type(L)=="table"then
for i=#L,1,-1 do
if not L[i]:isPlaying()then
rem(L,i)
function SFX.reset()
for _,L in next,Sources do
if type(L)=="table"then
for i=#L,1,-1 do
if not L[i]:isPlaying()then
rem(L,i)
end
end
end
end
end
end)
function SFX.loadAll()
SFX.loadOne(true)
end
end
return SFX

View File

@@ -1,116 +1,121 @@
local rnd=math.random
local rem=table.remove
local voiceQueue={free=0}
local bank={}--{vocName1={SRC1s},vocName2={SRC2s},...}
local VOC={}
VOC.list={}
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,"static")}
table.insert(VOC.list[N],vocName)
return true
end
end
function VOC.set(L)
VOC.name=L
VOC.len=#L
end
function VOC.init(list)
VOC.init=nil
local rnd=math.random
local rem=table.remove
local voiceQueue={free=0}
local bank={}--{vocName1={SRC1s},vocName2={SRC2s},...}
local Source={}
function VOC.loadOne(name)
local N=VOC.name[name]
VOC.list[N]={}
local i=0
repeat i=i+1 until not loadVoiceFile(N,N.."_"..i)
if i==1 then
if not loadVoiceFile(N,N)then
LOG.print("No VOICE file: "..N,5,COLOR.orange)
local count=#list function VOC.getCount()return count end
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,"static")}
table.insert(Source[N],vocName)
return true
end
end
if not VOC.list[N][1]then VOC.list[N]=nil end
end
function VOC.loadAll()
for i=1,#VOC.name do
VOC.loadOne(i)
end
collectgarbage()
end
function VOC.getFreeChannel()
local l=#voiceQueue
for i=1,l do
if #voiceQueue[i]==0 then return i end
end
voiceQueue[l+1]={s=0}
return l+1
end
function VOC.getCount()
return #voiceQueue
end
local function getVoice(str)
local L=bank[str]
local n=1
while L[n]:isPlaying()do
n=n+1
if not L[n]then
L[n]=L[1]:clone()
L[n]:seek(0)
break
local function getVoice(str)
local L=bank[str]
local n=1
while L[n]:isPlaying()do
n=n+1
if not L[n]then
L[n]=L[1]:clone()
L[n]:seek(0)
break
end
end
return L[n]
--Load voice with string
end
return L[n]
--Load voice with string
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]
VOC.loadOne=coroutine.wrap(function(skip)
VOC.loadAll=nil
for i=1,count do
Source[list[i]]={}
local n=0
repeat n=n+1 until not loadVoiceFile(list[i],list[i].."_"..n)
if n==1 then
if not loadVoiceFile(list[i],list[i])then
LOG.print("No VOICE file: "..list[i],5,COLOR.orange)
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
if not Source[list[i]][1]then Source[list[i]]=nil end
if not skip and i~=count then
coroutine.yield()
end
end
VOC.loadOne=nil
function VOC.getFreeChannel()
local l=#voiceQueue
for i=1,l do
if #voiceQueue[i]==0 then return i end
end
voiceQueue[l+1]={s=0}
return l+1
end
function VOC.getCount()
return #voiceQueue
end
function VOC.play(s,chn)
if SETTING.voc>0 then
local _=Source[s]
if not _ then return end
if chn then
local L=voiceQueue[chn]
L[#L+1]=_[rnd(#_)]
L.s=1
--Add to queue[chn]
else
voiceQueue[VOC.getFreeChannel()]={s=1,_[rnd(#_)]}
--Create new channel & play
end
end
end
end)
function VOC.loadAll()
VOC.loadOne(true)
end
end
function VOC.play(s,chn)
if SETTING.voc>0 then
local _=VOC.list[s]
if not _ then return end
if chn then
local L=voiceQueue[chn]
L[#L+1]=_[rnd(#_)]
L.s=1
--Add to queue[chn]
else
voiceQueue[VOC.getFreeChannel()]={s=1,_[rnd(#_)]}
--Create new channel & play
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]
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

View File

@@ -51,8 +51,33 @@ AIFUNC= require"parts/ai"
MODES= require"parts/modes"
TICK= require"parts/tick"
--Initialize image lib
IMG.init{
batteryImage="/mess/power.png",
title="mess/title.png",
title_color="mess/title_colored.png",
dialCircle="mess/dialCircle.png",
dialNeedle="mess/dialNeedle.png",
lifeIcon="mess/life.png",
badgeIcon="mess/badge.png",
spinCenter="mess/spinCenter.png",
ctrlSpeedLimit="mess/ctrlSpeedLimit.png",
speedLimit="mess/speedLimit.png",
pay1="mess/pay1.png",
pay2="mess/pay2.png",
miyaCH="miya/ch.png",
miyaF1="miya/f1.png",
miyaF2="miya/f2.png",
miyaF3="miya/f3.png",
miyaF4="miya/f4.png",
electric="mess/electric.png",
hbm="mess/hbm.png",
}
--Initialize sound libs
SFX.set{
SFX.init{
--Stereo sfxs(cannot set position)
"welcome_sfx",
"click","enter",
@@ -74,7 +99,7 @@ SFX.set{
"clear",
"error",
}
BGM.set{
BGM.init{
"blank",--menu
"race",--sprint, solo
"infinite",--infinite norm/dig, ultra, zen, tech-finesse
@@ -99,7 +124,7 @@ BGM.set{
"rockblock",--classic, 49/99
"cruelty","final","8-bit happiness","end","how feeling",--49/99
}
VOC.set{
VOC.init{
"zspin","sspin","lspin","jspin","tspin","ospin","ispin",
"single","double","triple","techrash",
"mini","b2b","b3b",

View File

@@ -172,7 +172,7 @@ scene.widgetList={
disp=WIDGET.lnk_CUSval("bg"),
code=function(i)CUSTOMENV.bg=i BG.set(i)end
},
WIDGET.newSelector{name="bgm", x=1070, y=230,w=250,color="yellow", list=BGM.list, disp=WIDGET.lnk_CUSval("bgm"), code=function(i)CUSTOMENV.bgm=i BGM.play(i)end},
WIDGET.newSelector{name="bgm", x=1070, y=230,w=250,color="yellow", list=BGM.getList(), disp=WIDGET.lnk_CUSval("bgm"), code=function(i)CUSTOMENV.bgm=i BGM.play(i)end},
--Copy/Paste/Start
WIDGET.newButton{name="copy", x=1070, y=310,w=310,h=70,color="lRed", font=25,code=WIDGET.lnk_pressKey("cC")},

View File

@@ -35,7 +35,7 @@ local function tick_httpREQ_launch(task)
end
end
end
function tick_httpREQ_autoLogin(task)
local function tick_httpREQ_autoLogin(task)
local time=0
while true do
coroutine.yield()
@@ -72,13 +72,13 @@ local scene={}
function scene.sceneInit()
sceneTemp={
time=0,--Animation timer
phase=1,--Loading stage
cur=1,--Loading timer
tar=#VOC.name,--Current Loading bar length
phase=0,--Loading stage
cur=0,--Loading timer
tar=0,--Current Loading bar length
list={
#VOC.name,
#BGM.list,
#SFX.list,
VOC.getCount(),
BGM.getCount(),
SFX.getCount(),
IMG.getCount(),
17,--Fontsize 20~100
SKIN.getCount(),
@@ -116,14 +116,15 @@ function scene.update()
local S=sceneTemp
if S.time==400 then return end
repeat
if S.phase==1 then
VOC.loadOne(S.cur)
if S.phase==0 then
elseif S.phase==1 then
VOC.loadOne()
elseif S.phase==2 then
BGM.loadOne(S.cur)
BGM.loadOne()
elseif S.phase==3 then
SFX.loadOne(S.cur)
SFX.loadOne()
elseif S.phase==4 then
IMG.loadOne(S.cur)
IMG.loadOne()
elseif S.phase==5 then
getFont(15+5*S.cur)
elseif S.phase==6 then

View File

@@ -7,7 +7,7 @@ local scene={}
function scene.sceneInit()
if BGM.nowPlay then
for i=1,BGM.len do
for i=1,BGM.getCount()do
if BGM.list[i]==BGM.nowPlay then
sceneTemp=i--Music selected
return
@@ -24,7 +24,7 @@ end
function scene.keyDown(key)
local S=sceneTemp
if key=="down"then
if S<BGM.len then
if S<BGM.getCount()then
sceneTemp=S+1
SFX.play("move",.7)
end
@@ -52,10 +52,10 @@ function scene.draw()
gc.print(BGM.list[sceneTemp],320,355)
setFont(35)
if sceneTemp>1 then gc.print(BGM.list[sceneTemp-1],320,350-30)end
if sceneTemp<BGM.len then gc.print(BGM.list[sceneTemp+1],320,350+65)end
if sceneTemp<BGM.getCount()then gc.print(BGM.list[sceneTemp+1],320,350+65)end
setFont(20)
if sceneTemp>2 then gc.print(BGM.list[sceneTemp-2],320,350-50)end
if sceneTemp<BGM.len-1 then gc.print(BGM.list[sceneTemp+2],320,350+110)end
if sceneTemp<BGM.getCount()-1 then gc.print(BGM.list[sceneTemp+2],320,350+110)end
gc.draw(IMG.title,840,220,nil,1.5,nil,206,35)
if BGM.nowPlay then
@@ -78,7 +78,7 @@ scene.widgetList={
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="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.getCount()end},
WIDGET.newButton{name="back", x=1140, y=640,w=170,h=80, font=40,code=WIDGET.lnk_BACK},
}

View File

@@ -91,7 +91,7 @@ function SKIN.loadOne(_)
end
function SKIN.loadAll()
for i=1,count do
SFX.loadOne(i)
SKIN.loadOne(i)
end
end
function SKIN.prevSet()--Prev skin_set