1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add upgrade and dismantle vehicle slot functionality for #14

This commit is contained in:
NG (Graham)
2025-05-11 12:09:23 -04:00
parent 221a5d5ca9
commit b04a8902e2
11 changed files with 222 additions and 22 deletions

View File

@@ -261,4 +261,13 @@ impl <C: Clone> super::ConfigProvider<C> for CubeConfig {
database: self.settings.server.database.clone(),
}
}
fn garage_upgrades(&self) -> super::GarageUpgrades {
super::GarageUpgrades {
increments: self.settings.garage_upgrades.iter().map(|inc| super::GarageUpgradeIncrement {
cpu: inc.cpu,
cost: inc.cost,
}).collect(),
}
}
}

View File

@@ -2,7 +2,7 @@ mod cubes_json;
pub use cubes_json::CubeConfig;
mod traits;
pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig};
pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement};
pub type ConfigImpl = CubeConfig;

View File

@@ -19,6 +19,7 @@ pub trait ConfigProvider<C: Clone> {
fn login_messages(&self) -> DevMessageProvider<C>;
fn public_channels(&self) -> Typed<C>;
fn server_config(&self) -> ServerConfig;
fn garage_upgrades(&self) -> GarageUpgrades;
}
pub struct CompleteCampaignProvider {
@@ -88,3 +89,27 @@ pub struct TypedDevMessage<C> {
pub struct ServerConfig {
pub database: String,
}
#[derive(Clone, Debug)]
pub struct GarageUpgrades {
pub increments: Vec<GarageUpgradeIncrement>,
}
#[derive(Clone, Debug)]
pub struct GarageUpgradeIncrement {
pub cpu: u32,
pub cost: u32,
}
impl GarageUpgrades {
pub fn slot_upgrades<C>(&self) -> Typed<C> {
Typed::HashMap(vec![
(Typed::Str("cpuIncreaseCost".into()), Typed::Dict(polariton::operation::Dict {
key_ty: polariton::serdes::TypePrefix::Int, // int
val_ty: polariton::serdes::TypePrefix::Int, // int
// (CPU limit, upgrade cost)
items: self.increments.iter().map(|inc| (Typed::Int(inc.cpu as _), Typed::Int(inc.cost as _))).collect(),
}))
].into())
}
}