Skip to content

Commit

Permalink
Parametize dialog speed
Browse files Browse the repository at this point in the history
Former-commit-id: 7451850
  • Loading branch information
janhohenheim committed Mar 20, 2023
1 parent 5c54fd8 commit e23ddc2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions assets/config/config.game.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ sprint_effect_speed_threshold = 7.0
fov_saturation_speed = 12.0
min_fov = 0.75
max_fov = 1.5

[dialog]
base_letters_per_second = 60.0
7 changes: 7 additions & 0 deletions src/file_system_interaction/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct GameConfig {
pub camera: Camera,
pub characters: Characters,
pub player: Player,
pub dialog: Dialog,
}

#[derive(Debug, Clone, PartialEq, Reflect, FromReflect, Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -87,3 +88,9 @@ pub struct Player {
pub min_fov: f32,
pub max_fov: f32,
}

#[derive(Debug, Clone, PartialEq, Reflect, FromReflect, Serialize, Deserialize, Default)]
#[reflect(Serialize, Deserialize)]
pub struct Dialog {
pub base_letters_per_second: f32,
}
2 changes: 2 additions & 0 deletions src/movement/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ use oxidized_navigation::{
};
use serde::{Deserialize, Serialize};

/// Manually tweaked
const CELL_WIDTH: f32 = 0.4 * npc::RADIUS;

/// Handles NPC pathfinding. Currently, all entities with the [`Follower`] component will follow the [`Player`].
pub fn navigation_plugin(app: &mut App) {
app.add_plugin(OxidizedNavigationPlugin)
// consts manually tweaked
.insert_resource(NavMeshSettings {
cell_width: CELL_WIDTH,
cell_height: 0.5 * CELL_WIDTH,
Expand Down
10 changes: 6 additions & 4 deletions src/world_interaction/dialog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::file_system_interaction::asset_loading::DialogAssets;
use crate::file_system_interaction::config::GameConfig;
use crate::player_control::actions::{ActionsFrozen, PlayerAction};
use crate::world_interaction::condition::{ActiveConditions, ConditionAddEvent, ConditionId};
use crate::world_interaction::dialog::resources::Page;
Expand Down Expand Up @@ -104,6 +105,7 @@ fn show_dialog(
actions: Query<&ActionState<PlayerAction>>,
time: Res<Time>,
mut elapsed_time: Local<f32>,
config: Res<GameConfig>,
) -> Result<()> {
let Some(mut current_dialog) = current_dialog else {
*elapsed_time = 0.0;
Expand All @@ -120,7 +122,7 @@ fn show_dialog(
ui.set_width(dialog_size.x);
ui.set_height(dialog_size.y);

let dialog_text = create_dialog_rich_text(&current_page, *elapsed_time);
let dialog_text = create_dialog_rich_text(&current_page, *elapsed_time, &config);
ui.vertical(|ui| {
ui.add_space(5.);
ui.label(&dialog_text);
Expand Down Expand Up @@ -250,9 +252,9 @@ fn set_dialog_style(style: &mut egui::Style) {
style.visuals.widgets.noninteractive.fg_stroke.color = egui::Color32::from_gray(250);
}

fn create_dialog_rich_text(page: &Page, elapsed_time: f32) -> String {
const BASE_LETTERS_PER_SECOND: f32 = 60.;
let letters_to_display = (BASE_LETTERS_PER_SECOND * page.talking_speed * elapsed_time) as usize;
fn create_dialog_rich_text(page: &Page, elapsed_time: f32, config: &GameConfig) -> String {
let base_letters_per_second = config.dialog.base_letters_per_second;
let letters_to_display = (base_letters_per_second * page.talking_speed * elapsed_time) as usize;
page.text.graphemes(true).take(letters_to_display).collect()
}

Expand Down

0 comments on commit e23ddc2

Please sign in to comment.