cleanup
This commit is contained in:
parent
0117a6d4d2
commit
253604e9aa
28
src/chat.rs
28
src/chat.rs
|
@ -1,11 +1,17 @@
|
|||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,20 +34,12 @@ pub struct StartConversationEvent {
|
|||
#[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()));
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue