implemented Phone Call and "script changename" command

This commit is contained in:
yuni 2024-10-26 19:36:54 +02:00
parent 242e06ebf1
commit 55426ba0dd
4 changed files with 50 additions and 0 deletions

View file

@ -21,6 +21,7 @@ use std::collections::HashMap;
pub const CHATS: &[&str] = &[ pub const CHATS: &[&str] = &[
include_str!("chats/fastravel.yaml"), include_str!("chats/fastravel.yaml"),
include_str!("chats/phone.yaml"),
include_str!("chats/serenity.yaml"), include_str!("chats/serenity.yaml"),
include_str!("chats/thebe.yaml"), include_str!("chats/thebe.yaml"),
]; ];
@ -890,6 +891,7 @@ pub fn handle_chat_scripts(
With<actor::Player>, With<actor::Player>,
>, >,
mut q_playercam: Query<(&mut Position, &mut LinearVelocity), With<actor::PlayerCamera>>, mut q_playercam: Query<(&mut Position, &mut LinearVelocity), With<actor::PlayerCamera>>,
mut q_chats: Query<&mut Chat>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_effect: EventWriter<visual::SpawnEffectEvent>, mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
mut ew_achievement: EventWriter<game::AchievementEvent>, mut ew_achievement: EventWriter<game::AchievementEvent>,
@ -1002,6 +1004,22 @@ pub fn handle_chat_scripts(
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Drink)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Drink));
ew_achievement.send(game::AchievementEvent::DrinkPizza); ew_achievement.send(game::AchievementEvent::DrinkPizza);
} }
"changename" => {
let mut new_name = param1.to_string();
if !param2.is_empty() {
if !new_name.is_empty() {
new_name += " ";
}
new_name += param2;
}
for mut chat in &mut q_chats {
if new_name.is_empty() {
chat.talker.name = None;
} else {
chat.talker.name = Some(new_name.clone());
}
}
}
_ => { _ => {
error!("Error, undefined chat script {name}"); error!("Error, undefined chat script {name}");
} }

10
src/chats/phone.yaml Normal file
View file

@ -0,0 +1,10 @@
- chat: phone
- Select contact to call.
- FASTravel:
- script: changename FASTravel™ Chatbot
- This is FASTravel, how can I help you?
- Icarus:
- script: changename Icarus
- Well hi there!
- "[Cancel]":
- goto: EXIT

View file

@ -98,6 +98,7 @@ pub enum GameEvent {
SetShadows(Turn), SetShadows(Turn),
UpdateFlashlight, UpdateFlashlight,
Achievement(String), Achievement(String),
PhoneCall,
} }
pub enum Turn { pub enum Turn {
@ -162,6 +163,7 @@ pub fn setup(mut settings: ResMut<Settings>, prefs: ResMut<var::Preferences>) {
pub fn handle_game_event( pub fn handle_game_event(
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut er_game: EventReader<GameEvent>, mut er_game: EventReader<GameEvent>,
mut ew_conv: EventWriter<chat::StartConversationEvent>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>, mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
mut ew_updatemenu: EventWriter<menu::UpdateMenuEvent>, mut ew_updatemenu: EventWriter<menu::UpdateMenuEvent>,
@ -270,6 +272,19 @@ pub fn handle_game_event(
spotlight.intensity = actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power]; spotlight.intensity = actor::FLASHLIGHT_INTENSITY[prefs.flashlight_power];
} }
} }
GameEvent::PhoneCall => {
let talker = chat::Talker {
chat_name: "phone".to_string(),
actor_id: "".to_string(),
name: Some("Phone".to_string()),
counts_towards_achievement: false,
pronoun: None,
talking_speed: 0.0,
};
ew_conv.send(chat::StartConversationEvent {
talker: talker,
});
}
} }
} }
} }

View file

@ -63,6 +63,7 @@ pub enum DeathScreenEvent {
} }
pub const MENUDEF: &[(&str, MenuAction)] = &[ pub const MENUDEF: &[(&str, MenuAction)] = &[
("Phone Call", MenuAction::PhoneCall),
("", MenuAction::ToggleAR), ("", MenuAction::ToggleAR),
("", MenuAction::ChangeARAvatar), ("", MenuAction::ChangeARAvatar),
("", MenuAction::ChangePointer), ("", MenuAction::ChangePointer),
@ -92,6 +93,7 @@ pub enum MenuAction {
ModReactor, ModReactor,
ToggleSound, ToggleSound,
ToggleMusic, ToggleMusic,
PhoneCall,
ToggleCamera, ToggleCamera,
ToggleFullscreen, ToggleFullscreen,
ToggleShadows, ToggleShadows,
@ -713,6 +715,11 @@ pub fn handle_input(
ew_game.send(GameEvent::SetShadows(Toggle)); ew_game.send(GameEvent::SetShadows(Toggle));
ew_updatemenu.send(UpdateMenuEvent); ew_updatemenu.send(UpdateMenuEvent);
} }
MenuAction::PhoneCall => {
ew_game.send(GameEvent::PhoneCall);
ew_game.send(GameEvent::SetMenu(Turn::Off));
ew_updatemenu.send(UpdateMenuEvent);
}
MenuAction::Restart => { MenuAction::Restart => {
settings.god_mode = false; settings.god_mode = false;
ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::Depressurization)); ew_playerdies.send(game::PlayerDiesEvent(actor::DamageType::Depressurization));