implement delays between messages
This commit is contained in:
parent
bac0b59733
commit
029a53c115
2 changed files with 28 additions and 9 deletions
|
@ -7,7 +7,7 @@
|
|||
id: "hialien",
|
||||
name: "Icarus",
|
||||
label: "INIT",
|
||||
delay: 0.0,
|
||||
delay: 3.0,
|
||||
sound: "ping",
|
||||
reply: "Requesting permission to communicate...",
|
||||
goto: "requested",
|
||||
|
@ -20,7 +20,7 @@
|
|||
id: "hialien",
|
||||
name: "Icarus",
|
||||
label: "requested",
|
||||
delay: 1.0,
|
||||
delay: 5.0,
|
||||
sound: "chat",
|
||||
reply: "Oh hey there, didn't even notice you! Was playing some VR game! What's up?",
|
||||
goto: "reply1",
|
||||
|
@ -33,9 +33,22 @@
|
|||
id: "hialien",
|
||||
name: "Icarus",
|
||||
label: "reply1",
|
||||
delay: 3.0,
|
||||
delay: 1.0,
|
||||
sound: "chat",
|
||||
reply: "Not so chatty, huh? That's ok. See you around.",
|
||||
goto: "disco",
|
||||
),
|
||||
},
|
||||
),
|
||||
4294967299: (
|
||||
components: {
|
||||
"outfly::actor::ChatBranch": (
|
||||
id: "hialien",
|
||||
name: "Icarus",
|
||||
label: "disco",
|
||||
delay: 0.0,
|
||||
sound: "ping",
|
||||
reply: "Disconnected.",
|
||||
goto: "EXIT",
|
||||
),
|
||||
},
|
||||
|
|
18
src/actor.rs
18
src/actor.rs
|
@ -53,7 +53,7 @@ pub struct ChatBranch {
|
|||
pub id: String,
|
||||
pub name: String,
|
||||
pub label: String,
|
||||
pub delay: f32,
|
||||
pub delay: f64,
|
||||
pub sound: String,
|
||||
pub reply: String,
|
||||
pub goto: String,
|
||||
|
@ -72,7 +72,7 @@ pub struct ChatChoice {
|
|||
pub struct Chat {
|
||||
pub id: String,
|
||||
pub label: String,
|
||||
pub timer: f32,
|
||||
pub timer: f64,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
|
@ -182,16 +182,14 @@ pub fn handle_input(
|
|||
pub fn handle_new_conversations(
|
||||
mut commands: Commands,
|
||||
mut er_conv: EventReader<StartConversationEvent>,
|
||||
mut log: ResMut<hud::Log>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
for _my_event in er_conv.read() {
|
||||
log.info("Establishing connection with Alien".to_string());
|
||||
commands.spawn(Chat {
|
||||
id: "hialien".to_string(),
|
||||
label: "INIT".to_string(),
|
||||
timer: 0.0,
|
||||
timer: time.elapsed_seconds_f64(),
|
||||
});
|
||||
//log.chat(my_event.conv.clone(), "Alien".to_string());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -201,15 +199,20 @@ pub fn handle_conversations(
|
|||
mut log: ResMut<hud::Log>,
|
||||
mut q_conv: Query<(Entity, &mut Chat)>,
|
||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
time: Res<Time>,
|
||||
chat_branches: Query<&ChatBranch>, // TODO: use Table for faster iteration?
|
||||
//chat_choices: Query<&ChatChoice>,
|
||||
) {
|
||||
let now = time.elapsed_seconds_f64();
|
||||
for (entity, mut chat) in &mut q_conv {
|
||||
if chat.label == "EXIT" {
|
||||
debug!("Despawning chat.");
|
||||
commands.entity(entity).despawn();
|
||||
continue;
|
||||
}
|
||||
if now < chat.timer {
|
||||
continue;
|
||||
}
|
||||
|
||||
let branches: Vec<&ChatBranch> = chat_branches.iter()
|
||||
.filter(|branch| branch.id == chat.id && branch.label == chat.label)
|
||||
|
@ -228,6 +231,9 @@ pub fn handle_conversations(
|
|||
let sfx = audio::str2sfx(branch.sound.as_str());
|
||||
ew_sfx.send(audio::PlaySfxEvent(sfx));
|
||||
}
|
||||
info!("<chat.timer={:.2}, branch.delay={:.2}, epoch={:.2}", chat.timer, branch.delay, now);
|
||||
chat.timer = now + branch.delay;
|
||||
info!(">chat.timer={:.2}, branch.delay={:.2}, epoch={:.2}", chat.timer, branch.delay, now);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue