80 lines
2.1 KiB
Rust
80 lines
2.1 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 {
|
|
pub(crate) index: usize,
|
|
|
|
/// The aspect ratio of this sprite (width / height)
|
|
pub aspect: f32,
|
|
}
|
|
|
|
impl SpriteHandle {
|
|
/// The index of this sprite in content's sprite array.
|
|
/// Render uses this to build its buffers.
|
|
pub fn get_index(&self) -> u32 {
|
|
self.index as u32
|
|
}
|
|
}
|
|
|
|
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 in crate, currently for debug (same with all other handles)
|
|
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 {
|
|
/// TODO
|
|
pub index: usize,
|
|
}
|
|
|
|
/// A lightweight representation of an effect
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
|
pub struct EffectHandle {
|
|
pub(crate) index: usize,
|
|
}
|