Minor edits
parent
f5c9540fb7
commit
a6bc1a021d
|
@ -15,6 +15,7 @@ use log4rs::{
|
|||
Config,
|
||||
};
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
|
@ -127,7 +128,7 @@ fn try_main() -> Result<()> {
|
|||
current_time: game.get_current_time(),
|
||||
ct: content.clone(),
|
||||
phys_img: PhysImage::new(),
|
||||
player: PlayerAgent::new(&content, p.0),
|
||||
player: RefCell::new(PlayerAgent::new(&content, p.0)),
|
||||
// TODO: this is a hack for testing.
|
||||
current_system: content.systems.values().next().unwrap().clone(),
|
||||
timing: game.get_timing().clone(),
|
||||
|
@ -184,13 +185,13 @@ fn try_main() -> Result<()> {
|
|||
},
|
||||
)
|
||||
.unwrap();
|
||||
game.apply_directive(directive, &input.player);
|
||||
game.apply_directive(directive, &mut input.player.borrow_mut());
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
let directive = gpu
|
||||
.process_input(&input, InputEvent::MouseMove(position.cast()))
|
||||
.unwrap();
|
||||
game.apply_directive(directive, &input.player);
|
||||
game.apply_directive(directive, &mut input.player.borrow_mut());
|
||||
}
|
||||
WindowEvent::MouseInput { state, button, .. } => {
|
||||
let down = state == &ElementState::Pressed;
|
||||
|
@ -201,7 +202,7 @@ fn try_main() -> Result<()> {
|
|||
};
|
||||
if let Some(event) = event {
|
||||
let directive = gpu.process_input(&input, event).unwrap();
|
||||
game.apply_directive(directive, &input.player);
|
||||
game.apply_directive(directive, &mut input.player.borrow_mut());
|
||||
}
|
||||
}
|
||||
WindowEvent::MouseWheel { delta, .. } => {
|
||||
|
@ -214,7 +215,7 @@ fn try_main() -> Result<()> {
|
|||
}),
|
||||
)
|
||||
.unwrap();
|
||||
game.apply_directive(directive, &input.player);
|
||||
game.apply_directive(directive, &mut input.player.borrow_mut());
|
||||
}
|
||||
WindowEvent::Resized(_) => {
|
||||
gpu.resize(&content);
|
||||
|
|
|
@ -29,13 +29,17 @@ pub struct PlayerAgent {
|
|||
/// Which ship this player is controlling
|
||||
pub ship: Option<ColliderHandle>,
|
||||
|
||||
/// What the player has selected
|
||||
/// What this player has selected
|
||||
pub selection: PlayerSelection,
|
||||
|
||||
/// The amount of money this player has
|
||||
pub credits: u32,
|
||||
}
|
||||
|
||||
impl PlayerAgent {
|
||||
pub fn new(ct: &Content, ship: ColliderHandle) -> Self {
|
||||
Self {
|
||||
credits: 1000,
|
||||
ship: Some(ship),
|
||||
selection: PlayerSelection::OrbitingBody(
|
||||
ct.systems
|
||||
|
|
|
@ -287,7 +287,7 @@ impl GPUState {
|
|||
|
||||
/// Main render function. Draws sprites on a window.
|
||||
pub fn render(&mut self, input: &Arc<RenderInput>) -> Result<(), wgpu::SurfaceError> {
|
||||
if let Some(ship) = input.player.ship {
|
||||
if let Some(ship) = input.player.borrow().ship {
|
||||
let o = input.phys_img.get_ship(&PhysSimShipHandle(ship));
|
||||
if let Some(o) = o {
|
||||
match o.ship.get_data().get_state() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::sync::Arc;
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
use galactica_content::{Content, System};
|
||||
use galactica_playeragent::PlayerAgent;
|
||||
|
@ -9,7 +9,7 @@ use galactica_util::timing::Timing;
|
|||
#[derive(Debug)]
|
||||
pub struct RenderInput {
|
||||
/// Player ship data
|
||||
pub player: PlayerAgent,
|
||||
pub player: RefCell<PlayerAgent>,
|
||||
|
||||
/// The system we're currently in
|
||||
pub current_system: Arc<System>,
|
||||
|
|
|
@ -301,7 +301,7 @@ impl UiScriptExecutor {
|
|||
|
||||
// Send player state change events
|
||||
if {
|
||||
let player = input.player.ship;
|
||||
let player = input.player.borrow().ship;
|
||||
if let Some(player) = player {
|
||||
let ship = input.phys_img.get_ship(&PhysSimShipHandle(player)).unwrap();
|
||||
if self.last_player_state == 0
|
||||
|
|
|
@ -104,6 +104,7 @@ impl OutfitSet {
|
|||
if outfit.is_none() {
|
||||
*outfit = Some(o.clone());
|
||||
added = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if !added {
|
||||
|
@ -112,14 +113,15 @@ impl OutfitSet {
|
|||
}
|
||||
|
||||
self.used_space += o.space;
|
||||
|
||||
self.stats.add(&o.stats);
|
||||
|
||||
self.shield_generators.push(ShieldGenerator {
|
||||
outfit: o.clone(),
|
||||
delay: o.stats.shield_delay,
|
||||
generation: o.stats.shield_generation,
|
||||
});
|
||||
if o.stats.shield_generation != 0.0 {
|
||||
self.shield_generators.push(ShieldGenerator {
|
||||
outfit: o.clone(),
|
||||
delay: o.stats.shield_delay,
|
||||
generation: o.stats.shield_generation,
|
||||
});
|
||||
}
|
||||
|
||||
if self.outfits.contains_key(&o.index) {
|
||||
self.outfits.get_mut(&o.index).unwrap().1 += 1;
|
||||
|
@ -133,26 +135,32 @@ impl OutfitSet {
|
|||
pub(super) fn remove(&mut self, o: &Arc<Outfit>) -> OutfitRemoveResult {
|
||||
if !self.outfits.contains_key(&o.index) {
|
||||
return OutfitRemoveResult::NotExist;
|
||||
}
|
||||
|
||||
let n = self.outfits.get_mut(&o.index).unwrap();
|
||||
if n.1 == 1u32 {
|
||||
self.outfits.remove(&o.index);
|
||||
} else {
|
||||
let n = self.outfits.get_mut(&o.index).unwrap();
|
||||
if n.1 == 1u32 {
|
||||
self.outfits.remove(&o.index);
|
||||
} else {
|
||||
self.outfits.get_mut(&o.index).unwrap().1 -= 1;
|
||||
}
|
||||
self.outfits.get_mut(&o.index).unwrap().1 -= 1;
|
||||
}
|
||||
|
||||
if o.gun.is_some() {
|
||||
let (_, x) = self
|
||||
.gun_points
|
||||
.iter_mut()
|
||||
.find(|(_, x)| x.is_some() && x.as_ref().unwrap().index == o.index)
|
||||
.unwrap();
|
||||
*x = None;
|
||||
}
|
||||
|
||||
self.used_space -= o.space;
|
||||
|
||||
self.stats.subtract(&o.stats);
|
||||
|
||||
{
|
||||
// This index will exist, since we checked the hashmap
|
||||
let index = self
|
||||
.shield_generators
|
||||
.iter()
|
||||
.position(|g| g.outfit.index == o.index)
|
||||
.unwrap();
|
||||
let index = self
|
||||
.shield_generators
|
||||
.iter()
|
||||
.position(|g| g.outfit.index == o.index);
|
||||
if let Some(index) = index {
|
||||
self.shield_generators.remove(index);
|
||||
}
|
||||
|
||||
|
@ -198,6 +206,29 @@ impl OutfitSet {
|
|||
&self.used_space
|
||||
}
|
||||
|
||||
/// Number of available (used & free) gun points
|
||||
pub fn total_gun_points(&self) -> usize {
|
||||
self.gun_points.len()
|
||||
}
|
||||
|
||||
/// Number of free gun points
|
||||
pub fn free_gun_points(&self) -> usize {
|
||||
self.iter_gun_points().filter(|(_, o)| o.is_none()).count()
|
||||
}
|
||||
|
||||
/// Does this set contain `count` of `outfit`?
|
||||
pub fn has_outfit(&self, outfit: &Arc<Outfit>, mut count: u32) -> bool {
|
||||
for i in self.iter_outfits() {
|
||||
if count <= 0 {
|
||||
return true;
|
||||
}
|
||||
if i.0.index == outfit.index {
|
||||
count -= 1;
|
||||
}
|
||||
}
|
||||
return count <= 0;
|
||||
}
|
||||
|
||||
/// Get the combined stats of all outfits in this set.
|
||||
/// There are two things to note here:
|
||||
/// First, shield_delay is always zero. That is handled
|
||||
|
|
|
@ -14,7 +14,7 @@ use rapier2d::{
|
|||
|
||||
use super::{autopilot, collapse::ShipCollapseSequence, controller::ShipController, ShipControls};
|
||||
use crate::{
|
||||
data::{ShipAutoPilot, ShipData, ShipPersonality, ShipState},
|
||||
data::{OutfitRemoveResult, ShipAutoPilot, ShipData, ShipPersonality, ShipState},
|
||||
phys::{
|
||||
get_phys_id,
|
||||
objects::{PhysEffect, PhysProjectile},
|
||||
|
@ -505,8 +505,8 @@ impl PhysShip {
|
|||
}
|
||||
|
||||
/// Add one outfit to this ship
|
||||
pub fn add_outfit(&mut self, o: Arc<Outfit>) {
|
||||
self.data.add_outfit(&o);
|
||||
pub fn add_outfit(&mut self, o: &Arc<Outfit>) {
|
||||
self.data.add_outfit(o);
|
||||
self.update_flares();
|
||||
}
|
||||
|
||||
|
@ -517,6 +517,13 @@ impl PhysShip {
|
|||
}
|
||||
self.update_flares();
|
||||
}
|
||||
|
||||
/// Remove one outfit from this ship
|
||||
pub fn remove_outfit(&mut self, o: &Arc<Outfit>) -> OutfitRemoveResult {
|
||||
let r = self.data.remove_outfit(o);
|
||||
self.update_flares();
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
/// Public immutable
|
||||
|
|
|
@ -192,7 +192,7 @@ impl PhysSim {
|
|||
}
|
||||
|
||||
/// Update a player ship's controls
|
||||
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &PlayerAgent) {
|
||||
pub fn apply_directive(&mut self, directive: PlayerDirective, player: &mut PlayerAgent) {
|
||||
if player.ship.is_none() {
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue