From 699bb4f56333730ea79ca1379015b526433627af Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 13 Apr 2024 23:21:53 +0200 Subject: [PATCH] implement chat sounds --- src/chat.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index f3ad4d6..57502c9 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -20,9 +20,9 @@ pub const TOKEN_IF: &str = "if"; pub const TOKEN_GOTO: &str = "goto"; pub const TOKEN_LABEL: &str = "label"; pub const TOKEN_SCRIPT: &str = "script"; +pub const TOKEN_SOUND: &str = "sound"; pub const TOKEN_GOTO_EXIT: &str = "EXIT"; -pub const NAME_FALLBACK: &str = "Unknown"; pub const MAX_BRANCH_DEPTH: usize = 64; pub const CHOICE_TIMER: f64 = 40.0 * settings::DEFAULT_CHAT_SPEED as f64; @@ -41,6 +41,7 @@ pub const NON_CHOICE_TOKENS: &[&str] = &[ TOKEN_GOTO, TOKEN_LABEL, TOKEN_SCRIPT, + TOKEN_SOUND, ]; pub struct ChatPlugin; @@ -409,7 +410,6 @@ pub fn handle_new_conversations( } match (*chatdb).get_chat_by_id(&event.talker.conv_id) { Ok(chat_id) => { - ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping)); let mut chat = Chat { id: chat_id, position: vec![0], @@ -447,6 +447,7 @@ pub fn handle_chat_events( mut commands: Commands, mut er_chatevent: EventReader, mut ew_chatscript: EventWriter, + mut ew_sfx: EventWriter, mut log: ResMut, q_choices: Query>, mut q_chats: Query<(Entity, &mut Chat)>, @@ -473,7 +474,7 @@ pub fn handle_chat_events( ChatEvent::SpawnMessage(message, level) => { match level { hud::LogLevel::Chat => { - log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string())); + log.chat(message.into(), chat.talker.name.clone().unwrap_or("".to_string())); } hud::LogLevel::Info | hud::LogLevel::Notice => { log.info(message.into()); @@ -483,6 +484,9 @@ pub fn handle_chat_events( } } chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_speed / settings.chat_speed) as f64; + + let sfx = audio::str2sfx("chat"); + ew_sfx.send(audio::PlaySfxEvent(sfx)); } ChatEvent::SpawnChoice(replytext, key, goto) => { commands.spawn(( @@ -523,7 +527,6 @@ fn handle_reply_keys( evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); chat.timer = time.elapsed_seconds_f64(); chat.position = choice.goto.clone(); - info!("GOTO {:?}", &chat.position); } break 'outer; }