cleanup
This commit is contained in:
parent
0117a6d4d2
commit
253604e9aa
26
src/chat.rs
26
src/chat.rs
|
@ -1,11 +1,17 @@
|
||||||
extern crate yaml_rust;
|
extern crate yaml_rust;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub const CHATS: &[&str] = &[
|
||||||
|
include_str!("chats/serenity.yaml"),
|
||||||
|
include_str!("chats/startrans.yaml"),
|
||||||
|
];
|
||||||
|
|
||||||
pub struct ChatPlugin;
|
pub struct ChatPlugin;
|
||||||
impl Plugin for ChatPlugin {
|
impl Plugin for ChatPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, load_chats);
|
app.add_systems(Startup, load_chats);
|
||||||
app.add_event::<StartConversationEvent>();
|
app.add_event::<StartConversationEvent>();
|
||||||
|
app.insert_resource(ChatDB(Vec::new()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,20 +34,12 @@ pub struct StartConversationEvent {
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct ChatDB(Vec<yaml_rust::Yaml>);
|
pub struct ChatDB(Vec<yaml_rust::Yaml>);
|
||||||
|
|
||||||
pub fn load_chats(
|
pub fn load_chats(mut chatdb: ResMut<ChatDB>) {
|
||||||
mut commands: Commands,
|
for chat_yaml in CHATS {
|
||||||
) {
|
if let Ok(mut yaml_data) = yaml_rust::YamlLoader::load_from_str(chat_yaml) {
|
||||||
let yaml_strings = [
|
chatdb.0.append(&mut yaml_data);
|
||||||
include_str!("chats/serenity.yaml"),
|
} else {
|
||||||
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.");
|
error!("Could not load chat definitions. Validate files in `src/chats/` path.");
|
||||||
commands.insert_resource(ChatDB(Vec::new()));
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue