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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! Core game metadata

use serde::Deserializer;
use std::time::Duration;

use crate::prelude::*;

mod map;
mod player;

pub use map::*;
pub use player::*;

/// Extension trait for the bones [`AssetServer`].
pub trait MatchAssetServerExt {
    /// Register the default assets from `bones_framework`.
    fn register_match_assets(self) -> Self;
}
impl MatchAssetServerExt for &mut AssetServer {
    fn register_match_assets(self) -> Self {
        CoreMeta::register_schema();
        PlayerMeta::register_schema();
        ElementMeta::register_schema();
        BulletMeta::register_schema();
        MapMeta::register_schema();
        HatMeta::register_schema();

        self
    }
}

#[derive(Clone, Debug, HasSchema, Default)]
#[repr(C)]
pub struct CoreMeta {
    pub camera: CameraMeta,
    pub physics: PhysicsMeta,
    pub config: CoreConfigMeta,
    pub map_tilesets: SVec<Handle<Atlas>>,
    pub players: SVec<Handle<PlayerMeta>>,
    pub player_emotes: SMap<Ustr, Handle<EmoteMeta>>,
    pub player_hats: SVec<Handle<HatMeta>>,
    pub player_win_indicator: Handle<WinIndicatorMeta>,
    pub stable_maps: SVec<Handle<MapMeta>>,
    pub map_elements: SVec<Handle<ElementMeta>>,
    pub experimental_maps: SVec<Handle<MapMeta>>,
}

#[derive(HasSchema, Clone, Debug)]
#[repr(C)]
pub struct CameraMeta {
    pub default_height: f32,
    pub border_top: f32,
    pub border_bottom: f32,
    pub border_left: f32,
    pub border_right: f32,
    pub move_lerp_factor: f32,
    pub zoom_in_lerp_factor: f32,
    pub zoom_out_lerp_factor: f32,
    pub min_camera_size: Vec2,
    pub player_camera_box_size: Vec2,
}

impl Default for CameraMeta {
    fn default() -> Self {
        Self {
            default_height: 400.0,
            border_top: 0.0,
            border_bottom: 0.0,
            border_left: 0.0,
            border_right: 0.0,
            move_lerp_factor: 1.0,
            zoom_in_lerp_factor: 1.0,
            zoom_out_lerp_factor: 1.0,
            min_camera_size: Vec2::ZERO,
            player_camera_box_size: Vec2::ZERO,
        }
    }
}

#[derive(HasSchema, Clone, Debug, Default)]
#[repr(C)]
pub struct PhysicsMeta {
    pub gravity: f32,
    pub terminal_velocity: f32,
    pub friction_lerp: f32,
    pub stop_threshold: f32,
    pub player: PhysicsPlayerMeta,
}

#[derive(HasSchema, Clone, Debug, Default)]
#[repr(C)]
pub struct PhysicsPlayerMeta {
    pub ragdoll_initial_pop: f32,
    pub ragdoll_initial_ang_vel: f32,
    pub ragdoll_twitch_vel: f32,
    pub ragdoll_twitch_delay: f32,
    // Add additional mass to ragdoll body
    pub ragdoll_additional_mass: f32,
}

#[derive(HasSchema, Deserialize, Clone, Debug, Default)]
#[derive_type_data(SchemaDeserialize)]
pub struct CoreConfigMeta {
    #[serde(default)]
    #[serde(with = "humantime_serde")]
    pub respawn_invincibility_time: Duration,

    /// After one or fewer players left, how long to watch before scoring
    #[serde(default)]
    #[serde(with = "humantime_serde")]
    pub round_end_score_time: Duration,

    /// How long round lingers after displaying round winner
    #[serde(default)]
    #[serde(with = "humantime_serde")]
    pub round_end_post_score_linger_time: Duration,

    /// How many rounds must be won to end match
    pub winning_score_threshold: u32,

    /// How many rounds between intermissions
    pub rounds_between_intermission: u32,
}