hgame 0.26.4

CG production management structs, e.g. of assets, personnels, progress, etc.
Documentation
use super::{proto::hunter::*, *};
use std::collections::HashMap;

pub struct DeliNote {
    users: HashMap<u32, User>,

    /// Test shared state.
    int: i32,
    //
    // other metadata of the delivery note goes here
}

impl DeliNote {
    fn new() -> Self {
        Self {
            users: HashMap::new(),
            int: 0,
        }
    }

    fn add_user(&mut self, id: u32) {
        self.users.insert(
            id,
            User {
                name: "new user".to_string(),
            },
        );
    }

    fn remove_user(&mut self, id: &u32) {
        self.users.remove(&id);
    }

    fn set_input(&mut self, _id: u32, _input: CellInput) {
        debug!("TODO: handle input");
        // self.int = input.x as i32;
    }
}

pub fn run(tx: UnboundedSender<BroadcastEvents>, mut rx: UnboundedReceiver<CollabEvents>) {
    let mut note = DeliNote::new();

    while let Ok(event) = rx.try_recv() {
        match event {
            CollabEvents::Join(conn) => {
                note.add_user(conn.id);
                tx.send(BroadcastEvents::Join(conn)).ok();
            }
            CollabEvents::Quit(id) => {
                note.remove_user(&id);
                tx.send(BroadcastEvents::Quit(id)).ok();
            }
            CollabEvents::Input(id, input) => {
                note.set_input(id, input);
            }
        }
    }
}