outfly/src/chat.rs

46 lines
1.1 KiB
Rust
Raw Normal View History

2024-04-12 19:26:23 +00:00
extern crate yaml_rust;
use bevy::prelude::*;
2024-04-12 19:34:55 +00:00
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) {
2024-04-12 19:26:23 +00:00
app.add_systems(Startup, load_chats);
app.add_event::<StartConversationEvent>();
2024-04-12 19:34:55 +00:00
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,
}
2024-04-12 19:26:23 +00:00
#[derive(Resource)]
pub struct ChatDB(Vec<yaml_rust::Yaml>);
2024-04-12 19:34:55 +00:00
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.");
}
2024-04-12 19:26:23 +00:00
}
}