Moved `shipbehavior` to crates
parent
bd8651b02a
commit
afa6bd6690
|
@ -584,6 +584,7 @@ dependencies = [
|
|||
"galactica-content",
|
||||
"galactica-physics",
|
||||
"galactica-render",
|
||||
"galactica-shipbehavior",
|
||||
"image",
|
||||
"nalgebra",
|
||||
"pollster",
|
||||
|
@ -615,19 +616,13 @@ dependencies = [
|
|||
name = "galactica-physics"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cgmath",
|
||||
"crossbeam",
|
||||
"galactica-content",
|
||||
"galactica-render",
|
||||
"image",
|
||||
"nalgebra",
|
||||
"pollster",
|
||||
"rand",
|
||||
"rapier2d",
|
||||
"walkdir",
|
||||
"wgpu",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -645,6 +640,15 @@ dependencies = [
|
|||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "galactica-shipbehavior"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"cgmath",
|
||||
"galactica-content",
|
||||
"galactica-physics",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.11"
|
||||
|
|
|
@ -33,6 +33,7 @@ members = [
|
|||
"crates/render",
|
||||
"crates/constants",
|
||||
"crates/physics",
|
||||
"crates/shipbehavior",
|
||||
]
|
||||
|
||||
|
||||
|
@ -42,6 +43,7 @@ galactica-content = { path = "crates/content" }
|
|||
galactica-render = { path = "crates/render" }
|
||||
galactica-constants = { path = "crates/constants" }
|
||||
galactica-physics = { path = "crates/physics" }
|
||||
galactica-shipbehavior = { path = "crates/shipbehavior" }
|
||||
|
||||
# Files
|
||||
image = { version = "0.24", features = ["png"] }
|
||||
|
|
|
@ -4,24 +4,11 @@ version = "0.0.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# Internal crates
|
||||
galactica-render = { path = "../render" }
|
||||
galactica-content = { path = "../content" }
|
||||
|
||||
|
||||
# Files
|
||||
image = { version = "0.24", features = ["png"] }
|
||||
# Graphics
|
||||
winit = "0.28"
|
||||
wgpu = "0.18"
|
||||
# Physics
|
||||
rapier2d = { version = "0.17.2" }
|
||||
nalgebra = "0.32.3"
|
||||
crossbeam = "0.8.3"
|
||||
# Misc helpers
|
||||
pollster = "0.3"
|
||||
anyhow = "1.0"
|
||||
# TODO: migrate to nalgebra
|
||||
cgmath = "0.18.0"
|
||||
rand = "0.8.5"
|
||||
walkdir = "2.4.0"
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
[package]
|
||||
name = "galactica-shipbehavior"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
galactica-content = { path = "../content" }
|
||||
galactica-physics = { path = "../physics" }
|
||||
cgmath = "0.18.0"
|
|
@ -0,0 +1,20 @@
|
|||
use crate::ShipBehavior;
|
||||
use galactica_content as content;
|
||||
use galactica_physics::{Physics, ShipHandle};
|
||||
|
||||
pub struct Dummy {
|
||||
_handle: ShipHandle,
|
||||
}
|
||||
|
||||
impl Dummy {
|
||||
pub fn new(handle: ShipHandle) -> Box<Self> {
|
||||
Box::new(Self { _handle: handle })
|
||||
}
|
||||
}
|
||||
|
||||
impl ShipBehavior for Dummy {
|
||||
fn update_controls(&mut self, _physics: &mut Physics, _content: &content::Content) {}
|
||||
fn get_handle(&self) -> ShipHandle {
|
||||
return self._handle;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
mod dummy;
|
||||
mod player;
|
||||
mod point;
|
||||
|
||||
pub use dummy::Dummy;
|
||||
pub use player::Player;
|
||||
pub use point::Point;
|
|
@ -0,0 +1,37 @@
|
|||
use crate::ShipBehavior;
|
||||
use galactica_content as content;
|
||||
use galactica_physics::{Physics, ShipHandle};
|
||||
|
||||
pub struct Player {
|
||||
handle: ShipHandle,
|
||||
key_left: bool,
|
||||
key_right: bool,
|
||||
key_guns: bool,
|
||||
key_thrust: bool,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(handle: ShipHandle) -> Box<Self> {
|
||||
Box::new(Self {
|
||||
handle,
|
||||
key_left: false,
|
||||
key_right: false,
|
||||
key_guns: false,
|
||||
key_thrust: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ShipBehavior for Player {
|
||||
fn update_controls(&mut self, physics: &mut Physics, _content: &content::Content) {
|
||||
let s = physics.get_ship_mut(&self.handle).unwrap();
|
||||
s.controls.left = self.key_left;
|
||||
s.controls.right = self.key_right;
|
||||
s.controls.guns = self.key_guns;
|
||||
s.controls.thrust = self.key_thrust;
|
||||
}
|
||||
|
||||
fn get_handle(&self) -> ShipHandle {
|
||||
return self.handle;
|
||||
}
|
||||
}
|
|
@ -1,67 +1,9 @@
|
|||
use cgmath::{Deg, InnerSpace};
|
||||
|
||||
use crate::content;
|
||||
use crate::ShipBehavior;
|
||||
use galactica_content as content;
|
||||
use galactica_physics::{util, Physics, ShipHandle};
|
||||
|
||||
pub trait ShipBehavior
|
||||
where
|
||||
Self: Send,
|
||||
{
|
||||
fn update_controls(&mut self, physics: &mut Physics, content: &content::Content);
|
||||
fn get_handle(&self) -> ShipHandle;
|
||||
}
|
||||
|
||||
pub struct Dummy {
|
||||
_handle: ShipHandle,
|
||||
}
|
||||
|
||||
impl Dummy {
|
||||
pub fn new(handle: ShipHandle) -> Box<Self> {
|
||||
Box::new(Self { _handle: handle })
|
||||
}
|
||||
}
|
||||
|
||||
impl ShipBehavior for Dummy {
|
||||
fn update_controls(&mut self, _physics: &mut Physics, _content: &content::Content) {}
|
||||
fn get_handle(&self) -> ShipHandle {
|
||||
return self._handle;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
handle: ShipHandle,
|
||||
key_left: bool,
|
||||
key_right: bool,
|
||||
key_guns: bool,
|
||||
key_thrust: bool,
|
||||
}
|
||||
|
||||
impl Player {
|
||||
pub fn new(handle: ShipHandle) -> Box<Self> {
|
||||
Box::new(Self {
|
||||
handle,
|
||||
key_left: false,
|
||||
key_right: false,
|
||||
key_guns: false,
|
||||
key_thrust: false,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl ShipBehavior for Player {
|
||||
fn update_controls(&mut self, physics: &mut Physics, _content: &content::Content) {
|
||||
let s = physics.get_ship_mut(&self.handle).unwrap();
|
||||
s.controls.left = self.key_left;
|
||||
s.controls.right = self.key_right;
|
||||
s.controls.guns = self.key_guns;
|
||||
s.controls.thrust = self.key_thrust;
|
||||
}
|
||||
|
||||
fn get_handle(&self) -> ShipHandle {
|
||||
return self.handle;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Point {
|
||||
handle: ShipHandle,
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
pub mod behavior;
|
||||
|
||||
use galactica_content as content;
|
||||
use galactica_physics::{Physics, ShipHandle};
|
||||
|
||||
pub trait ShipBehavior
|
||||
where
|
||||
Self: Send,
|
||||
{
|
||||
fn update_controls(&mut self, physics: &mut Physics, content: &content::Content);
|
||||
fn get_handle(&self) -> ShipHandle;
|
||||
}
|
|
@ -3,14 +3,11 @@ use std::time::Instant;
|
|||
use winit::event::{ElementState, MouseButton, MouseScrollDelta, TouchPhase, VirtualKeyCode};
|
||||
|
||||
use super::{camera::Camera, system::System};
|
||||
use crate::{
|
||||
content,
|
||||
inputstatus::InputStatus,
|
||||
shipbehavior::{self, ShipBehavior},
|
||||
};
|
||||
use crate::{content, inputstatus::InputStatus};
|
||||
use galactica_constants;
|
||||
use galactica_physics::{objects::ShipOutfits, util, Physics, ShipHandle};
|
||||
use galactica_render::{AnchoredUiPosition, ObjectSprite, UiSprite};
|
||||
use galactica_shipbehavior::{behavior, ShipBehavior};
|
||||
|
||||
struct Ui {}
|
||||
|
||||
|
@ -120,9 +117,9 @@ impl Game {
|
|||
);
|
||||
|
||||
let mut shipbehaviors: Vec<Box<dyn ShipBehavior>> = Vec::new();
|
||||
shipbehaviors.push(shipbehavior::Player::new(h1));
|
||||
shipbehaviors.push(shipbehavior::Dummy::new(h2));
|
||||
shipbehaviors.push(shipbehavior::Point::new(h3));
|
||||
shipbehaviors.push(behavior::Player::new(h1));
|
||||
shipbehaviors.push(behavior::Dummy::new(h2));
|
||||
shipbehaviors.push(behavior::Point::new(h3));
|
||||
|
||||
Game {
|
||||
last_update: Instant::now(),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
mod game;
|
||||
mod inputstatus;
|
||||
mod shipbehavior;
|
||||
|
||||
pub use galactica_content as content;
|
||||
|
||||
|
|
Loading…
Reference in New Issue