From 0117a6d4d2b399fcb7657d926e3a6b43af1dd1c1 Mon Sep 17 00:00:00 2001 From: hut Date: Fri, 12 Apr 2024 21:26:23 +0200 Subject: [PATCH] load chat yaml files --- Cargo.lock | 16 ++++++++++++++++ Cargo.toml | 1 + src/chat.rs | 23 +++++++++++++++++++++++ 3 files changed, 40 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 4026c84..146e353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2298,6 +2298,12 @@ dependencies = [ "redox_syscall 0.4.1", ] +[[package]] +name = "linked-hash-map" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" + [[package]] name = "linux-raw-sys" version = "0.4.13" @@ -2776,6 +2782,7 @@ dependencies = [ "bevy_xpbd_3d", "fastrand", "regex", + "yaml-rust", ] [[package]] @@ -4464,6 +4471,15 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a" +[[package]] +name = "yaml-rust" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" +dependencies = [ + "linked-hash-map", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/Cargo.toml b/Cargo.toml index 138645b..a910364 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ bevy = { version = "0.13.1", default-features = false, features = ["jpeg", "bevy bevy_xpbd_3d = { version = "0.4.2", default-features = false, features = ["3d", "f64", "parry-f64", "parallel", "async-collider"] } bevy_embedded_assets = "0.10.2" fastrand = "2.0.2" +yaml-rust = "0.4" [features] dev = ["bevy/dynamic_linking", "bevy/file_watcher"] diff --git a/src/chat.rs b/src/chat.rs index def0606..428d8e6 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,8 +1,10 @@ +extern crate yaml_rust; use bevy::prelude::*; pub struct ChatPlugin; impl Plugin for ChatPlugin { fn build(&self, app: &mut App) { + app.add_systems(Startup, load_chats); app.add_event::(); } } @@ -22,3 +24,24 @@ impl Default for Talker { fn default() -> Self { Self { pub struct StartConversationEvent { pub talker: Talker, } + +#[derive(Resource)] +pub struct ChatDB(Vec); + +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())); + } +}