From bac0b59733c92a9c8d1a70a17f075f2074967709 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 19 Mar 2024 05:38:11 +0100 Subject: [PATCH] implement conversation system --- assets/scenes/conversations.scn.ron | 44 +++++++++++ src/actor.rs | 114 +++++++++++++++++++++++++++- src/audio.rs | 20 ++++- src/hud.rs | 2 +- 4 files changed, 174 insertions(+), 6 deletions(-) create mode 100644 assets/scenes/conversations.scn.ron diff --git a/assets/scenes/conversations.scn.ron b/assets/scenes/conversations.scn.ron new file mode 100644 index 0000000..5a61e8a --- /dev/null +++ b/assets/scenes/conversations.scn.ron @@ -0,0 +1,44 @@ +( + resources: {}, + entities: { + 4294967296: ( + components: { + "outfly::actor::ChatBranch": ( + id: "hialien", + name: "Icarus", + label: "INIT", + delay: 0.0, + sound: "ping", + reply: "Requesting permission to communicate...", + goto: "requested", + ), + }, + ), + 4294967297: ( + components: { + "outfly::actor::ChatBranch": ( + id: "hialien", + name: "Icarus", + label: "requested", + delay: 1.0, + sound: "chat", + reply: "Oh hey there, didn't even notice you! Was playing some VR game! What's up?", + goto: "reply1", + ), + }, + ), + 4294967298: ( + components: { + "outfly::actor::ChatBranch": ( + id: "hialien", + name: "Icarus", + label: "reply1", + delay: 3.0, + sound: "chat", + reply: "Not so chatty, huh? That's ok. See you around.", + goto: "EXIT", + ), + }, + ), + }, +) diff --git a/src/actor.rs b/src/actor.rs index 6e9f897..c26444f 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -2,12 +2,17 @@ use bevy::prelude::*; use crate::{nature, settings, actor, audio, hud}; const MIN_INTERACT_DISTANCE: f32 = 30.0; +const ASSET_CONVERSATIONS: &str = "scenes/conversations.scn.ron"; pub struct ActorPlugin; impl Plugin for ActorPlugin { fn build(&self, app: &mut App) { + app.add_systems(Startup, setup); + app.register_type::(); + app.register_type::(); app.add_systems(FixedUpdate, update); app.add_systems(Update, ( + handle_new_conversations, handle_conversations, handle_input, )); @@ -42,6 +47,34 @@ impl Default for Actor { #[derive(Component)] pub struct PlayerInConversation; #[derive(Component)] pub struct InConversationWithPlayer; +#[derive(Component, Reflect, Default)] +#[reflect(Component)] +pub struct ChatBranch { + pub id: String, + pub name: String, + pub label: String, + pub delay: f32, + pub sound: String, + pub reply: String, + pub goto: String, +} + +#[derive(Component, Reflect, Default)] +#[reflect(Component)] +pub struct ChatChoice { + pub id: String, + pub label: String, + pub choice: String, + pub goto: String, +} + +#[derive(Component)] +pub struct Chat { + pub id: String, + pub label: String, + pub timer: f32, +} + #[derive(Component)] pub struct Talker { pub conv: String, @@ -75,6 +108,37 @@ const SUIT_SIMPLE: Suit = Suit { oxygen_max: nature::OXY_D, }; +pub fn setup( + mut commands: Commands, + asset_server: Res, +) { + commands.spawn(DynamicSceneBundle { + scene: asset_server.load(ASSET_CONVERSATIONS), + ..default() + }); +} + +//#[allow(dead_code)] +//pub fn serialize( +// world: &mut World, +//) { +// let mut scene_world = World::new(); +// scene_world.spawn(ChatBranch { +// id: "hialien".to_string(), +// name: "Icarus".to_string(), +// label: "INTERACT".to_string(), +// delay: 0.0, +// reply: "Requesting permission to communicate...".to_string(), +// goto: "requested".to_string(), +// }); +// let type_registry = world.resource::().clone(); +// scene_world.insert_resource(type_registry); +// let type_registry = world.resource::(); +// let scene = DynamicScene::from_world(&scene_world); +// let serialized_scene = scene.serialize_ron(type_registry).unwrap(); +// info!("{}", serialized_scene); +//} + pub fn update( time: Res