2024-04-12 19:26:23 +00:00
|
|
|
extern crate yaml_rust;
|
2024-04-04 11:33:54 +00:00
|
|
|
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);
|
2024-04-04 11:33:54 +00:00
|
|
|
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(),
|
2024-04-12 18:39:10 +00:00
|
|
|
conv_id: "undefined".to_string(),
|
2024-04-04 11:33:54 +00:00
|
|
|
}}}
|
|
|
|
|
2024-04-12 18:39:10 +00:00
|
|
|
#[derive(Event)]
|
|
|
|
pub struct StartConversationEvent {
|
|
|
|
pub talker: Talker,
|
2024-04-04 11:39:49 +00:00
|
|
|
}
|
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()));
|
|
|
|
}
|
|
|
|
}
|