move send reply code to chat.rs

This commit is contained in:
yuni 2024-04-04 18:53:20 +02:00
parent 8f380a6773
commit b1c78e4ccb
2 changed files with 30 additions and 23 deletions

View file

@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use crate::{actor, audio, hud}; use crate::{actor, audio, hud, settings};
pub struct ChatPlugin; pub struct ChatPlugin;
impl Plugin for ChatPlugin { impl Plugin for ChatPlugin {
@ -7,6 +7,7 @@ impl Plugin for ChatPlugin {
app.register_type::<ChatBranch>(); app.register_type::<ChatBranch>();
app.add_systems(Update, ( app.add_systems(Update, (
handle_new_conversations, handle_new_conversations,
handle_reply_keys,
handle_send_messages, handle_send_messages,
handle_conversations, handle_conversations,
handle_chat_scripts, handle_chat_scripts,
@ -109,6 +110,34 @@ pub fn handle_new_conversations(
} }
} }
fn handle_reply_keys(
keyboard_input: Res<ButtonInput<KeyCode>>,
settings: ResMut<settings::Settings>,
q_choices: Query<&ChoiceAvailable>,
mut evwriter_sendmsg: EventWriter<SendMessageEvent>,
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
) {
let mut selected_choice = 1;
'outer: for key in settings.get_reply_keys() {
if keyboard_input.just_pressed(key) {
let mut count = 1;
for choice in &q_choices {
if count == selected_choice {
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
evwriter_sendmsg.send(SendMessageEvent {
conv_id: choice.conv_id.clone(),
conv_label: choice.conv_label.clone(),
text: choice.text.clone(),
});
break 'outer;
}
count += 1;
}
}
selected_choice += 1;
}
}
pub fn handle_send_messages( pub fn handle_send_messages(
mut commands: Commands, mut commands: Commands,
mut er_sendmsg: EventReader<SendMessageEvent>, mut er_sendmsg: EventReader<SendMessageEvent>,

View file

@ -477,8 +477,6 @@ fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: ResMut<settings::Settings>, mut settings: ResMut<settings::Settings>,
mut q_hud: Query<&mut Visibility, With<ToggleableHudElement>>, mut q_hud: Query<&mut Visibility, With<ToggleableHudElement>>,
q_choices: Query<&chat::ChoiceAvailable>,
mut evwriter_sendmsg: EventWriter<chat::SendMessageEvent>,
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>, mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
mut evwriter_togglemusic: EventWriter<audio::ToggleMusicEvent>, mut evwriter_togglemusic: EventWriter<audio::ToggleMusicEvent>,
mut ambient_light: ResMut<AmbientLight>, mut ambient_light: ResMut<AmbientLight>,
@ -501,24 +499,4 @@ fn handle_input(
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch)); evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
evwriter_togglemusic.send(audio::ToggleMusicEvent()); evwriter_togglemusic.send(audio::ToggleMusicEvent());
} }
let mut selected_choice = 1;
'outer: for key in settings.get_reply_keys() {
if keyboard_input.just_pressed(key) {
let mut count = 1;
for choice in &q_choices {
if count == selected_choice {
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
evwriter_sendmsg.send(chat::SendMessageEvent {
conv_id: choice.conv_id.clone(),
conv_label: choice.conv_label.clone(),
text: choice.text.clone(),
});
break 'outer;
}
count += 1;
}
}
selected_choice += 1;
}
} }