diff --git a/src/chat.rs b/src/chat.rs index 428d8e6..938510c 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,11 +1,17 @@ extern crate yaml_rust; use bevy::prelude::*; +pub const CHATS: &[&str] = &[ + include_str!("chats/serenity.yaml"), + include_str!("chats/startrans.yaml"), +]; + pub struct ChatPlugin; impl Plugin for ChatPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, load_chats); app.add_event::(); + app.insert_resource(ChatDB(Vec::new())); } } @@ -28,20 +34,12 @@ pub struct StartConversationEvent { #[derive(Resource)] pub struct ChatDB(Vec); -pub fn load_chats( - mut commands: Commands, -) { - let yaml_strings = [ - include_str!("chats/serenity.yaml"), - include_str!("chats/startrans.yaml"), - ]; - let yaml_data = yaml_strings.join("\n\n---\n\n"); - - if let Ok(yaml_data) = yaml_rust::YamlLoader::load_from_str(yaml_data.as_str()) { - commands.insert_resource(ChatDB(yaml_data)); - } - else { - error!("Could not load chat definitions. Validate files in `src/chats/` path."); - commands.insert_resource(ChatDB(Vec::new())); +pub fn load_chats(mut chatdb: ResMut) { + for chat_yaml in CHATS { + if let Ok(mut yaml_data) = yaml_rust::YamlLoader::load_from_str(chat_yaml) { + chatdb.0.append(&mut yaml_data); + } else { + error!("Could not load chat definitions. Validate files in `src/chats/` path."); + } } }