48 lines
1.0 KiB
Rust

use std::collections::HashMap;
use crate::{
handles::GameShipHandle,
ship::Ship,
ship::{OutfitSet, ShipPersonality},
};
use content::ShipHandle;
use galactica_content as content;
/// Keeps track of all objects in the galaxy.
/// This struct does NO physics, it keeps track of data exclusively.
pub struct GameData {
// Universal counter.
// Used to create unique handles for game objects.
index: u64,
ships: HashMap<GameShipHandle, Ship>,
}
impl GameData {
pub fn new() -> Self {
Self {
index: 0,
ships: HashMap::new(),
}
}
/// Spawn a ship
pub fn create_ship(
&mut self,
ct: &content::Content,
ship: ShipHandle,
faction: content::FactionHandle,
personality: ShipPersonality,
outfits: OutfitSet,
) -> GameShipHandle {
let handle = GameShipHandle { index: self.index };
self.index += 1;
self.ships
.insert(handle, Ship::new(ct, ship, faction, personality, outfits));
return handle;
}
pub fn get_ship(&self, handle: GameShipHandle) -> Option<&Ship> {
self.ships.get(&handle)
}
}