diff --git a/crates/content/src/lib.rs b/crates/content/src/lib.rs index c2bb64e..81de53a 100644 --- a/crates/content/src/lib.rs +++ b/crates/content/src/lib.rs @@ -113,6 +113,8 @@ pub struct Content { /// Textures pub textures: Vec, + /// Map strings to texture names. + /// This is only necessary because we need to hard-code a few texture names for UI elements. texture_index: HashMap, /// The texture to use for starfield stars starfield_handle: Option, @@ -127,7 +129,7 @@ pub struct Content { ships: Vec, /// Star systems - pub systems: Vec, + systems: Vec, /// Factions factions: Vec, diff --git a/crates/gameobject/src/lib.rs b/crates/gameobject/src/lib.rs index 9f8984c..17a5192 100644 --- a/crates/gameobject/src/lib.rs +++ b/crates/gameobject/src/lib.rs @@ -7,7 +7,11 @@ mod outfits; mod projectile; mod ship; +mod system; +mod systemobject; pub use outfits::{OutfitSet, OutfitStatSum, ShipGun}; pub use projectile::Projectile; pub use ship::Ship; +pub use system::System; +pub use systemobject::SystemObject; diff --git a/src/game/system.rs b/crates/gameobject/src/system.rs similarity index 66% rename from src/game/system.rs rename to crates/gameobject/src/system.rs index 2f6f12e..7484289 100644 --- a/src/game/system.rs +++ b/crates/gameobject/src/system.rs @@ -1,5 +1,5 @@ -use super::SystemObject; -use crate::content; +use crate::SystemObject; +use galactica_content as content; use galactica_render::ObjectSprite; pub struct System { @@ -8,13 +8,14 @@ pub struct System { } impl System { - pub fn new(ct: &content::System) -> Self { + pub fn new(ct: &content::Content, handle: content::SystemHandle) -> Self { + let sys = ct.get_system(handle); let mut s = System { - name: ct.name.clone(), + name: sys.name.clone(), bodies: Vec::new(), }; - for o in &ct.objects { + for o in &sys.objects { s.bodies.push(SystemObject { pos: o.position, sprite_texture: o.sprite_texture, diff --git a/src/game/systemobject.rs b/crates/gameobject/src/systemobject.rs similarity index 92% rename from src/game/systemobject.rs rename to crates/gameobject/src/systemobject.rs index 626eb6c..bc12a6c 100644 --- a/src/game/systemobject.rs +++ b/crates/gameobject/src/systemobject.rs @@ -1,6 +1,6 @@ use cgmath::{Deg, Point3}; -use crate::content; +use galactica_content as content; use galactica_render::ObjectSprite; pub struct SystemObject { diff --git a/src/game/game.rs b/src/game/game.rs index 687e783..e7dd03f 100644 --- a/src/game/game.rs +++ b/src/game/game.rs @@ -1,8 +1,9 @@ use cgmath::{Deg, InnerSpace, Point2}; +use content::SystemHandle; use std::time::Instant; use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode}; -use super::{camera::Camera, system::System}; +use super::camera::Camera; use crate::{content, inputstatus::InputStatus}; use galactica_constants; use galactica_gameobject as object; @@ -70,7 +71,7 @@ pub struct Game { pub input: InputStatus, pub last_update: Instant, pub player: ShipPhysicsHandle, - pub system: System, + pub system: object::System, pub camera: Camera, paused: bool, pub time_scale: f32, @@ -142,7 +143,7 @@ impl Game { pos: (0.0, 0.0).into(), zoom: 500.0, }, - system: System::new(&ct.systems[0]), + system: object::System::new(&ct, SystemHandle { index: 0 }), paused: false, time_scale: 1.0, diff --git a/src/game/mod.rs b/src/game/mod.rs index ab544ad..b1e95b2 100644 --- a/src/game/mod.rs +++ b/src/game/mod.rs @@ -1,9 +1,6 @@ -//! This module contains high-level game control logic. +//! This module is responsible for high-level game control logic. mod camera; mod game; -mod system; -mod systemobject; pub use game::Game; -pub use systemobject::SystemObject;