spawn chat entity. limit number of chats to 1
This commit is contained in:
parent
14ef824b17
commit
ca709080eb
27
src/chat.rs
27
src/chat.rs
|
@ -1,7 +1,7 @@
|
||||||
extern crate yaml_rust;
|
extern crate yaml_rust;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use yaml_rust::{Yaml, YamlLoader};
|
use yaml_rust::{Yaml, YamlLoader};
|
||||||
use crate::{audio};
|
use crate::{audio, world};
|
||||||
|
|
||||||
pub const CHATS: &[&str] = &[
|
pub const CHATS: &[&str] = &[
|
||||||
include_str!("chats/serenity.yaml"),
|
include_str!("chats/serenity.yaml"),
|
||||||
|
@ -22,6 +22,13 @@ impl Plugin for ChatPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Chat {
|
||||||
|
pub id: u32,
|
||||||
|
pub position: u32,
|
||||||
|
pub timer: f64,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct ChatDB(Vec<Yaml>);
|
pub struct ChatDB(Vec<Yaml>);
|
||||||
impl ChatDB {
|
impl ChatDB {
|
||||||
|
@ -68,17 +75,29 @@ pub fn load_chats(mut chatdb: ResMut<ChatDB>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_new_conversations(
|
pub fn handle_new_conversations(
|
||||||
//mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut er_conv: EventReader<StartConversationEvent>,
|
mut er_conv: EventReader<StartConversationEvent>,
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
chatdb: Res<ChatDB>,
|
chatdb: Res<ChatDB>,
|
||||||
//time: Res<Time>,
|
q_chats: Query<&Chat>,
|
||||||
|
time: Res<Time>,
|
||||||
) {
|
) {
|
||||||
|
if !q_chats.is_empty() {
|
||||||
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
|
||||||
|
return;
|
||||||
|
}
|
||||||
for event in er_conv.read() {
|
for event in er_conv.read() {
|
||||||
match (*chatdb).get_chat_by_id(&event.talker.conv_id) {
|
match (*chatdb).get_chat_by_id(&event.talker.conv_id) {
|
||||||
Ok(chat_id) => {
|
Ok(chat_id) => {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Ping));
|
||||||
dbg!(chat_id);
|
commands.spawn((
|
||||||
|
Chat {
|
||||||
|
id: chat_id,
|
||||||
|
position: 1, // not 0, since the first item is always the chat name
|
||||||
|
timer: time.elapsed_seconds_f64(),
|
||||||
|
},
|
||||||
|
world::DespawnOnPlayerDeath,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
error!("Error while looking for chat ID: {error}");
|
error!("Error while looking for chat ID: {error}");
|
||||||
|
|
Loading…
Reference in a new issue