diff --git a/Zframework/bgm.lua b/Zframework/bgm.lua index 4f88c41f..37aca4f9 100644 --- a/Zframework/bgm.lua +++ b/Zframework/bgm.lua @@ -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 \ No newline at end of file diff --git a/Zframework/image.lua b/Zframework/image.lua index e7bed276..38100668 100644 --- a/Zframework/image.lua +++ b/Zframework/image.lua @@ -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 \ No newline at end of file diff --git a/Zframework/sfx.lua b/Zframework/sfx.lua index 9d83cfd7..8030d560 100644 --- a/Zframework/sfx.lua +++ b/Zframework/sfx.lua @@ -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 \ No newline at end of file diff --git a/Zframework/voice.lua b/Zframework/voice.lua index 7ceda1e8..a3832144 100644 --- a/Zframework/voice.lua +++ b/Zframework/voice.lua @@ -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 diff --git a/main.lua b/main.lua index f9184759..1031f06f 100644 --- a/main.lua +++ b/main.lua @@ -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", diff --git a/parts/scenes/customGame.lua b/parts/scenes/customGame.lua index 5b0b8ad4..4c442312 100644 --- a/parts/scenes/customGame.lua +++ b/parts/scenes/customGame.lua @@ -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")}, diff --git a/parts/scenes/load.lua b/parts/scenes/load.lua index 420a710e..da9716c3 100644 --- a/parts/scenes/load.lua +++ b/parts/scenes/load.lua @@ -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 diff --git a/parts/scenes/music.lua b/parts/scenes/music.lua index 88e20891..dacc8048 100644 --- a/parts/scenes/music.lua +++ b/parts/scenes/music.lua @@ -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 S1 then gc.print(BGM.list[sceneTemp-1],320,350-30)end - if sceneTemp2 then gc.print(BGM.list[sceneTemp-2],320,350-50)end - if sceneTemp