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

Implement loading of cube data from JSON file

This commit is contained in:
NGnius (Graham)
2025-03-09 16:28:03 -04:00
parent 303f72f010
commit 9b87b25131
20 changed files with 9541 additions and 64 deletions

View File

@@ -2,7 +2,7 @@
use std::collections::HashMap;
use polariton::operation::Typed;
pub struct CubeInfo {
pub struct CubeInfo<C: Clone> {
pub cpu: u32,
pub health: u32,
pub health_boost: f32,
@@ -14,7 +14,7 @@ pub struct CubeInfo {
pub protonium: bool,
pub unlocked_by_league: bool,
pub league_unlock_index: i32,
pub stats: HashMap<String, Typed>,
pub stats: HashMap<String, Typed<C>>,
pub description: String,
pub size: ItemTier,
pub type_: ItemType,
@@ -24,8 +24,8 @@ pub struct CubeInfo {
pub ignore_in_weapon_list: bool,
}
impl CubeInfo {
pub fn as_transmissible(&self) -> Typed {
impl <C: Clone> CubeInfo<C> {
pub fn as_transmissible(&self) -> Typed<C> {
Typed::HashMap(vec![
(Typed::Str("cpuRating".into()), Typed::Int(self.cpu as i32)),
(Typed::Str("health".into()), Typed::Int(self.health as i32)),
@@ -39,7 +39,7 @@ impl CubeInfo {
(Typed::Str("UnlockedByLeague".into()), Typed::Bool(self.unlocked_by_league.into())),
(Typed::Str("LeagueUnlockIndex".into()), Typed::Int(self.league_unlock_index)),
(Typed::Str("DisplayStats".into()), {
let items: Vec<(Typed, Typed)> = self.stats.iter().map(|(key, val)| (Typed::Str(key.into()), val.to_owned())).collect();
let items: Vec<(Typed<C>, Typed<C>)> = self.stats.iter().map(|(key, val)| (Typed::<C>::Str(key.into()), val.to_owned())).collect();
Typed::HashMap(items.into())
}),
(Typed::Str("Description".into()), Typed::Str(self.description.clone().into())),
@@ -52,7 +52,7 @@ impl CubeInfo {
].into())
}
pub fn as_transmissible_key_val(&self, cube_id: u32) -> (Typed, Typed) {
pub fn as_transmissible_key_val(&self, cube_id: u32) -> (Typed<C>, Typed<C>) {
(Typed::Str(hex::encode(cube_id.to_be_bytes()).into()), self.as_transmissible())
}
}

View File

@@ -19,7 +19,7 @@ pub struct MovementCategoryData {
}
impl MovementCategoryData {
pub fn as_transmissible(&self) -> Typed {
pub fn as_transmissible<C>(&self) -> Typed<C> {
let mut out = Vec::new();
self.horizontal_top_speed.map(|x| out.push((Typed::Str("horizontalTopSpeed".into()), Typed::Float(x))));
self.vertical_top_speed.map(|x| out.push((Typed::Str("verticalTopSpeed".into()), Typed::Float(x))));
@@ -57,7 +57,7 @@ pub enum MovementCategorySpecificData {
}
impl MovementCategorySpecificData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
match self {
Self::Wheel => Vec::default(),
Self::Hover(x) => x.as_transmissible(),
@@ -86,7 +86,7 @@ pub struct HoverCategoryData {
}
impl HoverCategoryData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("heightTolerance".into()), Typed::Float(self.height_tolerance)),
(Typed::Str("forceYOffset".into()), Typed::Float(self.force_y_offset)),
@@ -105,7 +105,7 @@ pub struct MechLegCategoryData {
}
impl MechLegCategoryData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("decelerationMultiplier".into()), Typed::Float(self.deceleration_multiplier)),
]
@@ -118,7 +118,7 @@ pub struct RotorCategoryData {
impl RotorCategoryData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("maxTurnRate".into()), Typed::Float(self.max_turn_rate)),
]
@@ -134,7 +134,7 @@ pub struct MovementData {
}
impl MovementData {
pub fn as_transmissible(&self) -> Typed {
pub fn as_transmissible<C>(&self) -> Typed<C> {
let mut out = Vec::new();
self.speed_boost.map(|x| out.push((Typed::Str("speedBoost".into()), Typed::Float(x))));
self.max_carry_mass.map(|x| out.push((Typed::Str("maxCarryMass".into()), Typed::Float(x))));
@@ -164,7 +164,7 @@ pub enum MovementSpecificData {
}
impl MovementSpecificData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
match self {
Self::Wheel(x) => x.as_transmissible(),
Self::Hover(x) => x.as_transmissible(),
@@ -195,7 +195,7 @@ pub struct WheelData {
}
impl WheelData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("steeringSpeedLight".into()), Typed::Float(self.steering_speed_light)),
(Typed::Str("steeringSpeedHeavy".into()), Typed::Float(self.steering_speed_heavy)),
@@ -227,7 +227,7 @@ pub struct HoverData {
}
impl HoverData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("maxHoverHeightLight".into()), Typed::Float(self.max_hover_height_light)),
(Typed::Str("maxHoverHeightHeavy".into()), Typed::Float(self.max_hover_height_heaver)),
@@ -261,7 +261,7 @@ pub struct AerofoilData {
}
impl AerofoilData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("barrelSpeedLight".into()), Typed::Float(self.barrel_speed_light)),
(Typed::Str("barrelSpeedHeavy".into()), Typed::Float(self.barrel_speed_heavy)),
@@ -285,7 +285,7 @@ pub struct ThrusterData {
}
impl ThrusterData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("accelerationDelayLight".into()), Typed::Float(self.acceleration_delay_light)),
(Typed::Str("accelerationDelayHeavy".into()), Typed::Float(self.acceleration_delay_heavy)),
@@ -323,7 +323,7 @@ pub struct InsectLegData {
}
impl InsectLegData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("idealHeightLight".into()), Typed::Float(self.ideal_height_light)),
(Typed::Str("idealHeightHeavy".into()), Typed::Float(self.ideal_height_heavy)),
@@ -373,7 +373,7 @@ pub struct MechLegData {
}
impl MechLegData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("timeGroundedAfterJumpLight".into()), Typed::Float(self.time_grounded_after_jump_light)),
(Typed::Str("timeGroundedAfterJumpHeavy".into()), Typed::Float(self.time_grounded_after_jump_heavy)),
@@ -405,7 +405,7 @@ pub struct TankTrackData {
}
impl TankTrackData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("maxTurnRateMovingLight".into()), Typed::Float(self.max_turn_rate_moving_light)),
(Typed::Str("maxTurnRateMovingHeavy".into()), Typed::Float(self.max_turn_rate_moving_heavy)),
@@ -434,7 +434,7 @@ pub struct RotorData {
impl RotorData {
pub fn as_transmissible(&self) -> Vec<(Typed, Typed)> {
pub fn as_transmissible<C>(&self) -> Vec<(Typed<C>, Typed<C>)> {
vec![
(Typed::Str("heightAccelerationLight".into()), Typed::Float(self.height_acceleration_light)),
(Typed::Str("heightAccelerationHeavy".into()), Typed::Float(self.height_acceleration_heavy)),

View File

@@ -68,7 +68,7 @@ pub struct WeaponData {
}
impl WeaponData {
pub fn as_transmissible(&self) -> Typed {
pub fn as_transmissible<C>(&self) -> Typed<C> {
let mut out = Vec::new();
self.damage_inflicted.map(|x| out.push((Typed::Str("damageInflicted".into()), Typed::Int(x))));
@@ -114,7 +114,7 @@ impl WeaponData {
self.spin_initial_cooldown.map(|x| out.push((Typed::Str("spinInitialCooldown".into()), Typed::Float(x))));
if !self.group_fire_scales.is_empty() {
let typed_arr: Vec<Typed> = self.group_fire_scales.iter().map(|x| Typed::Float(*x)).collect();
let typed_arr: Vec<Typed<C>> = self.group_fire_scales.iter().map(|x| Typed::Float(*x)).collect();
out.push((Typed::Str("groupFireScales".into()), Typed::ObjArr(typed_arr.into())));
}
@@ -156,7 +156,7 @@ pub enum ItemCategory {
Ski = 8,
TankTrack = 9,
Rotor = 10,
SrpinterLeg = 11,
SprinterLeg = 11,
Propeller = 12,
Laser = 100,
Plasma = 200,
@@ -190,7 +190,7 @@ impl ItemCategory {
ItemCategory::Ski => "Ski",
ItemCategory::TankTrack => "TankTrack",
ItemCategory::Rotor => "Rotor",
ItemCategory::SrpinterLeg => "SrpinterLeg",
ItemCategory::SprinterLeg => "SprinterLeg",
ItemCategory::Propeller => "Propeller",
ItemCategory::Laser => "Laser",
ItemCategory::Plasma => "Plasma",