implement chat speed setting

This commit is contained in:
yuni 2024-04-13 01:34:18 +02:00
parent c0672f0ad8
commit 1fd0481ec4
2 changed files with 9 additions and 3 deletions

View file

@ -1,7 +1,7 @@
extern crate yaml_rust; extern crate yaml_rust;
use bevy::prelude::*; use bevy::prelude::*;
use yaml_rust::{Yaml, YamlLoader}; use yaml_rust::{Yaml, YamlLoader};
use crate::{audio, hud, world}; use crate::{audio, hud, settings, world};
pub const CHATS: &[&str] = &[ pub const CHATS: &[&str] = &[
include_str!("chats/serenity.yaml"), include_str!("chats/serenity.yaml"),
@ -9,7 +9,8 @@ pub const CHATS: &[&str] = &[
]; ];
pub const TOKEN_CHAT: &str = "chat"; pub const TOKEN_CHAT: &str = "chat";
pub const TALKER_SPEED_FACTOR: f32 = 1.0 / 17.0; pub const LETTERS_PER_SECOND: f32 = 17.0;
pub const TALKER_SPEED_FACTOR: f32 = settings::DEFAULT_CHAT_SPEED / LETTERS_PER_SECOND;
pub const CHAT_SPEED_MIN_LEN: f32 = 40.0; pub const CHAT_SPEED_MIN_LEN: f32 = 40.0;
pub const NAME_FALLBACK: &str = "Unknown"; pub const NAME_FALLBACK: &str = "Unknown";
@ -176,6 +177,7 @@ pub fn handle_chat_events(
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)>,
time: Res<Time>, time: Res<Time>,
settings: Res<settings::Settings>,
) { ) {
for event in er_chatevent.read() { for event in er_chatevent.read() {
let now = time.elapsed_seconds_f64(); let now = time.elapsed_seconds_f64();
@ -196,7 +198,7 @@ pub fn handle_chat_events(
} }
ChatEvent::DisplayMessage(message) => { ChatEvent::DisplayMessage(message) => {
log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string())); log.chat(message.into(), chat.talker.name.clone().unwrap_or(NAME_FALLBACK.to_string()));
chat.timer = now + ((message.len() as f32).max(CHAT_SPEED_MIN_LEN) * TALKER_SPEED_FACTOR * chat.talker.talking_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;
} }
} }
} }

View file

@ -1,6 +1,8 @@
use bevy::prelude::*; use bevy::prelude::*;
use std::env; use std::env;
pub const DEFAULT_CHAT_SPEED: f32 = 10.0;
#[derive(Resource)] #[derive(Resource)]
pub struct Settings { pub struct Settings {
pub dev_mode: bool, pub dev_mode: bool,
@ -16,6 +18,7 @@ pub struct Settings {
pub zoom_sensitivity_factor: f32, pub zoom_sensitivity_factor: f32,
pub font_size_hud: f32, pub font_size_hud: f32,
pub font_size_conversations: f32, pub font_size_conversations: f32,
pub chat_speed: f32,
pub hud_active: bool, pub hud_active: bool,
pub is_zooming: bool, pub is_zooming: bool,
pub third_person: bool, pub third_person: bool,
@ -100,6 +103,7 @@ impl Default for Settings {
zoom_sensitivity_factor: 0.25, zoom_sensitivity_factor: 0.25,
font_size_hud: 32.0, font_size_hud: 32.0,
font_size_conversations: 32.0, font_size_conversations: 32.0,
chat_speed: DEFAULT_CHAT_SPEED,
hud_active: false, hud_active: false,
is_zooming: false, is_zooming: false,
third_person: false, third_person: false,