outfly/src/chat.rs

48 lines
1.1 KiB
Rust
Raw Normal View History

2024-04-12 19:26:23 +00:00
extern crate yaml_rust;
use bevy::prelude::*;
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>();
}
}
#[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>);
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()));
}
}