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

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,5 +1,14 @@
local min=math.min local BGM={
--nowPlay=[str:playing ID]
--playing=[src:playing SRC]
}
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) local function fadeOut(src)
while true do while true do
coroutine.yield() coroutine.yield()
@@ -26,44 +35,37 @@ local function removeCurFadeOut(task,code,src)
return task.code==code and task.args[1]==src return task.code==code and task.args[1]==src
end end
local BGM={ BGM.loadOne=coroutine.wrap(function(skip)
--nowPlay=[str:playing ID] BGM.loadAll=nil
--playing=[src:playing SRC] for i=1,count do
} local file="media/BGM/"..list[i]..".ogg"
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 if love.filesystem.getInfo(file)then
BGM.list[N]=love.audio.newSource(file,"stream") Sources[list[i]]=love.audio.newSource(file,"stream")
BGM.list[N]:setLooping(true) Sources[list[i]]:setLooping(true)
BGM.list[N]:setVolume(0) Sources[list[i]]:setVolume(0)
else else
LOG.print("No BGM file: "..N,5,COLOR.orange) LOG.print("No BGM file: "..list[i],5,COLOR.orange)
end end
end if not skip and i~=count then
function BGM.loadAll() coroutine.yield()
for i=1,#BGM.list do
BGM.loadOne(i)
end end
end end
BGM.loadOne=nil
function BGM.play(s) function BGM.play(s)
if SETTING.bgm==0 then if SETTING.bgm==0 then
BGM.nowPlay=s BGM.nowPlay=s
BGM.playing=BGM.list[s] BGM.playing=Sources[s]
return return
end end
if s and BGM.list[s]and BGM.nowPlay~=s then if s and Sources[s]and BGM.nowPlay~=s then
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
TASK.removeTask_iterate(removeCurFadeOut,fadeOut,BGM.list[s]) TASK.removeTask_iterate(removeCurFadeOut,fadeOut,Sources[s])
TASK.removeTask_code(fadeIn) TASK.removeTask_code(fadeIn)
TASK.new(fadeIn,BGM.list[s]) TASK.new(fadeIn,Sources[s])
BGM.nowPlay=s BGM.nowPlay=s
BGM.playing=BGM.list[s] BGM.playing=Sources[s]
BGM.playing:play() BGM.playing:play()
end end
end end
@@ -83,4 +85,9 @@ function BGM.stop()
if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end if BGM.nowPlay then TASK.new(fadeOut,BGM.playing)end
BGM.nowPlay,BGM.playing=nil BGM.nowPlay,BGM.playing=nil
end end
end)
function BGM.loadAll()
BGM.loadOne(true)
end
end
return BGM return BGM

View File

@@ -1,42 +1,26 @@
local IMG={ local IMG={}
batteryImage="/mess/power.png", function IMG.init(list)
title="mess/title.png", IMG.init=nil
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",
}
local list={}
local count=0 local count=0
for k,_ in next,IMG do for k,v in next,list do
count=count+1 count=count+1
list[count]=k IMG[k]=v
end end
function IMG.getCount() function IMG.getCount()return count end
return count
end IMG.loadOne=coroutine.wrap(function()
function IMG.loadOne(_) IMG.loadAll=nil
local N=list[_] for k,v in next,list do
IMG[N]=love.graphics.newImage("media/image/"..IMG[N]) IMG[k]=love.graphics.newImage("media/image/"..v)
coroutine.yield()
end end
IMG.loadOne=nil
end)
function IMG.loadAll() function IMG.loadAll()
for i=1,count do for i=1,count do
IMG.loadOne(i) IMG.loadOne(i)
end end
end end
end
return IMG return IMG

View File

@@ -1,30 +1,33 @@
local rem=table.remove
local SFX={} local SFX={}
function SFX.set(L) function SFX.init(list)
SFX.list=L SFX.init=nil
SFX.len=#L local rem=table.remove
end local Sources={}
function SFX.loadOne(_)
_,SFX.list[_]=SFX.list[_] local count=#list function SFX.getCount()return count end
local N="media/SFX/".._..".ogg"
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 if love.filesystem.getInfo(N)then
SFX.list[_]={love.audio.newSource(N,"static")} Sources[list[i]]={love.audio.newSource(N,"static")}
else else
LOG.print("No SFX file: "..N,5,COLOR.orange) LOG.print("No SFX file: "..N,5,COLOR.orange)
end end
end if not skip and i~=count then
function SFX.loadAll() coroutine.yield()
for i=1,#SFX.list do
SFX.loadOne(i)
end end
end end
SFX.loadOne=nil
function SFX.fieldPlay(s,v,P) function SFX.fieldPlay(s,v,P)
SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15) SFX.play(s,v,(P.curX+P.sc[2]-5.5)*.15)
end end
function SFX.play(s,vol,pos) function SFX.play(s,vol,pos)
if SETTING.sfx==0 then return end if SETTING.sfx==0 then return end
local S=SFX.list[s]--Source list local S=Sources[s]--Source list
if not S then return end if not S then return end
local n=1 local n=1
while S[n]:isPlaying()do while S[n]:isPlaying()do
@@ -48,7 +51,7 @@ function SFX.play(s,vol,pos)
S:play() S:play()
end end
function SFX.fplay(s,vol,pos) function SFX.fplay(s,vol,pos)
local S=SFX.list[s]--Source list local S=Sources[s]--Source list
if not S then return end if not S then return end
local n=1 local n=1
while S[n]:isPlaying()do while S[n]:isPlaying()do
@@ -72,7 +75,7 @@ function SFX.fplay(s,vol,pos)
S:play() S:play()
end end
function SFX.reset() function SFX.reset()
for _,L in next,SFX.list do for _,L in next,Sources do
if type(L)=="table"then if type(L)=="table"then
for i=#L,1,-1 do for i=#L,1,-1 do
if not L[i]:isPlaying()then if not L[i]:isPlaying()then
@@ -82,4 +85,9 @@ function SFX.reset()
end end
end end
end end
end)
function SFX.loadAll()
SFX.loadOne(true)
end
end
return SFX return SFX

View File

@@ -1,56 +1,22 @@
local VOC={}
function VOC.init(list)
VOC.init=nil
local rnd=math.random local rnd=math.random
local rem=table.remove local rem=table.remove
local voiceQueue={free=0} local voiceQueue={free=0}
local bank={}--{vocName1={SRC1s},vocName2={SRC2s},...} local bank={}--{vocName1={SRC1s},vocName2={SRC2s},...}
local VOC={} local Source={}
VOC.list={}
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" local fileName="media/VOICE/"..SETTING.cv.."/"..vocName..".ogg"
if love.filesystem.getInfo(fileName)then if love.filesystem.getInfo(fileName)then
bank[vocName]={love.audio.newSource(fileName,"static")} bank[vocName]={love.audio.newSource(fileName,"static")}
table.insert(VOC.list[N],vocName) table.insert(Source[N],vocName)
return true return true
end end
end end
function VOC.set(L)
VOC.name=L
VOC.len=#L
end
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)
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 function getVoice(str)
local L=bank[str] local L=bank[str]
local n=1 local n=1
@@ -65,6 +31,59 @@ local function getVoice(str)
return L[n] return L[n]
--Load voice with string --Load voice with string
end end
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
end
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
function VOC.update() function VOC.update()
for i=#voiceQueue,1,-1 do for i=#voiceQueue,1,-1 do
local Q=voiceQueue[i] local Q=voiceQueue[i]
@@ -99,19 +118,5 @@ function VOC.update()
end end
end end
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
end
end
end end
return VOC return VOC

View File

@@ -51,8 +51,33 @@ AIFUNC= require"parts/ai"
MODES= require"parts/modes" MODES= require"parts/modes"
TICK= require"parts/tick" 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 --Initialize sound libs
SFX.set{ SFX.init{
--Stereo sfxs(cannot set position) --Stereo sfxs(cannot set position)
"welcome_sfx", "welcome_sfx",
"click","enter", "click","enter",
@@ -74,7 +99,7 @@ SFX.set{
"clear", "clear",
"error", "error",
} }
BGM.set{ BGM.init{
"blank",--menu "blank",--menu
"race",--sprint, solo "race",--sprint, solo
"infinite",--infinite norm/dig, ultra, zen, tech-finesse "infinite",--infinite norm/dig, ultra, zen, tech-finesse
@@ -99,7 +124,7 @@ BGM.set{
"rockblock",--classic, 49/99 "rockblock",--classic, 49/99
"cruelty","final","8-bit happiness","end","how feeling",--49/99 "cruelty","final","8-bit happiness","end","how feeling",--49/99
} }
VOC.set{ VOC.init{
"zspin","sspin","lspin","jspin","tspin","ospin","ispin", "zspin","sspin","lspin","jspin","tspin","ospin","ispin",
"single","double","triple","techrash", "single","double","triple","techrash",
"mini","b2b","b3b", "mini","b2b","b3b",

View File

@@ -172,7 +172,7 @@ scene.widgetList={
disp=WIDGET.lnk_CUSval("bg"), disp=WIDGET.lnk_CUSval("bg"),
code=function(i)CUSTOMENV.bg=i BG.set(i)end 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 --Copy/Paste/Start
WIDGET.newButton{name="copy", x=1070, y=310,w=310,h=70,color="lRed", font=25,code=WIDGET.lnk_pressKey("cC")}, 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 end
end end
function tick_httpREQ_autoLogin(task) local function tick_httpREQ_autoLogin(task)
local time=0 local time=0
while true do while true do
coroutine.yield() coroutine.yield()
@@ -72,13 +72,13 @@ local scene={}
function scene.sceneInit() function scene.sceneInit()
sceneTemp={ sceneTemp={
time=0,--Animation timer time=0,--Animation timer
phase=1,--Loading stage phase=0,--Loading stage
cur=1,--Loading timer cur=0,--Loading timer
tar=#VOC.name,--Current Loading bar length tar=0,--Current Loading bar length
list={ list={
#VOC.name, VOC.getCount(),
#BGM.list, BGM.getCount(),
#SFX.list, SFX.getCount(),
IMG.getCount(), IMG.getCount(),
17,--Fontsize 20~100 17,--Fontsize 20~100
SKIN.getCount(), SKIN.getCount(),
@@ -116,14 +116,15 @@ function scene.update()
local S=sceneTemp local S=sceneTemp
if S.time==400 then return end if S.time==400 then return end
repeat repeat
if S.phase==1 then if S.phase==0 then
VOC.loadOne(S.cur) elseif S.phase==1 then
VOC.loadOne()
elseif S.phase==2 then elseif S.phase==2 then
BGM.loadOne(S.cur) BGM.loadOne()
elseif S.phase==3 then elseif S.phase==3 then
SFX.loadOne(S.cur) SFX.loadOne()
elseif S.phase==4 then elseif S.phase==4 then
IMG.loadOne(S.cur) IMG.loadOne()
elseif S.phase==5 then elseif S.phase==5 then
getFont(15+5*S.cur) getFont(15+5*S.cur)
elseif S.phase==6 then elseif S.phase==6 then

View File

@@ -7,7 +7,7 @@ local scene={}
function scene.sceneInit() function scene.sceneInit()
if BGM.nowPlay then if BGM.nowPlay then
for i=1,BGM.len do for i=1,BGM.getCount()do
if BGM.list[i]==BGM.nowPlay then if BGM.list[i]==BGM.nowPlay then
sceneTemp=i--Music selected sceneTemp=i--Music selected
return return
@@ -24,7 +24,7 @@ end
function scene.keyDown(key) function scene.keyDown(key)
local S=sceneTemp local S=sceneTemp
if key=="down"then if key=="down"then
if S<BGM.len then if S<BGM.getCount()then
sceneTemp=S+1 sceneTemp=S+1
SFX.play("move",.7) SFX.play("move",.7)
end end
@@ -52,10 +52,10 @@ function scene.draw()
gc.print(BGM.list[sceneTemp],320,355) gc.print(BGM.list[sceneTemp],320,355)
setFont(35) setFont(35)
if sceneTemp>1 then gc.print(BGM.list[sceneTemp-1],320,350-30)end 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) setFont(20)
if sceneTemp>2 then gc.print(BGM.list[sceneTemp-2],320,350-50)end 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) gc.draw(IMG.title,840,220,nil,1.5,nil,206,35)
if BGM.nowPlay then 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.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")}, 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}, 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 end
function SKIN.loadAll() function SKIN.loadAll()
for i=1,count do for i=1,count do
SFX.loadOne(i) SKIN.loadOne(i)
end end
end end
function SKIN.prevSet()--Prev skin_set function SKIN.prevSet()--Prev skin_set