From 56385b257d7765668178f2102489f76d0e114c4a Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 12 Apr 2024 20:39:10 +0200 Subject: [PATCH] rip out existing chat implementation (this was SO satisfying) --- src/actor.rs | 12 +- src/chat.rs | 390 +------------------------------------- src/chat_old.rs | 406 ++++++++++++++++++++++++++++++++++++++++ src/chats/serenity.yaml | 8 + src/commands.rs | 92 ++++----- src/defs.txt | 188 ------------------- src/hud.rs | 2 +- src/main.rs | 4 +- 8 files changed, 473 insertions(+), 629 deletions(-) create mode 100644 src/chat_old.rs diff --git a/src/actor.rs b/src/actor.rs index 35a3b31..8b38d41 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use bevy_xpbd_3d::prelude::*; use bevy::scene::SceneInstance; use bevy::math::DVec3; -use crate::{actor, audio, camera, chat2, commands, effects, hud, nature, settings, world}; +use crate::{actor, audio, camera, chat, commands, effects, hud, nature, settings, world}; pub const ENGINE_SPEED_FACTOR: f32 = 30.0; const MAX_TRANSMISSION_DISTANCE: f32 = 60.0; @@ -235,11 +235,11 @@ pub fn handle_input( mut commands: Commands, keyboard_input: Res>, mut settings: ResMut, - q_talker: Query<(&chat2::Talker, &Transform), (Without, Without)>, + q_talker: Query<(&chat::Talker, &Transform), (Without, Without)>, player: Query>, q_camera: Query<&Transform, With>, q_vehicles: Query<(Entity, &Transform), (With, Without, Without)>, - mut ew_conv: EventWriter, + mut ew_conv: EventWriter, mut ew_vehicle: EventWriter, mut ew_playerdies: EventWriter, q_player_drives: Query>, @@ -252,14 +252,14 @@ pub fn handle_input( if keyboard_input.just_pressed(settings.key_interact) { // Talking to people - let objects: Vec<(chat2::Talker, &Transform)> = q_talker + let objects: Vec<(chat::Talker, &Transform)> = q_talker .iter() .map(|(talker, transform)| (talker.clone(), transform)) .collect(); // TODO: replace Transform.translation with Position - if let (Some(talker), dist) = camera::find_closest_target::(objects, camtrans) { + if let (Some(talker), dist) = camera::find_closest_target::(objects, camtrans) { if dist <= MAX_TRANSMISSION_DISTANCE { - ew_conv.send(chat2::StartConversationEvent{talker: talker.clone()}); + ew_conv.send(chat::StartConversationEvent{talker: talker.clone()}); } } // Entering Vehicles diff --git a/src/chat.rs b/src/chat.rs index eef5710..def0606 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,79 +1,12 @@ use bevy::prelude::*; -use bevy_xpbd_3d::prelude::*; -use bevy::math::DVec3; -use crate::{actor, audio, hud, settings, world, effects}; pub struct ChatPlugin; impl Plugin for ChatPlugin { fn build(&self, app: &mut App) { - app.register_type::(); - app.add_systems(Update, ( - handle_new_conversations, - handle_reply_keys, - handle_send_messages, - handle_conversations, - handle_chat_scripts, - )); - app.add_systems(PostUpdate, despawn_old_choices); 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(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)] -pub struct ChoiceAvailable { - pub conv_id: String, - pub conv_label: String, - pub recipient: String, - pub text: String, -} - - #[derive(Component)] #[derive(Clone)] pub struct Talker { @@ -82,325 +15,10 @@ pub struct Talker { } impl Default for Talker { fn default() -> Self { Self { pronoun: "they/them".to_string(), - conv_id: "error".to_string(), + conv_id: "undefined".to_string(), }}} -pub fn handle_new_conversations( - mut commands: Commands, - mut er_conv: EventReader, - mut ew_sfx: EventWriter, - q_conv: Query<&Chat>, - time: Res