diff --git a/src/actor.rs b/src/actor.rs index aa2c9ca..064bc7b 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; use bevy_xpbd_3d::prelude::*; -use crate::{nature, settings, actor, audio, hud}; +use crate::{actor, audio, chat, nature, settings}; pub const ENGINE_SPEED_FACTOR: f32 = 30.0; const MIN_INTERACT_DISTANCE: f32 = 30.0; @@ -9,47 +9,20 @@ const NO_RIDE: u32 = 0; pub struct ActorPlugin; impl Plugin for ActorPlugin { fn build(&self, app: &mut App) { - app.register_type::(); app.add_systems(FixedUpdate, ( update_physics_lifeforms, )); app.add_systems(Update, ( - handle_new_conversations, - handle_send_messages, - handle_conversations, handle_input, - handle_chat_scripts, handle_collisions, )); app.add_systems(PostUpdate, ( handle_vehicle_enter_exit, )); - app.add_event::(); - app.add_event::(); - app.add_event::(); app.add_event::(); } } -#[derive(Event)] -pub struct StartConversationEvent { - pub talker: Talker, -} - -#[derive(Event)] -pub struct SendMessageEvent { - pub conv_id: String, - pub conv_label: String, - pub text: String, -} - -#[derive(Event)] -pub struct ChatScriptEvent { - name: String, - param: String, - param2: String, -} - #[derive(Event)] pub struct VehicleEnterExitEvent { vehicle: Entity, @@ -87,42 +60,6 @@ impl Default for Actor { #[derive(Component)] pub struct ActorEnteringVehicle; #[derive(Component)] pub struct ActorVehicleBeingEntered; -#[derive(Debug)] -#[derive(Component, Reflect, Default)] -#[reflect(Component)] -pub struct ChatBranch { - pub id: String, - pub name: String, - pub label: String, - pub delay: f64, - pub sound: String, - pub level: String, - pub reply: String, - pub goto: String, - pub choice: String, - pub script: String, - pub script_parameter: String, - pub script_parameter2: String, -} - -#[derive(Component)] -pub struct Chat { - pub id: String, - pub label: String, - pub timer: f64, -} - -#[derive(Component)] -#[derive(Clone)] -pub struct Talker { - pub pronoun: String, - pub conv_id: String, -} -impl Default for Talker { fn default() -> Self { Self { - pronoun: "they/them".to_string(), - conv_id: "error".to_string(), -}}} - #[derive(Component)] pub struct LifeForm { pub is_alive: bool, @@ -239,10 +176,10 @@ pub fn handle_input( mut commands: Commands, keyboard_input: Res>, settings: ResMut, - q_talker: Query<(&Talker, &Transform), Without>, + q_talker: Query<(&chat::Talker, &Transform), Without>, mut player: Query<(Entity, &mut Actor, &mut Transform), With>, mut q_vehicles: Query<(Entity, &mut Visibility, &Transform), (With, Without)>, - mut ew_conv: EventWriter, + mut ew_conv: EventWriter, mut ew_vehicle: EventWriter, q_player_drives: Query>, ) { @@ -251,8 +188,9 @@ pub fn handle_input( // Talking to people if let Ok((_player_entity, _player_actor, player)) = player.get_single() { for (talker, transform) in &q_talker { + // TODO: replace Transform.translation with Position if transform.translation.distance_squared(player.translation) <= mindist { - ew_conv.send(StartConversationEvent{talker: talker.clone()}); + ew_conv.send(chat::StartConversationEvent{talker: talker.clone()}); break; } } @@ -341,225 +279,6 @@ pub fn handle_vehicle_enter_exit( } } -pub fn handle_new_conversations( - mut commands: Commands, - mut er_conv: EventReader, - mut ew_sfx: EventWriter, - q_conv: Query<&Chat>, - time: Res