jellymodel 0.1.1

Data models for jellybeanidle
Documentation
use anyhow::Result;
use bnum::types::U2048;
use serde::{Deserialize, Serialize};

use crate::comp::Comp;
use crate::jel::Jel;

#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Player {
    id: u64, //TODO: use UUID later
    pub username: String,
    pub jel: Jel,
    pub comp: Comp,
}

impl Default for Player {
    fn default() -> Self {
        Self::new()
    }
}

impl Player {
    pub fn new() -> Self {
        Self {
            id: rand::random::<u64>(),
            username: String::from("UserName"),
            jel: Jel::new(),
            comp: Comp::new(),
        }
    }
    pub fn update(&mut self) -> Result<()> {
        // We go multi-step drifting tonight
        self.jel
            .add_count(((3u64 << 8) * (256 + self.comp.rate())) >> 8);
        self.jel.big_add_count(
            ((self.comp.l1.count() << 8) * U2048::from(256 + self.comp.l1.rate().clone())) >> 8,
        );
        self.comp.l1.big_add_count(
            ((self.comp.l2.count() << 8) * U2048::from(256 + self.comp.l2.rate().clone())) >> 8,
        );
        Ok(())
    }
    pub fn id(&self) -> &u64 {
        &self.id
    }
}