|
|
|
@ -16,12 +16,12 @@ fn main() {
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.bank",
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.bank",
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.strings.bank",
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Master.strings.bank",
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Music.bank",
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/Music.bank",
|
|
|
|
|
|
|
|
"./assets/audio/Martian Chess/Build/Desktop/SFX.bank",
|
|
|
|
],
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.add_systems(Startup, startup)
|
|
|
|
.add_systems(Startup, startup)
|
|
|
|
.add_systems(PostStartup, play_music)
|
|
|
|
.add_systems(Update, play_music)
|
|
|
|
.add_systems(Update, set_music)
|
|
|
|
|
|
|
|
.run();
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -29,66 +29,64 @@ fn main() {
|
|
|
|
struct MyMusicPlayer;
|
|
|
|
struct MyMusicPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
|
|
|
|
fn startup(mut commands: Commands, studio: Res<FmodStudio>) {
|
|
|
|
let event_description = studio.0.get_event("event:/Martian Chess").unwrap();
|
|
|
|
commands
|
|
|
|
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
|
|
|
|
style: Style {
|
|
|
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
studio
|
|
|
|
studio
|
|
|
|
.0
|
|
|
|
.0
|
|
|
|
.get_bank_list(10)
|
|
|
|
.get_bank_list(10)
|
|
|
|
.expect("List banks")
|
|
|
|
.expect("List banks")
|
|
|
|
.iter()
|
|
|
|
.into_iter()
|
|
|
|
.for_each(|bank| {
|
|
|
|
.flat_map(|bank| {
|
|
|
|
info!("Bank: {:?}", bank.get_path().expect("Get bank path"));
|
|
|
|
|
|
|
|
bank.get_event_list(100)
|
|
|
|
bank.get_event_list(100)
|
|
|
|
.iter()
|
|
|
|
.into_iter()
|
|
|
|
.flat_map(|events| events.iter())
|
|
|
|
.flat_map(|events| events.into_iter())
|
|
|
|
.for_each(|event| {
|
|
|
|
.filter_map(|event| event.get_path().ok())
|
|
|
|
info!("Event path: {:?}", event.get_path());
|
|
|
|
})
|
|
|
|
info!(
|
|
|
|
.for_each(|event_path| {
|
|
|
|
"Event parameter description {:?}",
|
|
|
|
parent
|
|
|
|
event.get_parameter_description_by_name("Game State")
|
|
|
|
.spawn((
|
|
|
|
);
|
|
|
|
ButtonBundle {
|
|
|
|
|
|
|
|
style: Style { ..default() },
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
AudioSource::new(studio.0.get_event(event_path.as_str()).unwrap()),
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
|
|
|
parent.spawn(TextBundle::from_section(
|
|
|
|
|
|
|
|
event_path,
|
|
|
|
|
|
|
|
TextStyle {
|
|
|
|
|
|
|
|
color: Color::BLACK.into(),
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
commands.spawn((
|
|
|
|
.spawn(MyMusicPlayer)
|
|
|
|
Camera2dBundle { ..default() },
|
|
|
|
.insert(AudioSource::new(event_description));
|
|
|
|
UiCameraConfig { show_ui: true },
|
|
|
|
}
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
fn play_music(mut audio_sources: Query<&AudioSource, With<MyMusicPlayer>>) {
|
|
|
|
|
|
|
|
if let Ok(audio_source) = audio_sources.get_single_mut() {
|
|
|
|
|
|
|
|
audio_source.play();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn set_music(
|
|
|
|
fn play_music(
|
|
|
|
mut events: EventReader<KeyboardInput>,
|
|
|
|
mut events: Query<
|
|
|
|
mut audio_sources: Query<&AudioSource, With<MyMusicPlayer>>,
|
|
|
|
(&Interaction, &mut AudioSource),
|
|
|
|
|
|
|
|
(Changed<Interaction>, With<Button>, With<AudioSource>),
|
|
|
|
|
|
|
|
>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
events.iter().for_each(
|
|
|
|
events
|
|
|
|
|KeyboardInput {
|
|
|
|
.iter_mut()
|
|
|
|
key_code, state, ..
|
|
|
|
.filter(|(&i, _)| i == Interaction::Pressed)
|
|
|
|
}| {
|
|
|
|
.for_each(|(_, a)| {
|
|
|
|
if let Ok(audio_source) = audio_sources.get_single_mut() {
|
|
|
|
info!("Toggling Audio");
|
|
|
|
let target = match state {
|
|
|
|
a.play();
|
|
|
|
ButtonState::Pressed => match key_code {
|
|
|
|
});
|
|
|
|
Some(KeyCode::Key1) => 0.0,
|
|
|
|
|
|
|
|
Some(KeyCode::Key2) => 1.0,
|
|
|
|
|
|
|
|
Some(KeyCode::Key3) => 2.0,
|
|
|
|
|
|
|
|
Some(KeyCode::Key4) => 3.0,
|
|
|
|
|
|
|
|
Some(KeyCode::Key5) => 4.0,
|
|
|
|
|
|
|
|
Some(KeyCode::Key6) => 5.0,
|
|
|
|
|
|
|
|
_ => -1.0,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_ => -1.0,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
if target >= 0.0 {
|
|
|
|
|
|
|
|
audio_source
|
|
|
|
|
|
|
|
.event_instance
|
|
|
|
|
|
|
|
.set_parameter_by_name("Game State", target, true)
|
|
|
|
|
|
|
|
.expect("Set audio parameter");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|