Condorra
261151881d
This is the start of being able to implement following in a way that works for NPCs, but it isn't finished yet. It does mean NPCs can do things like climb immediately, and will make it far simpler for NPCs to do other player-like actions in the future.
38 lines
1003 B
Rust
38 lines
1003 B
Rust
use chrono::{DateTime, Utc};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
|
#[serde(default)]
|
|
pub struct Session {
|
|
pub source: String,
|
|
pub less_explicit_mode: bool,
|
|
pub last_active: Option<DateTime<Utc>>,
|
|
// Reminder: Consider backwards compatibility when updating this. New fields should generally
|
|
// be an Option, or you should ensure the default value is sensible, or things will
|
|
// crash out for existing sessions.
|
|
}
|
|
|
|
impl Session {
|
|
pub fn explicit_if_allowed<'l>(
|
|
self: &Self,
|
|
explicit: &'l str,
|
|
non_explicit: Option<&'l str>,
|
|
) -> &'l str {
|
|
if self.less_explicit_mode {
|
|
non_explicit.unwrap_or(explicit)
|
|
} else {
|
|
explicit
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Default for Session {
|
|
fn default() -> Self {
|
|
Session {
|
|
source: "unknown".to_owned(),
|
|
less_explicit_mode: false,
|
|
last_active: None,
|
|
}
|
|
}
|
|
}
|