72 lines
1.9 KiB
Rust
72 lines
1.9 KiB
Rust
//! This module defines lightweight handles for every content type.
|
|
//! This isn't strictly necessary (we could refer to them using their string keys),
|
|
//! but this approach doesn't require frequent string cloning, and
|
|
//! gives each content type a distinct Rust type.
|
|
//!
|
|
//! We could also use raw references to content types, but that creates a mess of lifetimes
|
|
//! in our code. It's managable, but the approach here is simpler and easier to understand.
|
|
use std::{cmp::Eq, hash::Hash};
|
|
|
|
/// A lightweight representation of a sprite
|
|
#[derive(Debug, Clone, Copy)]
|
|
pub struct SpriteHandle {
|
|
/// The index of this sprite in content.sprites
|
|
/// This must be public, since render uses this to
|
|
/// select sprites.
|
|
///
|
|
/// This is a u32 for that same reason, too.
|
|
pub index: u32,
|
|
|
|
/// The aspect ratio of this sprite (width / height)
|
|
pub aspect: f32,
|
|
}
|
|
|
|
impl Hash for SpriteHandle {
|
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
|
self.index.hash(state)
|
|
}
|
|
}
|
|
|
|
impl Eq for SpriteHandle {}
|
|
impl PartialEq for SpriteHandle {
|
|
fn eq(&self, other: &Self) -> bool {
|
|
self.index.eq(&other.index)
|
|
}
|
|
}
|
|
|
|
/// A lightweight representation of an outfit
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct OutfitHandle {
|
|
/// TODO
|
|
pub index: usize,
|
|
}
|
|
|
|
/// A lightweight representation of a gun
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct GunHandle {
|
|
/// TODO
|
|
pub index: usize,
|
|
}
|
|
|
|
/// A lightweight representation of a ship
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct ShipHandle {
|
|
/// TODO
|
|
pub index: usize,
|
|
}
|
|
|
|
/// A lightweight representation of a star system
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct SystemHandle {
|
|
/// TODO
|
|
pub index: usize,
|
|
}
|
|
|
|
/// A lightweight representation of a faction
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct FactionHandle {
|
|
/// The index of this faction in content.factions
|
|
/// TODO: pub in crate, currently for debug (same with all other handles)
|
|
pub index: usize,
|
|
}
|