pub struct ArcadeState {
pub high_score: u32,
pub games_played: u32,
pub achievements: Vec<String>,
}Expand description
Serializable progress state for Arcade mode.
use limitless_cli::models::ArcadeState;
let mut arcade = ArcadeState::default();
let new_record = arcade.record_game(2500);
arcade.unlock_achievement("first-win");
assert!(new_record);
let json = serde_json::to_string(&arcade).unwrap();
let back: ArcadeState = serde_json::from_str(&json).unwrap();
assert_eq!(back.high_score, 2500);
assert_eq!(back.games_played, 1);
assert_eq!(back.achievements, vec!["first-win"]);Fields§
§high_score: u32The best score achieved so far.
games_played: u32Total number of games played.
achievements: Vec<String>Names of unlocked achievements (kept unique).
Implementations§
Source§impl ArcadeState
impl ArcadeState
Sourcepub fn record_game(&mut self, score: u32) -> bool
pub fn record_game(&mut self, score: u32) -> bool
Records a finished game. Returns true when a new high score was set.
Sourcepub fn unlock_achievement(&mut self, name: impl Into<String>) -> bool
pub fn unlock_achievement(&mut self, name: impl Into<String>) -> bool
Unlocks an achievement. Returns false if it was already unlocked.
Trait Implementations§
Source§impl Clone for ArcadeState
impl Clone for ArcadeState
Source§impl Debug for ArcadeState
impl Debug for ArcadeState
Source§impl Default for ArcadeState
impl Default for ArcadeState
Source§impl<'de> Deserialize<'de> for ArcadeState
impl<'de> Deserialize<'de> for ArcadeState
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for ArcadeState
Source§impl PartialEq for ArcadeState
impl PartialEq for ArcadeState
Source§impl Serialize for ArcadeState
impl Serialize for ArcadeState
impl StructuralPartialEq for ArcadeState
Auto Trait Implementations§
impl Forget for ArcadeState
impl Freeze for ArcadeState
impl RefUnwindSafe for ArcadeState
impl Send for ArcadeState
impl Sync for ArcadeState
impl Unpin for ArcadeState
impl UnsafeUnpin for ArcadeState
impl UnwindSafe for ArcadeState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more