Skip to content

Commit

Permalink
调整一些音频播放方式,添加更多音频相关检查
Browse files Browse the repository at this point in the history
添加一个数据表文件夹
允许fmod播放音效的参数简化为只写一个音量
整理代码
  • Loading branch information
MrZ626 committed Aug 14, 2024
1 parent 9e95fe0 commit 4f772d8
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 34 deletions.
8 changes: 5 additions & 3 deletions assets/fmod20221/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ setmetatable(M.music,{__call=function(_,...) return M.music.play(...) end})
--------------------------

---@class FMOD._Effect
---@overload fun(name:string, args?:{instant?:boolean, volume?:number, pitch?:number, tune?:number, fine?:number, pos?:number[], param?:table}):FMOD.Studio.EventInstance?
---@overload fun(name:string, args?:number|{instant?:boolean, volume?:number, pitch?:number, tune?:number, fine?:number, pos?:number[], param?:table}):FMOD.Studio.EventInstance?
M.effect={}

---@param v number
Expand All @@ -321,7 +321,7 @@ local unhintedSFX={}
---
---param:{'paramName', 0, true?}
---@param name string
---@param args? {volume?:number, pitch?:number, tune?:number, fine?:number, pos?:number[], param?:table}
---@param args? number|{volume?:number, pitch?:number, tune?:number, fine?:number, pos?:number[], param?:table}
---@return FMOD.Studio.EventInstance?
function M.effect.play(name,args)
if not studio then return end
Expand All @@ -339,7 +339,9 @@ function M.effect.play(name,args)
return
end

if args then
if type(args)=='number' then
event:setVolume(args)
elseif args then
assert(type(args)=='table',"args must be table")
if args.volume then event:setVolume(args.volume) end
if args.pitch then
Expand Down
63 changes: 43 additions & 20 deletions assets/gamefunc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,53 @@ function playSample(...)
end
end
end

gameSoundFunc={}
gameSoundFunc.__index=gameSoundFunc
gameSoundFunc.__metatable=true
for _,n in next,{
'move','move_down','move_failed',
'touch','lock','tuck',
'rotate','rotate_init',
'rotate_locked','rotate_corners',
'rotate_failed','rotate_special',
'hold','hold_init',
'drop_old',
'clear_all','clear_half',
'frenzy','discharge',
'suffocate','desuffocate',
'beep_rise','beep_drop','beep_notice',
'finish_win','finish_suffocate','finish_lockout','finish_topout',
'finish_timeout','finish_rule','finish_exhaust','finish_taskfail','finish_other',
'win','fail',
} do
gameSoundFunc[n]=function() FMOD.effect(n) end
end
function gameSoundFunc.drop(vol)
FMOD.effect('drop',{volume=vol})
function gameSoundFunc.__newindex(self,k,v)
if v==NULL then
rawset(self,k,function(vol) FMOD.effect(k,vol) end)
else
rawset(self,k,v)
end
end

gameSoundFunc.move =NULL
gameSoundFunc.move_down =NULL
gameSoundFunc.move_failed =NULL
gameSoundFunc.touch =NULL
gameSoundFunc.lock =NULL
gameSoundFunc.tuck =NULL
gameSoundFunc.rotate =NULL
gameSoundFunc.rotate_init =NULL
gameSoundFunc.rotate_locked =NULL
gameSoundFunc.rotate_corners =NULL
gameSoundFunc.rotate_failed =NULL
gameSoundFunc.rotate_special =NULL
gameSoundFunc.hold =NULL
gameSoundFunc.hold_init =NULL
gameSoundFunc.drop =NULL
gameSoundFunc.drop_old =NULL
gameSoundFunc.clear_all =NULL
gameSoundFunc.clear_half =NULL
gameSoundFunc.frenzy =NULL
gameSoundFunc.discharge =NULL
gameSoundFunc.suffocate =NULL
gameSoundFunc.desuffocate =NULL
gameSoundFunc.beep_rise =NULL
gameSoundFunc.beep_drop =NULL
gameSoundFunc.beep_notice =NULL
gameSoundFunc.finish_win =NULL
gameSoundFunc.finish_suffocate =NULL
gameSoundFunc.finish_lockout =NULL
gameSoundFunc.finish_topout =NULL
gameSoundFunc.finish_timeout =NULL
gameSoundFunc.finish_rule =NULL
gameSoundFunc.finish_exhaust =NULL
gameSoundFunc.finish_taskfail =NULL
gameSoundFunc.finish_other =NULL

function gameSoundFunc.countDown(num)
if num==0 then -- 6, 3+6+6
playSample('sine',{'A3',.8})
Expand Down
6 changes: 3 additions & 3 deletions assets/scene/tutorial_shape.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ end
local function answer(ansID)
if noControl then
if ansID==curPiece.id then
gameSoundFunc.move_failed()
FMOD.effect('move_failed')
end
return
end
Expand All @@ -171,7 +171,7 @@ local function answer(ansID)
noControl=0.26
end
else
FMOD.effect('finish_rule')
FMOD.effect('move_failed')
end
end

Expand Down Expand Up @@ -201,7 +201,7 @@ function scene.update(dt)
local lines=AI.util.clearLine(matrix)
if lines>0 then gameSoundFunc.clear(lines) end
if #matrix==0 then
gameSoundFunc.clear_all()
FMOD.effect('clear_all')
end
-- newPiece()
noControl=nil
Expand Down
2 changes: 1 addition & 1 deletion assets/scene/zeta_input_method.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function scene.load()
charQueue={}

if not database then
local data=STRING.split(FILE.load("assets/stroke_data.txt"),"\n")
local data=STRING.split(FILE.load('datatable/stroke_data.txt'),'\n')
database={{},{},{},{},{},list={}}
for i=1,#data do
local char
Expand Down
2 changes: 1 addition & 1 deletion assets/scene_app/dropper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function scene.update(dt)
else
move.y=SCR.h0-2*brickHeight
comboSound(math.floor(floor/2)+1)
FMOD.effect(move.x==base.x and 'clear_3' or 'clear_2',{volume=.6})
FMOD.effect(move.x==base.x and 'clear_3' or 'clear_2',.6)
state='shorten'
end
end
Expand Down
2 changes: 1 addition & 1 deletion assets/scene_app/dtw.lua
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ local function touch(n)
state=2
FMOD.effect('finish_win')
else
FMOD.effect('beep_notice',{volume=.5})
FMOD.effect('beep_notice',.5)
end
end
height=height+B.ch
Expand Down
6 changes: 3 additions & 3 deletions assets/scene_app/link.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ local function tap(x,y)

-- Check win
if field.remain==0 then
FMOD.effect('frenzy',{volume=.8})
FMOD.effect('frenzy',.8)
if noComboBreak then
TEXT:add{text="FULL COMBO",x=800,y=500,fontSize=50,k=2,style='beat',styleArg=.626}
comboTime=comboTime+3
Expand Down Expand Up @@ -244,12 +244,12 @@ local function tap(x,y)
selX,selY=false,false
else
selX,selY=x,y
FMOD.effect('move',{volume=.9})
FMOD.effect('move',.9)
end
else
if field[y][x] and (x~=selX or y~=selY) then
selX,selY=x,y
FMOD.effect('move',{volume=.8})
FMOD.effect('move',.8)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion assets/scene_app/memorize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function scene.update(dt)
if inputTime<=0 then
inputTime=0
state=1
FMOD.effect('finish_timeout',{volume=.6})
FMOD.effect('finish_timeout',.6)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion assets/scene_app/polyforge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function scene.keyDown(key,isRep)
end
else
hit[c]=2
FMOD.effect('finish_suffocate',{volume=.6})
FMOD.effect('finish_suffocate',.6)
needReset=true
state=1
end
Expand Down
44 changes: 44 additions & 0 deletions datatable/se_names.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---@enum Techmino.SE
return {
-- In-game
'spawn_z','spawn_s','spawn_l','spawn_j','spawn_t','spawn_o','spawn_i',
'move','move_down','move_failed',
'touch','lock','tuck',
'rotate','rotate_init',
'rotate_locked','rotate_corners',
'rotate_failed','rotate_special',
'spin_0','spin_1','spin_2','spin_3','spin_4','spin_mega',
'hold','hold_init',
'drop','drop_old','drop_1','drop_2','drop_3','drop_4','drop_5','drop_6',
'clear_1','clear_2','clear_3','clear_4','clear_5','clear_6','clear_8','clear_10',
'clear_12','clear_14','clear_16','clear_18','clear_19','clear_20','clear_21','clear_22','clear_24','clear_26',
'clear_all','clear_half',
'frenzy','discharge',
'charge_1','charge_2','charge_3','charge_4','charge_5',
'charge_6','charge_7','charge_8','charge_9','charge_10',
'charge_11',
'suffocate','desuffocate',
'beep_rise','beep_drop','beep_notice',
'finish_win','finish_suffocate','finish_lockout','finish_topout',
'finish_timeout','finish_rule','finish_exhaust','finish_taskfail','finish_other',

-- Game UI
'pause_pause','pause_unpause','pause_restart','pause_setting','pause_quit',
'music_highcut','music_pause',
'notice_up','notice_down','unlock_secret',
'simulation_select','map_select','map_enter',
'map_pass_1','map_pass_2','map_pass_3','map_pass_4','map_pass_5',
'map_unlock','map_unlock_bg',
'dict_open','dict_close','dict_copy','dict_link',

-- Widgets
'button_back','button_norm','button_soft',
'selector',
'check_on','check_off',
'listbox_select','listbox_click',
'slider_drag','slider_fill_drag',
'inputbox_input','inputbox_bksp','inputbox_clear',

-- Other
'triangle_wave','sine_wave','square_wave',
}
File renamed without changes.
31 changes: 31 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,18 @@ function FMODLoadFunc() -- Will be called again when applying advanced options
-- print("--------------------------")
-- print("Musics")
-- for k,v in next,L do print(k,v)end

-- Music check
local regMore={}
for name in next,SONGBOOK do
if not L[name] then
table.insert(regMore,name)
end
end
if #regMore>0 then
MSG.new('warn',"Music not found in Bank:")
for i=1,#regMore do MSG.new('info',regMore[i]) end
end
return L
end)())
FMOD.registerEffect((function()
Expand All @@ -421,18 +433,37 @@ function FMODLoadFunc() -- Will be called again when applying advanced options
return {}
end
local L={}
local nameList={}
local l,c=bankEffect:getEventList()
for i=1,c do
local path=l[i-1]:getPath()
if path then
local name=path:match('/([^/]+)$'):lower()
L[name]=path
if path:find('event:') then
table.insert(nameList,name)
end
-- print(name,path)
end
end
-- print("--------------------------")
-- print("Effects")
-- for k,v in next,L do print(k,v)end

-- SE check
local regList=require'datatable.se_names'
local existMore,regMore=TABLE.copy(nameList),TABLE.copy(regList)
TABLE.subtract(existMore,regList)
TABLE.subtract(regMore,nameList)
if #existMore>0 then
MSG.new('warn',"SE not registered:")
for i=1,#existMore do MSG.new('info',existMore[i]) end
end
if #regMore>0 then
MSG.new('warn',"SE not found in Bank:")
for i=1,#regMore do MSG.new('info',regMore[i]) end
end

return L
end)())
end
Expand Down

0 comments on commit 4f772d8

Please sign in to comment.