2024-01-08 22:38:36 -08:00
|
|
|
use std::ops::{Add, AddAssign, Sub, SubAssign};
|
|
|
|
|
2023-12-30 21:05:06 -08:00
|
|
|
pub(crate) mod syntax {
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct OutfitSpace {
|
|
|
|
pub outfit: Option<u32>,
|
|
|
|
pub weapon: Option<u32>,
|
|
|
|
pub engine: Option<u32>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 22:38:36 -08:00
|
|
|
// TODO: user-defined space values
|
|
|
|
|
2023-12-30 21:05:06 -08:00
|
|
|
/// Represents outfit space, either that available in a ship
|
|
|
|
/// or that used by an outfit.
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub struct OutfitSpace {
|
|
|
|
/// Total available outfit space.
|
|
|
|
/// This should be greater than weapon and engine.
|
|
|
|
pub outfit: u32,
|
|
|
|
|
|
|
|
/// Space for weapons
|
|
|
|
pub weapon: u32,
|
|
|
|
|
|
|
|
/// Space for engine
|
|
|
|
pub engine: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl OutfitSpace {
|
2024-01-08 22:38:36 -08:00
|
|
|
/// Make a new, zeroed OutfitSpace
|
2023-12-30 21:05:06 -08:00
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
outfit: 0,
|
|
|
|
weapon: 0,
|
|
|
|
engine: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 22:38:36 -08:00
|
|
|
/// Can this outfit contain `smaller`?
|
2024-01-01 15:41:47 -08:00
|
|
|
pub fn can_contain(&self, smaller: &Self) -> bool {
|
2024-01-08 22:38:36 -08:00
|
|
|
self.outfit >= smaller.outfit
|
2023-12-30 21:05:06 -08:00
|
|
|
&& self.weapon >= smaller.weapon
|
|
|
|
&& self.engine >= smaller.engine
|
|
|
|
}
|
2024-01-08 22:38:36 -08:00
|
|
|
}
|
2023-12-30 21:05:06 -08:00
|
|
|
|
2024-01-08 22:38:36 -08:00
|
|
|
impl Sub for OutfitSpace {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn sub(self, rhs: Self) -> Self::Output {
|
|
|
|
OutfitSpace {
|
|
|
|
outfit: self.outfit - rhs.outfit,
|
|
|
|
weapon: self.weapon - rhs.weapon,
|
|
|
|
engine: self.engine - rhs.engine,
|
|
|
|
}
|
2023-12-30 21:05:06 -08:00
|
|
|
}
|
2024-01-08 22:38:36 -08:00
|
|
|
}
|
2023-12-30 21:05:06 -08:00
|
|
|
|
2024-01-08 22:38:36 -08:00
|
|
|
impl SubAssign for OutfitSpace {
|
|
|
|
fn sub_assign(&mut self, rhs: Self) {
|
|
|
|
self.outfit -= rhs.outfit;
|
2023-12-30 21:05:06 -08:00
|
|
|
self.weapon -= rhs.weapon;
|
|
|
|
self.engine -= rhs.engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-08 22:38:36 -08:00
|
|
|
impl Add for OutfitSpace {
|
|
|
|
type Output = Self;
|
|
|
|
|
|
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
|
|
OutfitSpace {
|
|
|
|
outfit: self.outfit + rhs.outfit,
|
|
|
|
weapon: self.weapon + rhs.weapon,
|
|
|
|
engine: self.engine + rhs.engine,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl AddAssign for OutfitSpace {
|
|
|
|
fn add_assign(&mut self, rhs: Self) {
|
|
|
|
self.outfit += rhs.outfit;
|
|
|
|
self.weapon += rhs.weapon;
|
|
|
|
self.engine += rhs.engine;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-30 21:05:06 -08:00
|
|
|
impl From<syntax::OutfitSpace> for OutfitSpace {
|
|
|
|
fn from(value: syntax::OutfitSpace) -> Self {
|
|
|
|
Self {
|
|
|
|
outfit: value.outfit.unwrap_or(0),
|
|
|
|
engine: value.engine.unwrap_or(0),
|
|
|
|
weapon: value.weapon.unwrap_or(0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|