implement persistent phonebook
This commit is contained in:
parent
b9708f7839
commit
c787e7caf4
41
src/chat.rs
41
src/chat.rs
|
@ -26,6 +26,8 @@ pub const CHATS: &[&str] = &[
|
||||||
include_str!("chats/thebe.yaml"),
|
include_str!("chats/thebe.yaml"),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
pub const CONTACTS: &[&str] = &["icarus", "travel", "luna", "nox"];
|
||||||
|
|
||||||
pub const TEXT_CONTINUE: &str = "Continue...";
|
pub const TEXT_CONTINUE: &str = "Continue...";
|
||||||
|
|
||||||
pub const TOKEN_CHAT: &str = "chat";
|
pub const TOKEN_CHAT: &str = "chat";
|
||||||
|
@ -897,6 +899,7 @@ pub fn handle_chat_scripts(
|
||||||
mut ew_achievement: EventWriter<game::AchievementEvent>,
|
mut ew_achievement: EventWriter<game::AchievementEvent>,
|
||||||
id2pos: Res<game::Id2Pos>,
|
id2pos: Res<game::Id2Pos>,
|
||||||
id2v: Res<game::Id2V>,
|
id2v: Res<game::Id2V>,
|
||||||
|
mut prefs: ResMut<Preferences>,
|
||||||
) {
|
) {
|
||||||
for script in er_chatscript.read() {
|
for script in er_chatscript.read() {
|
||||||
// Parse the script string
|
// Parse the script string
|
||||||
|
@ -1020,6 +1023,14 @@ pub fn handle_chat_scripts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"registercontact" => {
|
||||||
|
if CONTACTS.contains(¶m1) {
|
||||||
|
prefs.contacts.push(param1.to_string());
|
||||||
|
prefs.save();
|
||||||
|
} else {
|
||||||
|
error!("Can't register contact `{param1}', it doesn't exist in the chat::CONTACTS constant.");
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
error!("Error, undefined chat script {name}");
|
error!("Error, undefined chat script {name}");
|
||||||
}
|
}
|
||||||
|
@ -1030,6 +1041,7 @@ pub fn handle_chat_scripts(
|
||||||
pub fn update_chat_variables(
|
pub fn update_chat_variables(
|
||||||
mut vars: ResMut<var::GameVars>,
|
mut vars: ResMut<var::GameVars>,
|
||||||
settings: Res<var::Settings>,
|
settings: Res<var::Settings>,
|
||||||
|
prefs: Res<var::Preferences>,
|
||||||
q_player: Query<&actor::Suit, With<actor::Player>>,
|
q_player: Query<&actor::Suit, With<actor::Player>>,
|
||||||
) {
|
) {
|
||||||
if let Ok(suit) = q_player.get_single() {
|
if let Ok(suit) = q_player.get_single() {
|
||||||
|
@ -1043,15 +1055,7 @@ pub fn update_chat_variables(
|
||||||
"player_suit_health_percent",
|
"player_suit_health_percent",
|
||||||
((suit.integrity * 100.0).round() as u8).to_string(),
|
((suit.integrity * 100.0).round() as u8).to_string(),
|
||||||
);
|
);
|
||||||
vars.set_in_scope(
|
vars.set_in_scope("$", "ar", bool2chatvar(settings.hud_active));
|
||||||
"$",
|
|
||||||
"ar",
|
|
||||||
if settings.hud_active {
|
|
||||||
String::from("1")
|
|
||||||
} else {
|
|
||||||
String::from("0")
|
|
||||||
},
|
|
||||||
);
|
|
||||||
let wears_chefhat = if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
|
let wears_chefhat = if let Some(ava) = hud::PLAYER_AR_AVATARS.get(settings.ar_avatar) {
|
||||||
match ava.0 {
|
match ava.0 {
|
||||||
hud::Avatar::ChefHat => 1,
|
hud::Avatar::ChefHat => 1,
|
||||||
|
@ -1061,5 +1065,24 @@ pub fn update_chat_variables(
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
vars.set_in_scope("$", "chefhat", wears_chefhat.to_string());
|
vars.set_in_scope("$", "chefhat", wears_chefhat.to_string());
|
||||||
|
|
||||||
|
// Set phone variables
|
||||||
|
let mut any = false;
|
||||||
|
for contact in CONTACTS {
|
||||||
|
let value = prefs.contacts.contains(&contact.to_string());
|
||||||
|
if value {
|
||||||
|
any = true;
|
||||||
|
}
|
||||||
|
vars.set_in_scope("phone", contact, bool2chatvar(value));
|
||||||
|
}
|
||||||
|
vars.set_in_scope("phone", "any", bool2chatvar(any));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bool2chatvar(var: bool) -> String {
|
||||||
|
if var {
|
||||||
|
String::from("1")
|
||||||
|
} else {
|
||||||
|
String::from("0")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
- chat: phone
|
- chat: phone
|
||||||
|
- if ~phone$any:
|
||||||
|
- "Error: Phonebook empty."
|
||||||
|
- goto: EXIT
|
||||||
- Select contact to call.
|
- Select contact to call.
|
||||||
- FASTravel:
|
- if: phone$travel
|
||||||
|
FASTravel:
|
||||||
- script: changename FASTravel™ Chatbot
|
- script: changename FASTravel™ Chatbot
|
||||||
- This is FASTravel, how can I help you?
|
- This is FASTravel, how can I help you?
|
||||||
- Icarus:
|
- if: phone$icarus
|
||||||
|
Icarus:
|
||||||
- script: changename Icarus
|
- script: changename Icarus
|
||||||
- Well hi there!
|
- Well hi there!
|
||||||
- "[Cancel]":
|
- "[Cancel]":
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
- How are you doing?
|
- How are you doing?
|
||||||
- goto: howru
|
- goto: howru
|
||||||
- Oh hey, you're awake!
|
- Oh hey, you're awake!
|
||||||
|
- script: registercontact icarus
|
||||||
- set: $met
|
- set: $met
|
||||||
- I found you drifting out cold, and thought, I better watch over you.
|
- I found you drifting out cold, and thought, I better watch over you.
|
||||||
- Took us here behind that moonlet, to shield you from the micrometeorites.
|
- Took us here behind that moonlet, to shield you from the micrometeorites.
|
||||||
|
|
|
@ -477,6 +477,7 @@ pub struct Preferences {
|
||||||
#[serde(default = "Preferences::default_flashlight_power")]
|
#[serde(default = "Preferences::default_flashlight_power")]
|
||||||
pub flashlight_power: usize, // 0-2
|
pub flashlight_power: usize, // 0-2
|
||||||
pub thruster_boost: usize, // 0-2
|
pub thruster_boost: usize, // 0-2
|
||||||
|
pub contacts: Vec<String>,
|
||||||
|
|
||||||
#[serde(skip)]
|
#[serde(skip)]
|
||||||
pub source_file: Option<String>,
|
pub source_file: Option<String>,
|
||||||
|
|
Loading…
Reference in a new issue