load chat yaml files
This commit is contained in:
parent
b9528b3637
commit
0117a6d4d2
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -2298,6 +2298,12 @@ dependencies = [
|
||||||
"redox_syscall 0.4.1",
|
"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]]
|
[[package]]
|
||||||
name = "linux-raw-sys"
|
name = "linux-raw-sys"
|
||||||
version = "0.4.13"
|
version = "0.4.13"
|
||||||
|
@ -2776,6 +2782,7 @@ dependencies = [
|
||||||
"bevy_xpbd_3d",
|
"bevy_xpbd_3d",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"regex",
|
"regex",
|
||||||
|
"yaml-rust",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -4464,6 +4471,15 @@ version = "0.8.19"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0fcb9cbac069e033553e8bb871be2fbdffcab578eb25bd0f7c508cedc6dcd75a"
|
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]]
|
[[package]]
|
||||||
name = "zerocopy"
|
name = "zerocopy"
|
||||||
version = "0.7.32"
|
version = "0.7.32"
|
||||||
|
|
|
@ -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_xpbd_3d = { version = "0.4.2", default-features = false, features = ["3d", "f64", "parry-f64", "parallel", "async-collider"] }
|
||||||
bevy_embedded_assets = "0.10.2"
|
bevy_embedded_assets = "0.10.2"
|
||||||
fastrand = "2.0.2"
|
fastrand = "2.0.2"
|
||||||
|
yaml-rust = "0.4"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
dev = ["bevy/dynamic_linking", "bevy/file_watcher"]
|
dev = ["bevy/dynamic_linking", "bevy/file_watcher"]
|
||||||
|
|
23
src/chat.rs
23
src/chat.rs
|
@ -1,8 +1,10 @@
|
||||||
|
extern crate yaml_rust;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
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_event::<StartConversationEvent>();
|
app.add_event::<StartConversationEvent>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,3 +24,24 @@ impl Default for Talker { fn default() -> Self { Self {
|
||||||
pub struct StartConversationEvent {
|
pub struct StartConversationEvent {
|
||||||
pub talker: Talker,
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue