// StarKingdoms.IO, a browser game about drifting through space
// Copyright (C) 2024 ghostly_zsh, TerraMaster85, core
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see .
use crate::module::component::PartType;
use crate::planet::PlanetType;
use bevy::ecs::system::Resource;
use bevy_rapier2d::rapier::dynamics::IntegrationParameters;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::IpAddr;
#[derive(Resource, Serialize, Deserialize, Debug, Clone)]
pub struct StkConfig {
pub security: SecurityConfig,
pub server: ServerConfig,
pub world: WorldConfig,
pub physics: PhysicsConfig,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SecurityConfig {
pub app_key: String,
pub required_permission_level: i32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ServerConfig {
pub tick_time_ms: u64,
pub world_fixed_timestep: f64,
pub bind: BindConfig,
pub max_free_parts: usize,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BindConfig {
pub ip: IpAddr,
pub port: u16,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct WorldConfig {
pub gravity: f32,
pub pixels_per_meter: f32,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PhysicsConfig {
pub parameters: IntegrationParameters,
pub solver: PhysicsSolver,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub enum PhysicsSolver {
SmallstepPGS,
OldPGS,
}
#[derive(Resource, Serialize, Deserialize, Debug, Clone)]
pub struct PlanetsConfig {
pub planets: HashMap,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PlanetConfig {
pub size: f32,
pub mass: f32,
}
#[derive(Resource, Deserialize, Debug, Clone)]
pub struct PartsConfig {
pub parts: HashMap,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PartConfig {
pub mass: f32,
pub energy_capacity: u32,
pub thruster_force: f32,
pub thruster_energy: u32,
}
#[macro_export]
macro_rules! mass {
($p:expr) => {
match $crate::parts_config().parts.get(&$p) {
Some(v) => v.mass,
None => 1.0,
}
};
}
#[macro_export]
macro_rules! capacity {
($p:expr) => {
match $crate::parts_config().parts.get(&$p) {
Some(v) => v.energy_capacity,
None => 0,
}
};
}
#[macro_export]
macro_rules! planet {
($t:expr) => {
$crate::planets_config().planets.get(&$t).unwrap()
};
}
#[macro_export]
macro_rules! part {
($t:expr) => {
$crate::parts_config().parts.get(&$t).unwrap()
};
}