aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-core/src/config/mod.rs
blob: 447c0fcbcc351a0095333ebddf930d5a5045a60a (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
38
39
40
41
42
43
44
45
46
47
48
49
50
//! The file formats backing maps and other configs
//!
//! When creating maps to share with other clients, or to load into a
//! server, these types can be constructed with the YML description
//! format, outlined in [load_map](config::io::load_map)

mod io;
pub use io::*;

use crate::data::{LinkId, NodeId};
use serde::{Deserialize, Serialize};

/// A config tree that describes a map
#[derive(Serialize, Deserialize)]
pub struct MapCfg {
    /// The set of nodes
    pub nodes: Vec<NodeCfg>,
    /// Links connecting nodes
    pub links: Vec<LinkCfg>,
    /// Default spawn points (player count)
    pub spawns: Vec<SpawnCfg>,
}

/// A single node on a map, with an x and y coordinate
#[derive(Serialize, Deserialize)]
pub struct NodeCfg {
    /// Node ID
    pub id: NodeId,
    /// Render/world position
    pub x: f64,
    pub y: f64,
}

/// A link between two nodes
#[derive(Serialize, Deserialize)]
pub struct LinkCfg {
    /// The link ID
    id: LinkId,
    /// List of connectioned nodes
    con: (NodeId, NodeId),
}

/// Special configuration for a node to act as a player spawn point
#[derive(Serialize, Deserialize)]
pub struct SpawnCfg {
    /// The node of the spawn point
    pub n_id: NodeId,
    /// At what number of players is this spawn available?
    pub max_players: usize,
}