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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! The rust side of the `dist/project-constants.json` file
//! 
//! ## Overview
//! 
//! This file contains a structure defining all data we want to load from the project constants file.
//! Feel free to add anything you'd like here, just make sure the relavant data is also written in the JSON file so the game doesn't crash.
//! You can treat these as constants. I just prefer storing this kind of data in JSON rather than hard-coding it in the program.
//! 
//! ## How this is loaded
//! 
//! Somewhere in `lib.rs`, a call is made to load this through the `asset_manager`. 
//! Its all already set up, so you shouldn't have to worry about the logistics.

use std::collections::HashMap;

use serde::Deserialize;

/// Constants relating to Discord
#[derive(Debug, Deserialize)]
pub struct DiscordConstants {
    /// The Discord application ID
    pub app_id: i64,

    /// Artwork name mapping
    pub artwork: HashMap<String, String>,
    
    /// Strings
    pub strings: HashMap<String, String>,
}

/// Constants relating to the Player
#[derive(Debug, Deserialize)]
pub struct PlayerConstants {

    /// Maximum velocity, tiles per second
    pub max_velocity: u32,

    /// Acceleration, tiles per second per second
    pub acceleration: u32,

    /// Deceleration, tiles per second per second
    pub deceleration: u32,

    /// Starting size of player in tiles
    pub start_size: f32,
}

/// This structure is filled with the contents of `dist/project-constants.json` at runtime
#[derive(Debug, Deserialize)]
pub struct ProjectConstants {
    /// The name of the game
    pub game_name: String,

    /// The window size to use on launch
    pub base_window_size: (u32, u32),

    /// The Discord constants
    pub discord: DiscordConstants,

    /// The Player constants
    pub player: PlayerConstants,

    /// The target framerate of the game
    pub target_fps: u32,

    /// The size of the game tiles
    pub tile_size: u32,
}