语音系统升级

This commit is contained in:
MrZ626
2020-09-22 11:09:46 +08:00
parent 98b2fe6260
commit 1b2c0efe9c
3 changed files with 55 additions and 61 deletions

View File

@@ -1,49 +1,66 @@
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={}--{{SRC1s},{SRC2s},...} local bank={}--{vocName1={SRC1s},vocName2={SRC2s},...}
local VOC={} local VOC={}
VOC.name={ VOC.name={
"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","pc", "mini","b2b","b3b","clear",
"win","lose", "win","lose",
"bye", "bye",
"nya", "nya",
"happy", "nya_happy",
"doubt", "nya_doubt",
"sad", "nya_sad",
"egg", "egg",
"welcome" "welcome_voc"
} }
VOC.list={ VOC.list={}
zspin={"zspin_1","zspin_2","zspin_3"},
sspin={"sspin_1","sspin_2","sspin_3","sspin_4","sspin_5","sspin_6"},
lspin={"lspin_1","lspin_2"},
jspin={"jspin_1","jspin_2","jspin_3","jspin_4"},
tspin={"tspin_1","tspin_2","tspin_3","tspin_4","tspin_5","tspin_6"},
ospin={"ospin_1","ospin_2","ospin_3"},
ispin={"ispin_1","ispin_2","ispin_3"},
single={"single_1","single_2","single_3","single_4","single_5","single_6","single_7"}, local function loadVoiceFile(N,vocName)
double={"double_1","double_2","double_3","double_4","double_5"}, local fileName="VOICE/"..vocName..".ogg"
triple={"triple_1","triple_2","triple_3","triple_4","triple_5","triple_6","triple_7"}, if love.filesystem.getInfo(fileName)then
techrash={"techrash_1","techrash_2","techrash_3","techrash_4"}, bank[vocName]={love.audio.newSource(fileName,"static")}
table.insert(VOC.list[N],vocName)
return true
else
return
end
end
function VOC.loadOne(_)
local N=VOC.name[_]
VOC.list[N]={}
local i=1
while true do
if not loadVoiceFile(N,N.."_"..i)then
break
end
i=i+1
end
if i==1 then
if not loadVoiceFile(N,N)then
LOG.print("No VOICE file: "..N,"warn")
end
end
end
function VOC.loadAll()
for i=1,#VOC.name do
VOC.loadOne(i)
end
end
mini={"mini_1","mini_2","mini_3"}, function VOC.getFreeChannel()
b2b={"b2b_1","b2b_2","b2b_3"}, local i=#voiceQueue
b3b={"b3b_1","b3b_2"}, for i=1,i do
pc={"clear_1","clear_2"}, if #voiceQueue[i]==0 then return i end
win={"win_1","win_2","win_3","win_4","win_5","win_6","win_6","win_7"}, end
lose={"lose_1","lose_2","lose_3"}, voiceQueue[i+1]={s=0}
bye={"bye_1","bye_2"}, return i+1
nya={"nya_1","nya_2","nya_3","nya_4"}, end
happy={"nya_happy_1","nya_happy_2","nya_happy_3","nya_happy_4"}, function VOC.getCount()
doubt={"nya_doubt_1","nya_doubt_2"}, return #voiceQueue
sad={"nya_sad_1"}, end
egg={"egg_1","egg_2"},
welcome={"welcome_voc"},
}
local function getVoice(str) local function getVoice(str)
local L=bank[str] local L=bank[str]
@@ -59,29 +76,6 @@ local function getVoice(str)
return L[n] return L[n]
--Load voice with string --Load voice with string
end end
function VOC.loadOne(_)
local N=VOC.name[_]
for i=1,#VOC.list[N]do
local V=VOC.list[N][i]
bank[V]={love.audio.newSource("VOICE/"..V..".ogg","static")}
end
end
function VOC.loadAll()
for i=1,#VOC.list do
VOC.loadOne(i)
end
end
function VOC.getFreeChannel()
local i=#voiceQueue
for i=1,i do
if #voiceQueue[i]==0 then return i end
end
voiceQueue[i+1]={s=0}
return i+1
end
function VOC.getCount()
return #voiceQueue
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]
@@ -118,15 +112,15 @@ function VOC.update()
end end
function VOC.play(s,chn) function VOC.play(s,chn)
if setting.voc>0 then if setting.voc>0 then
local _=VOC.list[s]
if not _ then return end
if chn then if chn then
local L=voiceQueue[chn] local L=voiceQueue[chn]
local _=VOC.list[s]
if not _ then return end
L[#L+1]=_[rnd(#_)] L[#L+1]=_[rnd(#_)]
L.s=1 L.s=1
--Add to queue[chn] --Add to queue[chn]
else else
voiceQueue[VOC.getFreeChannel()]={s=1,VOC.list[s][rnd(#VOC.list[s])]} voiceQueue[VOC.getFreeChannel()]={s=1,_[rnd(#_)]}
--Create new channel & play --Create new channel & play
end end
end end

View File

@@ -2350,7 +2350,7 @@ do--player.drop(P)--Place piece
STAT.pc=STAT.pc+1 STAT.pc=STAT.pc+1
if P.human then if P.human then
SFX.play("clear") SFX.play("clear")
VOC.play("pc",CHN) VOC.play("clear",CHN)
end end
C.special=true C.special=true
elseif cc>1 or #P.field==P.garbageBeneath then elseif cc>1 or #P.field==P.garbageBeneath then

View File

@@ -719,7 +719,7 @@ do--load
-------------------------- --------------------------
if not setting.appLock then if not setting.appLock then
SFX.play("welcome_sfx") SFX.play("welcome_sfx")
VOC.play("welcome") VOC.play("welcome_voc")
end end
else else
S.cur=S.cur+1 S.cur=S.cur+1
@@ -2474,7 +2474,7 @@ do--setting_sound
S.jump=10 S.jump=10
local t=Timer()-S.last local t=Timer()-S.last
if t>1 then if t>1 then
VOC.play((t<1.5 or t>15)and"doubt"or rnd()<.8 and"happy"or"egg") VOC.play((t<1.5 or t>15)and"nya_doubt"or rnd()<.8 and"nya_happy"or"egg")
S.last=Timer() S.last=Timer()
end end
end end