prevent multiple chats with the same person

This commit is contained in:
yuni 2024-03-19 06:07:20 +01:00
parent 029a53c115
commit 2f19df9f95
2 changed files with 15 additions and 3 deletions

View file

@ -20,7 +20,7 @@
id: "hialien", id: "hialien",
name: "Icarus", name: "Icarus",
label: "requested", label: "requested",
delay: 5.0, delay: 8.0,
sound: "chat", sound: "chat",
reply: "Oh hey there, didn't even notice you! Was playing some VR game! What's up?", reply: "Oh hey there, didn't even notice you! Was playing some VR game! What's up?",
goto: "reply1", goto: "reply1",

View file

@ -182,12 +182,24 @@ pub fn handle_input(
pub fn handle_new_conversations( pub fn handle_new_conversations(
mut commands: Commands, mut commands: Commands,
mut er_conv: EventReader<StartConversationEvent>, mut er_conv: EventReader<StartConversationEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_conv: Query<&Chat>,
time: Res<Time>, time: Res<Time>,
) { ) {
let id = "hialien";
let label = "INIT";
for _my_event in er_conv.read() { for _my_event in er_conv.read() {
// check for existing chats with this id
let chats: Vec<&Chat> = q_conv.iter().filter(|c| c.id == id).collect();
if chats.len() > 0 {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
continue;
}
// no existing chats yet, let's create a new one
commands.spawn(Chat { commands.spawn(Chat {
id: "hialien".to_string(), id: id.to_string(),
label: "INIT".to_string(), label: label.to_string(),
timer: time.elapsed_seconds_f64(), timer: time.elapsed_seconds_f64(),
}); });
break; break;