use crate::comp::Pos;
use serde::{Deserialize, Serialize};
use specs::Entity;
use std::ops::{Mul, MulAssign};
use vek::Vec3;
#[derive(Copy, Clone, Debug, Serialize, Deserialize, Default)]
pub struct TimeOfDay(pub f64);
impl TimeOfDay {
pub fn new(t: f64) -> Self { TimeOfDay(t) }
fn get_angle_rad(self) -> f32 {
const TIME_FACTOR: f64 = (std::f64::consts::PI * 2.0) / (3600.0 * 24.0);
((self.0 * TIME_FACTOR) % (std::f64::consts::PI * 2.0)) as f32
}
pub fn get_sun_dir(self) -> Vec3<f32> {
let angle_rad = self.get_angle_rad();
Vec3::new(-angle_rad.sin(), 0.0, angle_rad.cos())
}
pub fn get_moon_dir(self) -> Vec3<f32> {
let angle_rad = self.get_angle_rad();
-Vec3::new(-angle_rad.sin(), 0.0, angle_rad.cos() - 0.5).normalized()
}
}
impl TimeOfDay {
pub fn day(&self) -> f64 { self.0.rem_euclid(24.0 * 3600.0) }
}
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct Time(pub f64);
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
pub struct ProgramTime(pub f64);
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct TimeScale(pub f64);
impl Default for TimeScale {
fn default() -> Self { Self(1.0) }
}
#[derive(Default)]
pub struct DeltaTime(pub f32);
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize, PartialEq)]
#[serde(transparent)]
pub struct Secs(pub f64);
impl Mul<f64> for Secs {
type Output = Self;
fn mul(self, mult: f64) -> Self { Self(self.0 * mult) }
}
impl MulAssign<f64> for Secs {
fn mul_assign(&mut self, mult: f64) { *self = *self * mult; }
}
#[derive(Default)]
pub struct EntitiesDiedLastTick(pub Vec<(Entity, Pos)>);
#[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum GameMode {
Server,
Client,
Singleplayer,
}
#[derive(Copy, Clone, Default, Debug)]
pub struct PlayerEntity(pub Option<Entity>);
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq)]
pub struct PlayerPhysicsSetting {
pub client_optin: bool,
}
impl PlayerPhysicsSetting {
pub fn server_authoritative(&self) -> bool { self.client_optin }
pub fn client_authoritative(&self) -> bool { !self.server_authoritative() }
}
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq, enum_map::Enum)]
pub enum MapKind {
Square,
Circle,
}
impl std::fmt::Display for MapKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
MapKind::Square => f.write_str("Square"),
MapKind::Circle => f.write_str("Circle"),
}
}
}
#[derive(Clone, Default, Debug)]
pub struct PlayerPhysicsSettings {
pub settings: hashbrown::HashMap<uuid::Uuid, PlayerPhysicsSetting>,
}
#[derive(PartialEq, Eq, Copy, Clone, Debug, Deserialize, Serialize)]
pub enum BattleMode {
PvP,
PvE,
}