Audio: do not use event arguments

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2024-04-29 20:33:24 -07:00
parent e711f69fad
commit 7ad38d6eff
2 changed files with 14 additions and 7 deletions

View file

@ -25,6 +25,7 @@ pub const Mod = mach.Mod(@This());
pub const events = .{
.init = .{ .handler = init },
.after_init = .{ .handler = afterInit },
.deinit = .{ .handler = deinit },
.tick = .{ .handler = tick },
.audio_state_change = .{ .handler = audioStateChange },
@ -37,9 +38,8 @@ pub const components = .{
ghost_key_mode: bool = false,
fn init(core: *mach.Core.Mod, audio: *mach.Audio.Mod, app: *Mod) void {
// Initialize audio module, telling it to send our module's .audio_state_change event when an
// entity's sound stops playing
audio.send(.init, .{app.event(.audio_state_change)});
audio.send(.init, .{});
app.send(.after_init, .{});
// Initialize piano module state
app.init(.{});
@ -53,6 +53,12 @@ fn init(core: *mach.Core.Mod, audio: *mach.Audio.Mod, app: *Mod) void {
core.send(.start, .{});
}
fn afterInit(audio: *mach.Audio.Mod, app: *Mod) void {
// Configure the audio module to send our app's .audio_state_change event when an entity's sound
// finishes playing.
audio.state().on_state_change = app.event(.audio_state_change);
}
fn deinit(core: *mach.Core.Mod, audio: *mach.Audio.Mod) void {
audio.send(.deinit, .{});
core.send(.deinit, .{});