From 1403a6e3d083acf63cd90620f32bfeee5367cec9 Mon Sep 17 00:00:00 2001 From: "NG (Graham)" Date: Sun, 17 Aug 2025 15:03:30 -0400 Subject: [PATCH] Make power bar configurable --- rc_core/src/persist/combat.rs | 15 +++++++++++++++ rc_core/src/persist/config/cubes_json.rs | 7 +++++++ rc_core/src/persist/config/mod.rs | 2 +- rc_core/src/persist/config/traits.rs | 7 +++++++ rc_services_room/src/operations/mod.rs | 2 +- .../src/operations/power_bar_stats.rs | 15 ++++++++------- 6 files changed, 39 insertions(+), 9 deletions(-) diff --git a/rc_core/src/persist/combat.rs b/rc_core/src/persist/combat.rs index 82c100f..30d38d2 100644 --- a/rc_core/src/persist/combat.rs +++ b/rc_core/src/persist/combat.rs @@ -16,6 +16,8 @@ pub struct BattleConfig { pub multiplayer: super::MultiplayerConfig, #[serde(default = "default_maps")] pub maps: super::MapsConfig, + #[serde(default = "default_energy")] + pub energy: EnergyConfig, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -234,6 +236,12 @@ impl GameType { } } +#[derive(Serialize, Deserialize, Clone, Debug, Copy)] +pub struct EnergyConfig { + pub refill_rate_per_s: f32, + pub total: u32, +} + fn default_game_modes() -> GameModes { GameModes { battle_arena: GameMode { @@ -498,3 +506,10 @@ fn default_maps() -> super::MapsConfig { map: super::maps::default_map(), } } + +fn default_energy() -> EnergyConfig { + EnergyConfig { + refill_rate_per_s: 0.1, // should take 10s to refill + total: 12_550, + } +} diff --git a/rc_core/src/persist/config/cubes_json.rs b/rc_core/src/persist/config/cubes_json.rs index a0f5e54..ba37c35 100644 --- a/rc_core/src/persist/config/cubes_json.rs +++ b/rc_core/src/persist/config/cubes_json.rs @@ -434,4 +434,11 @@ impl super::ConfigProvider for CubeConfig { implementation: player.implementation.clone().to_config(), }).collect() } + + fn energy(&self) -> super::EnergyConfig { + super::EnergyConfig { + refill_rate: self.battle.energy.refill_rate_per_s, + total: self.battle.energy.total, + } + } } diff --git a/rc_core/src/persist/config/mod.rs b/rc_core/src/persist/config/mod.rs index a596a4a..ce8f37d 100644 --- a/rc_core/src/persist/config/mod.rs +++ b/rc_core/src/persist/config/mod.rs @@ -2,7 +2,7 @@ mod cubes_json; pub use cubes_json::CubeConfig; mod traits; -pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator}; +pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig}; pub type ConfigImpl = CubeConfig; diff --git a/rc_core/src/persist/config/traits.rs b/rc_core/src/persist/config/traits.rs index 76b55f3..6ba9fe3 100644 --- a/rc_core/src/persist/config/traits.rs +++ b/rc_core/src/persist/config/traits.rs @@ -34,6 +34,7 @@ pub trait ConfigProvider { fn maps(&self) -> std::collections::HashMap; fn url_links(&self) -> LinksConfig; fn fake_players(&self) -> Vec; + fn energy(&self) -> EnergyConfig; } pub struct CompleteCampaignProvider { @@ -379,3 +380,9 @@ pub struct FakePlayer { pub enum ClientEmulator { Experiment, } + +#[derive(Clone, Debug)] +pub struct EnergyConfig { + pub refill_rate: f32, + pub total: u32, +} diff --git a/rc_services_room/src/operations/mod.rs b/rc_services_room/src/operations/mod.rs index c67981d..76639ba 100644 --- a/rc_services_room/src/operations/mod.rs +++ b/rc_services_room/src/operations/mod.rs @@ -123,7 +123,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler .add(crf_config::crf_config_provider()) .add(weapon_stats::weapon_config_provider(&init_ctx.cubes)) .add(movement_stats::movement_config_provider(&init_ctx.cubes)) - .add(power_bar_stats::power_bar_provider()) + .add(power_bar_stats::power_bar_provider(&init_ctx.cubes)) .add(damage_boost_stats::damage_boost_provider()) .add(battle_arena_config::battle_arena_config_provider()) .add(cpu_limits_config::cpu_config_provider()) diff --git a/rc_services_room/src/operations/power_bar_stats.rs b/rc_services_room/src/operations/power_bar_stats.rs index 21519a0..72e7b85 100644 --- a/rc_services_room/src/operations/power_bar_stats.rs +++ b/rc_services_room/src/operations/power_bar_stats.rs @@ -1,16 +1,17 @@ -use polariton_server::operations::SimpleFunc; +use polariton_server::operations::Immediate; use polariton::operation::{ParameterTable, Typed}; const PARAM_KEY: u8 = 61; -pub(super) fn power_bar_provider() -> SimpleFunc<51, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { - SimpleFunc::new(|params, _| { - let mut params = params.to_dict(); +pub(super) fn power_bar_provider(conf: &oj_rc_core::ConfigImpl) -> Immediate<51, crate::UserTy> { + let energy_conf = >::energy(conf); + Immediate::new(|| { + let mut params = ParameterTable::with_capacity(2); params.insert(PARAM_KEY, Typed::HashMap(vec![ - (Typed::Str("refillRatePerSecond".into()), Typed::Float(0.10)), // should take 10s to refill - (Typed::Str("powerForAllRobots".into()), Typed::Int(12_550 /* converted to u32 */)), + (Typed::Str("refillRatePerSecond".into()), Typed::Float(energy_conf.refill_rate)), + (Typed::Str("powerForAllRobots".into()), Typed::Int(energy_conf.total as _)), ].into() )); - Ok(params.into()) + params }) }