aboutsummaryrefslogtreecommitdiff
path: root/src/map.rs
blob: 6d279db468e3e109516cd4f33990ff1765bdf097 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Implements a map graph and world logic

use crate::{
    data::{Link, Node},
    server::{Result, ServerErr},
    wire::Response
};
use async_std::sync::Arc;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

/// A map that people fight on
///
/// A map is defined by it's graph relationships, but also where on
/// the map nodes are placed, how much spacing there is, etc.  All
/// this information is encoded in the same structs because it's
/// static, and just more convenient.
#[derive(Default, Serialize, Deserialize)]
pub struct Map {
    /// Node IDs mapped to node objects
    nodes: BTreeMap<u16, Arc<Node>>,
    /// Link IDs mapped to link objects
    links: BTreeMap<u16, Arc<Link>>,
}

impl Map {
    pub fn new() -> Arc<Self> {
        Arc::new(Self::default())
    }

    pub fn update<F>(&mut self, cb: F) -> Result<Response>
    where
        F: Fn(&mut Map) -> Result<Response>,
    {
        unimplemented!()
    }
}