2023-10-31 17:23:15 +01:00
|
|
|
use serde::{Serialize, Deserialize};
|
|
|
|
|
|
2024-01-08 00:22:24 +01:00
|
|
|
use crate::{structs::Vec3, enums::PlayerType};
|
|
|
|
|
|
2023-10-31 17:23:15 +01:00
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct PlayerData {
|
|
|
|
|
pos: Vec3,
|
|
|
|
|
yaw: f32,
|
|
|
|
|
#[serde(rename = "playerType")]
|
|
|
|
|
player_type: PlayerType,
|
|
|
|
|
|
|
|
|
|
#[serde(rename = "hasBomb")]
|
|
|
|
|
has_bomb: bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PlayerData {
|
|
|
|
|
pub fn new(pos: Vec3, yaw: f32, player_type: PlayerType, has_bomb: bool) -> PlayerData {
|
|
|
|
|
PlayerData { pos, yaw, player_type, has_bomb }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct BombData {
|
|
|
|
|
pos: Vec3,
|
|
|
|
|
#[serde(rename = "isPlanted")]
|
|
|
|
|
is_planted: bool
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-28 00:59:45 +01:00
|
|
|
#[allow(dead_code)]
|
2023-10-31 17:23:15 +01:00
|
|
|
impl BombData {
|
|
|
|
|
pub fn new(pos: Vec3, is_planted: bool) -> BombData {
|
|
|
|
|
BombData { pos, is_planted }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub enum EntityData {
|
|
|
|
|
Player(PlayerData),
|
|
|
|
|
Bomb(BombData)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct RadarData {
|
2024-01-08 00:22:24 +01:00
|
|
|
freq: usize,
|
2023-10-31 17:23:15 +01:00
|
|
|
ingame: bool,
|
|
|
|
|
|
|
|
|
|
#[serde(rename = "mapName")]
|
|
|
|
|
map_name: String,
|
|
|
|
|
|
|
|
|
|
#[serde(rename(serialize = "entityData"))]
|
|
|
|
|
player_data: Vec<EntityData>,
|
|
|
|
|
|
2023-11-28 00:59:45 +01:00
|
|
|
//#[serde(rename(serialize = "localYaw"))]
|
|
|
|
|
//local_yaw: f32,
|
2023-10-31 17:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RadarData {
|
2024-01-08 00:22:24 +01:00
|
|
|
pub fn new(ingame: bool, map_name: String, player_data: Vec<EntityData>, freq: usize) -> RadarData {
|
|
|
|
|
RadarData { ingame, map_name, player_data, freq }
|
2023-10-31 17:23:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns empty RadarData, it's also the same data that gets sent to clients when not ingame
|
2024-01-08 00:22:24 +01:00
|
|
|
pub fn empty(freq: usize) -> RadarData {
|
2023-10-31 17:23:15 +01:00
|
|
|
RadarData {
|
|
|
|
|
ingame: false,
|
|
|
|
|
map_name: String::new(),
|
|
|
|
|
player_data: Vec::new(),
|
2024-01-08 00:22:24 +01:00
|
|
|
freq
|
2023-10-31 17:23:15 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-01-08 00:22:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe impl Send for RadarData {}
|
|
|
|
|
|
|
|
|
|
pub type ArcRwlockRadarData = std::sync::Arc<tokio::sync::RwLock<RadarData>>;
|