outfly/src/chat.rs
2024-04-12 21:45:36 +02:00

46 lines
1.1 KiB
Rust

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::<StartConversationEvent>();
app.insert_resource(ChatDB(Vec::new()));
}
}
#[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: "undefined".to_string(),
}}}
#[derive(Event)]
pub struct StartConversationEvent {
pub talker: Talker,
}
#[derive(Resource)]
pub struct ChatDB(Vec<yaml_rust::Yaml>);
pub fn load_chats(mut chatdb: ResMut<ChatDB>) {
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.");
}
}
}