implement chat sounds
This commit is contained in:
parent
b06e54a0d9
commit
699bb4f563
11
src/chat.rs
11
src/chat.rs
|
@ -20,9 +20,9 @@ pub const TOKEN_IF: &str = "if";
|
||||||
pub const TOKEN_GOTO: &str = "goto";
|
pub const TOKEN_GOTO: &str = "goto";
|
||||||
pub const TOKEN_LABEL: &str = "label";
|
pub const TOKEN_LABEL: &str = "label";
|
||||||
pub const TOKEN_SCRIPT: &str = "script";
|
pub const TOKEN_SCRIPT: &str = "script";
|
||||||
|
pub const TOKEN_SOUND: &str = "sound";
|
||||||
pub const TOKEN_GOTO_EXIT: &str = "EXIT";
|
pub const TOKEN_GOTO_EXIT: &str = "EXIT";
|
||||||
|
|
||||||
pub const NAME_FALLBACK: &str = "Unknown";
|
|
||||||
pub const MAX_BRANCH_DEPTH: usize = 64;
|
pub const MAX_BRANCH_DEPTH: usize = 64;
|
||||||
|
|
||||||
pub const CHOICE_TIMER: f64 = 40.0 * settings::DEFAULT_CHAT_SPEED as f64;
|
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_GOTO,
|
||||||
TOKEN_LABEL,
|
TOKEN_LABEL,
|
||||||
TOKEN_SCRIPT,
|
TOKEN_SCRIPT,
|
||||||
|
TOKEN_SOUND,
|
||||||
];
|
];
|
||||||
|
|
||||||
pub struct ChatPlugin;
|
pub struct ChatPlugin;
|
||||||
|
@ -409,7 +410,6 @@ pub fn handle_new_conversations(
|
||||||
}
|
}
|
||||||
match (*chatdb).get_chat_by_id(&event.talker.conv_id) {
|
match (*chatdb).get_chat_by_id(&event.talker.conv_id) {
|
||||||
Ok(chat_id) => {
|
Ok(chat_id) => {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
|
|
||||||
let mut chat = Chat {
|
let mut chat = Chat {
|
||||||
id: chat_id,
|
id: chat_id,
|
||||||
position: vec![0],
|
position: vec![0],
|
||||||
|
@ -447,6 +447,7 @@ pub fn handle_chat_events(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut er_chatevent: EventReader<ChatEvent>,
|
mut er_chatevent: EventReader<ChatEvent>,
|
||||||
mut ew_chatscript: EventWriter<ChatScriptEvent>,
|
mut ew_chatscript: EventWriter<ChatScriptEvent>,
|
||||||
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
mut log: ResMut<hud::Log>,
|
mut log: ResMut<hud::Log>,
|
||||||
q_choices: Query<Entity, With<Choice>>,
|
q_choices: Query<Entity, With<Choice>>,
|
||||||
mut q_chats: Query<(Entity, &mut Chat)>,
|
mut q_chats: Query<(Entity, &mut Chat)>,
|
||||||
|
@ -473,7 +474,7 @@ pub fn handle_chat_events(
|
||||||
ChatEvent::SpawnMessage(message, level) => {
|
ChatEvent::SpawnMessage(message, level) => {
|
||||||
match level {
|
match level {
|
||||||
hud::LogLevel::Chat => {
|
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 => {
|
hud::LogLevel::Info | hud::LogLevel::Notice => {
|
||||||
log.info(message.into());
|
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;
|
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) => {
|
ChatEvent::SpawnChoice(replytext, key, goto) => {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -523,7 +527,6 @@ fn handle_reply_keys(
|
||||||
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||||
chat.timer = time.elapsed_seconds_f64();
|
chat.timer = time.elapsed_seconds_f64();
|
||||||
chat.position = choice.goto.clone();
|
chat.position = choice.goto.clone();
|
||||||
info!("GOTO {:?}", &chat.position);
|
|
||||||
}
|
}
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue