From 2aaecdc113d900b57f51cba4a30c64019b119a24 Mon Sep 17 00:00:00 2001 From: hut Date: Sat, 13 Apr 2024 00:05:42 +0200 Subject: [PATCH] start implementing ChatDB.advance_chat() --- src/chat.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 2141bf8..9194681 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -16,8 +16,10 @@ impl Plugin for ChatPlugin { app.add_systems(Startup, load_chats); app.add_systems(Update, ( handle_new_conversations, + handle_chat_events.after(handle_new_conversations), )); app.add_event::(); + app.add_event::(); app.insert_resource(ChatDB(Vec::new())); } } @@ -29,6 +31,9 @@ pub struct Chat { pub timer: f64, } +#[derive(Component)] +pub struct Choice; + #[derive(Resource)] pub struct ChatDB(Vec); impl ChatDB { @@ -49,6 +54,10 @@ impl ChatDB { } return Err(format!("No chat with the conversation ID `{id}` was found.")); } + pub fn advance_chat(&self, chat: &mut Chat, event: &mut EventWriter) { + event.send(ChatEvent::DespawnAllChoices); + chat.position += 1; + } } #[derive(Component)] @@ -64,6 +73,14 @@ pub struct StartConversationEvent { pub talker: Talker, } +#[derive(Event)] +pub enum ChatEvent { + DespawnAllChoices, + //ShowMessage(String), + //SpawnChoice(String), + //Script(String, String, String), +} + pub fn load_chats(mut chatdb: ResMut) { for chat_yaml in CHATS { if let Ok(mut yaml_data) = YamlLoader::load_from_str(chat_yaml) { @@ -78,24 +95,27 @@ pub fn handle_new_conversations( mut commands: Commands, mut er_conv: EventReader, mut ew_sfx: EventWriter, + mut ew_chatevent: EventWriter, chatdb: Res, q_chats: Query<&Chat>, time: Res