load chat yaml files

This commit is contained in:
yuni 2024-04-12 21:26:23 +02:00
parent b9528b3637
commit 0117a6d4d2
3 changed files with 40 additions and 0 deletions

16
Cargo.lock generated
View file

@ -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"

View file

@ -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"]

View file

@ -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::<StartConversationEvent>();
}
}
@ -22,3 +24,24 @@ impl Default for Talker { fn default() -> Self { Self {
pub struct StartConversationEvent {
pub talker: Talker,
}
#[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()));
}
}