diff --git a/Zframework/bgm.lua b/Zframework/bgm.lua index b1ad4b8f..d0acecac 100644 --- a/Zframework/bgm.lua +++ b/Zframework/bgm.lua @@ -1,9 +1,9 @@ local BGM={ + vol=1, default=false, getList=function()error("Cannot getList before initialize!")end, getCount=function()return 0 end, play=NULL, - freshVolume=NULL, stop=NULL, onChange=NULL, --nowPlay=[str:playing ID] @@ -13,7 +13,7 @@ local BGM={ local function task_fadeOut(src) while true do coroutine.yield() - local v=src:getVolume()-.025*SETTING.bgm + local v=src:getVolume()-.025*BGM.vol src:setVolume(v>0 and v or 0) if v<=0 then src:pause() @@ -24,10 +24,10 @@ end local function task_fadeIn(src) while true do coroutine.yield() - local v=SETTING.bgm + local v=BGM.vol v=math.min(v,src:getVolume()+.025*v) src:setVolume(v) - if v>=SETTING.bgm then + if v>=BGM.vol then return true end end @@ -41,6 +41,10 @@ end function BGM.setChange(func) BGM.onChange=func end +function BGM.setVol(v) + assert(type(v)=='number'and v>=0 and v<=1) + BGM.vol=v +end function BGM.init(list) BGM.init=nil local Sources={} @@ -71,6 +75,18 @@ function BGM.init(list) LOG("No BGM: "..name,5) end end + function BGM.setVol(v) + assert(type(v)=='number'and v>=0 and v<=1) + BGM.vol=v + if BGM.playing then + if BGM.vol>0 then + BGM.playing:setVolume(BGM.vol) + BGM.playing:play() + elseif BGM.nowPlay then + BGM.playing:pause() + end + end + end function BGM.loadAll()--Not neccessary, unless you want avoid the lag when playing something for the first time for name in next,Sources do _load(name) @@ -79,7 +95,7 @@ function BGM.init(list) function BGM.play(name) name=name or BGM.default if not _load(name)then return end - if SETTING.bgm==0 then + if BGM.vol==0 then BGM.nowPlay=name BGM.playing=Sources[name] return true @@ -117,17 +133,6 @@ function BGM.init(list) 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(task_fadeIn) if BGM.nowPlay then diff --git a/Zframework/sfx.lua b/Zframework/sfx.lua index 81aae38a..d0058949 100644 --- a/Zframework/sfx.lua +++ b/Zframework/sfx.lua @@ -1,4 +1,6 @@ local SFX={ + vol=1, + stereo=1, getCount=function()return 0 end, load=function()error("Cannot load before init!")end, fieldPlay=NULL, @@ -6,6 +8,14 @@ local SFX={ fplay=NULL, reset=NULL, } +function SFX.setVol(v) + assert(type(v)=='number'and v>=0 and v<=1) + SFX.vol=v +end +function SFX.setStereo(v) + assert(type(v)=='number'and v>=0 and v<=1) + SFX.stereo=v +end function SFX.init(list) SFX.init=nil local rem=table.remove @@ -23,7 +33,7 @@ function SFX.init(list) end function SFX.play(s,vol,pos) - if SETTING.sfx==0 or vol==0 then return end + if SFX.vol==0 or vol==0 then return end local S=Sources[s]--Source list if not S then return end local n=1 @@ -38,13 +48,13 @@ function SFX.init(list) S=S[n]--AU_SRC if S:getChannelCount()==1 then if pos then - pos=pos*SETTING.stereo + pos=pos*SFX.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:setVolume(((vol or 1)*SFX.vol)^1.626) S:play() end function SFX.fplay(s,vol,pos) @@ -62,7 +72,7 @@ function SFX.init(list) S=S[n]--AU_SRC if S:getChannelCount()==1 then if pos then - pos=pos*SETTING.stereo + pos=pos*SFX.stereo S:setPosition(pos,1-pos^2,0) else S:setPosition(0,0,0) diff --git a/Zframework/voice.lua b/Zframework/voice.lua index 1e59b9af..d42234ea 100644 --- a/Zframework/voice.lua +++ b/Zframework/voice.lua @@ -1,4 +1,5 @@ local VOC={ + vol=1, getCount=function()return 0 end, getQueueCount=function()return 0 end, load=function()error("Cannot load before init!")end, @@ -6,6 +7,10 @@ local VOC={ play=NULL, update=NULL, } +function VOC.setVol(v) + assert(type(v)=='number'and v>=0 and v<=1) + VOC.vol=v +end function VOC.init(list) VOC.init=nil local rnd=math.random @@ -67,7 +72,7 @@ function VOC.init(list) end function VOC.play(s,chn) - if SETTING.voc>0 then + if VOC.vol>0 then local _=Source[s] if not _ then return end if chn then @@ -90,13 +95,13 @@ function VOC.init(list) end elseif Q.s==1 then--Waiting load source Q[1]=_getVoice(Q[1]) - Q[1]:setVolume(SETTING.voc) + Q[1]:setVolume(VOC.vol) 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]:setVolume(VOC.vol) Q[2]:play() Q.s=3 end diff --git a/main.lua b/main.lua index ddc29f2e..b78aa046 100644 --- a/main.lua +++ b/main.lua @@ -36,7 +36,7 @@ math.randomseed(os.time()*626) love.setDeprecationOutput(false) love.keyboard.setKeyRepeat(true) love.keyboard.setTextInput(false) -if SYSTEM=='Android'or SYSTEM=='iOS'then +if MOBILE then local w,h,f=love.window.getMode() f.resizable=false love.window.setMode(w,h,f) diff --git a/parts/gameFuncs.lua b/parts/gameFuncs.lua index 3d35ca48..26d6f889 100644 --- a/parts/gameFuncs.lua +++ b/parts/gameFuncs.lua @@ -36,6 +36,9 @@ function applySettings() love.audio.setVolume(SETTING.mainVol) love.mouse.setVisible(SETTING.sysCursor) VK.setShape(SETTING.VKSkin) + BGM.setVol(SETTING.bgm) + SFX.setVol(SETTING.sfx) + VOC.setVol(SETTING.voc) applyBlockSatur(SETTING.blockSatur) applyFieldSatur(SETTING.fieldSatur) applyLanguage() diff --git a/parts/scenes/launchpad.lua b/parts/scenes/launchpad.lua index 6d86ba02..44399d82 100644 --- a/parts/scenes/launchpad.lua +++ b/parts/scenes/launchpad.lua @@ -218,9 +218,9 @@ end scene.widgetList={ WIDGET.newText{name="title", x=640, y=-5,font=50}, - WIDGET.newSlider{name="bgm", x=1000,y=80,lim=130,w=250,disp=SETval('bgm'),code=function(v)SETTING.bgm=v BGM.freshVolume()end}, - WIDGET.newSlider{name="sfx", x=1000,y=150,lim=130,w=250,disp=SETval('sfx'),code=SETsto('sfx'),change=function()SFX.play('blip_1')end}, - WIDGET.newSlider{name="voc", x=1000,y=220,lim=130,w=250,disp=SETval('voc'),code=SETsto('voc'),change=function()VOC.play('test')end}, + WIDGET.newSlider{name="bgm", x=1000,y=80, lim=130,w=250,disp=SETval('bgm'),code=function(v)SETTING.bgm=v BGM.setVol(SETTING.bgm)end}, + WIDGET.newSlider{name="sfx", x=1000,y=150,lim=130,w=250,disp=SETval('sfx'),code=function(v)SETTING.sfx=v SFX.setVol(SETTING.sfx)end}, + WIDGET.newSlider{name="voc", x=1000,y=220,lim=130,w=250,disp=SETval('voc'),code=function(v)SETTING.voc=v VOC.setVol(SETTING.voc)end}, WIDGET.newSwitch{name="label",x=1200,y=290,lim=160,disp=function()return showLabel end,code=pressKey"space",}, WIDGET.newButton{name="music",x=1140,y=540,w=170,h=80,font=40,code=pressKey"tab"}, WIDGET.newButton{name="back", x=1140,y=640,w=170,h=80,font=60,fText=CHAR.icon.back,code=backScene}, diff --git a/parts/scenes/music.lua b/parts/scenes/music.lua index e4488b6a..312d8c7e 100644 --- a/parts/scenes/music.lua +++ b/parts/scenes/music.lua @@ -116,7 +116,7 @@ scene.widgetList={ code=function(v)BGM.seek(v*BGM.playing:getDuration())end, hideF=function()return not BGM.nowPlay end }, - WIDGET.newSlider{name="bgm", x=760,y=80,w=400,disp=SETval('bgm'),code=function(v)SETTING.bgm=v BGM.freshVolume()end}, + WIDGET.newSlider{name="bgm", x=760,y=80,w=400,disp=SETval('bgm'),code=function(v)SETTING.bgm=v BGM.setVol(SETTING.bgm)end}, WIDGET.newButton{name="up", x=200,y=250,w=120,code=pressKey"up",hideF=function()return selected==1 end,font=60,fText=CHAR.key.up}, WIDGET.newButton{name="play", x=200,y=390,w=120,code=pressKey"space",font=65,fText=CHAR.icon.play_pause}, WIDGET.newButton{name="down", x=200,y=530,w=120,code=pressKey"down",hideF=function()return selected==#bgmList end,font=60,fText=CHAR.key.down}, diff --git a/parts/scenes/setting_sound.lua b/parts/scenes/setting_sound.lua index 4d379f99..70674408 100644 --- a/parts/scenes/setting_sound.lua +++ b/parts/scenes/setting_sound.lua @@ -79,14 +79,14 @@ scene.widgetList={ WIDGET.newButton{name="game", x=200, y=80,w=240,h=80,color='lC',font=35,code=swapScene('setting_game','swipeR')}, WIDGET.newButton{name="graphic", x=1080,y=80,w=240,h=80,color='lC',font=35,code=swapScene('setting_video','swipeL')}, - WIDGET.newSlider{name="mainVol", x=300, y=170,w=420,lim=220,color='lG',disp=SETval('mainVol'),code=function(v)SETTING.mainVol=v love.audio.setVolume(SETTING.mainVol)end}, - WIDGET.newSlider{name="bgm", x=300, y=240,w=420,lim=220,color='lG',disp=SETval('bgm'),code=function(v)SETTING.bgm=v BGM.freshVolume()end}, - WIDGET.newSlider{name="sfx", x=300, y=310,w=420,lim=220,color='lC',change=function()SFX.play('blip_1')end,disp=SETval('sfx'),code=SETsto('sfx')}, - WIDGET.newSlider{name="stereo", x=300, y=380,w=420,lim=220,color='lC',change=function()SFX.play('move',1,-1)SFX.play('lock',1,1)end,disp=SETval('stereo'),code=SETsto('stereo'),hideF=function()return SETTING.sfx==0 end}, - WIDGET.newSlider{name="spawn", x=300, y=450,w=420,lim=220,color='lC',change=function()SFX.fplay('spawn_'..math.random(7),SETTING.sfx_spawn)end,disp=SETval('sfx_spawn'),code=SETsto('sfx_spawn')}, - WIDGET.newSlider{name="warn", x=300, y=520,w=420,lim=220,color='lC',change=function()SFX.fplay('warning',SETTING.sfx_warn)end,disp=SETval('sfx_warn'),code=SETsto('sfx_warn')}, - WIDGET.newSlider{name="vib", x=300, y=590,w=420,lim=220,color='lN',unit=10,change=function()if SETTING.vib>0 then VIB(SETTING.vib+2)end end,disp=SETval('vib'),code=SETsto('vib')}, - WIDGET.newSlider{name="voc", x=300, y=660,w=420,lim=220,color='lN',change=function()VOC.play('test')end,disp=SETval('voc'),code=SETsto('voc')}, + WIDGET.newSlider{name="mainVol", x=300, y=170,w=420,lim=220,color='lG',disp=SETval('mainVol'), code=function(v)SETTING.mainVol=v love.audio.setVolume(SETTING.mainVol)end}, + WIDGET.newSlider{name="bgm", x=300, y=240,w=420,lim=220,color='lG',disp=SETval('bgm'), code=function(v)SETTING.bgm=v BGM.setVol(SETTING.bgm)end}, + WIDGET.newSlider{name="sfx", x=300, y=310,w=420,lim=220,color='lC',disp=SETval('sfx'), code=function(v)SETTING.sfx=v SFX.setVol(SETTING.sfx)end, change=function()SFX.play('blip_1')end}, + WIDGET.newSlider{name="stereo", x=300, y=380,w=420,lim=220,color='lC',disp=SETval('stereo'), code=function(v)SETTING.stereo=v SFX.setStereo(SETTING.stereo)end,change=function()SFX.play('move',1,-1)SFX.play('lock',1,1)end,hideF=function()return SETTING.sfx==0 end}, + WIDGET.newSlider{name="spawn", x=300, y=450,w=420,lim=220,color='lC',disp=SETval('sfx_spawn'), code=function(v)SETTING.sfx_spawn=v end, change=function()SFX.fplay('spawn_'..math.random(7),SETTING.sfx_spawn)end,}, + WIDGET.newSlider{name="warn", x=300, y=520,w=420,lim=220,color='lC',disp=SETval('sfx_warn'), code=function(v)SETTING.sfx_warn=v end, change=function()SFX.fplay('warning',SETTING.sfx_warn)end}, + WIDGET.newSlider{name="vib", x=300, y=590,w=420,lim=220,color='lN',disp=SETval('vib'),unit=10,code=function(v)SETTING.vib=v end, change=function()if SETTING.vib>0 then VIB(SETTING.vib+2)end end}, + WIDGET.newSlider{name="voc", x=300, y=660,w=420,lim=220,color='lN',disp=SETval('voc'), code=function(v)SETTING.voc=v VOC.setVol(SETTING.voc)end, change=function()VOC.play('test')end}, WIDGET.newSwitch{name="autoMute", x=1150,y=180,lim=380,disp=SETval('autoMute'),code=SETrev('autoMute')}, WIDGET.newSwitch{name="fine", x=1150,y=250,lim=380,disp=SETval('fine'),code=function()SETTING.fine=not SETTING.fine if SETTING.fine then SFX.play('finesseError',.6)end end},