From e49dc2fa16fe95e986b8c6ec8a807d453705bce7 Mon Sep 17 00:00:00 2001 From: ghostly_zsh Date: Fri, 11 Jul 2025 12:58:18 -0500 Subject: [PATCH] feat: fuel exists, but does nothing --- crates/unified/Cargo.toml | 1 + .../assets/config/parts/hearty.part.toml | 6 +++- crates/unified/src/client/ui.rs | 30 ++++++++++++++++--- crates/unified/src/config/part.rs | 6 ++++ crates/unified/src/ecs.rs | 12 ++++++++ crates/unified/src/server/player.rs | 16 +++++++--- crates/unified/src/shared_plugins.rs | 5 ++-- 7 files changed, 65 insertions(+), 11 deletions(-) diff --git a/crates/unified/Cargo.toml b/crates/unified/Cargo.toml index f4db34931fa979e42e3676cbe9497caca27c1c79..1ebde3747cc4b7c86093346274b93aff9d01b251 100644 --- a/crates/unified/Cargo.toml +++ b/crates/unified/Cargo.toml @@ -27,6 +27,7 @@ bevy = { version = "0.16", default-features = false, features = [ "multi_threaded", "bevy_dev_tools", "bevy_sprite_picking_backend", + "default_font", "png" ] } bevy_rapier2d = { version = "0.30", features = ["serde-serialize", "simd-stable"] } diff --git a/crates/unified/assets/config/parts/hearty.part.toml b/crates/unified/assets/config/parts/hearty.part.toml index 5cf22daf1fcefe628578f59f01684ff654ea295f..d3057597d1f0a47508b3912fb0a16e71036af55e 100644 --- a/crates/unified/assets/config/parts/hearty.part.toml +++ b/crates/unified/assets/config/parts/hearty.part.toml @@ -8,6 +8,10 @@ width = 50 height = 50 mass = 100 +[thruster] +flow_rate = 0.1 +exhaust_speed = 250 + [[joints]] id = "Top" target = { translation = [ 0.0, 50.0, 0.0 ], rotation = 0.0 } @@ -27,4 +31,4 @@ snap = { translation = [ 0.0, -25.0, 0.0 ], rotation = 180.0 } [[joints]] id = "Left" target = { translation = [ -50.0, 0.0, 0.0 ], rotation = 270.0 } -snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 270.0 } \ No newline at end of file +snap = { translation = [ -25.0, 0.0, 0.0 ], rotation = 270.0 } diff --git a/crates/unified/src/client/ui.rs b/crates/unified/src/client/ui.rs index f31505983f630412bf5211476f1871a0cd65d019..327067bd249ac079ebeb2c7527247f131b17bc20 100644 --- a/crates/unified/src/client/ui.rs +++ b/crates/unified/src/client/ui.rs @@ -1,9 +1,11 @@ use bevy::prelude::*; -use crate::client::colors; +use crate::{client::colors, ecs::{FuelText, Player, PlayerStorage, PowerText}}; pub fn ui_plugin(app: &mut App) { - app.add_systems(Startup, setup_ui); + app + .add_systems(Startup, setup_ui) + .add_systems(Update, update_ui); } fn setup_ui(mut commands: Commands) { @@ -25,7 +27,18 @@ fn setup_ui(mut commands: Commands) { }, BorderRadius::all(Val::Px(5.0)), BackgroundColor(colors::MANTLE), - children![( + children![ + ( + TextColor(colors::PEACH), + Text::new("Fuel: 25"), + FuelText, + ), + ( + TextColor(colors::PEACH), + Text::new("Power: 25"), + PowerText, + ), + /*( Node { width: Val::Percent(100.0), height: Val::Px(20.0), @@ -34,7 +47,16 @@ fn setup_ui(mut commands: Commands) { }, BorderRadius::all(Val::Px(5.0)), BackgroundColor(colors::CRUST), - )], + )*/], )], )); } + +fn update_ui( + mut fuel_text: Single<&mut Text, With>, + mut power_text: Single<&mut Text, (With, Without)>, + player: Single<(&PlayerStorage), (With, Without)>, +) { + fuel_text.0 = format!("Fuel: {}/{}", player.fuel, player.fuel_capacity); + power_text.0 = format!("Power: {}/{}", player.power, player.power_capacity); +} diff --git a/crates/unified/src/config/part.rs b/crates/unified/src/config/part.rs index 3c8a38fbad7c5ddc3fe587251c552bc38b2fd578..c7011ed1b25e8e5334f2a295a30af5e246faa2a9 100644 --- a/crates/unified/src/config/part.rs +++ b/crates/unified/src/config/part.rs @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize}; pub struct PartConfig { pub part: PartPartConfig, pub physics: PartPhysicsConfig, + pub thruster: Option, pub joints: Vec, } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] @@ -22,6 +23,11 @@ pub struct PartPhysicsConfig { pub mass: f32, } #[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] +pub struct PartThrusterConfig { + pub flow_rate: f32, // kg/s + pub exhaust_speed: f32, // m/s +} +#[derive(Deserialize, TypePath, Serialize, Clone, Debug, PartialEq)] pub struct JointConfig { pub id: String, pub target: JointOffset, diff --git a/crates/unified/src/ecs.rs b/crates/unified/src/ecs.rs index 21e5713114abd36ac41d332ec00c5e1e6f8b93db..d6296febbe7e791ecbe661316d4e7d67cd43a900 100644 --- a/crates/unified/src/ecs.rs +++ b/crates/unified/src/ecs.rs @@ -16,6 +16,10 @@ pub struct StarfieldFront; pub struct StarfieldMid; #[derive(Component)] pub struct StarfieldBack; +#[derive(Component)] +pub struct FuelText; +#[derive(Component)] +pub struct PowerText; #[derive(Resource, Default)] pub struct CursorWorldCoordinates(pub Option); @@ -72,3 +76,11 @@ pub struct DragRequestEvent { #[entities] pub snap_target: Option, } + +#[derive(Component, Serialize, Deserialize, Debug)] +pub struct PlayerStorage { + pub fuel_capacity: f32, + pub fuel: f32, + pub power_capacity: f32, + pub power: f32, +} diff --git a/crates/unified/src/server/player.rs b/crates/unified/src/server/player.rs index 47096be0bb319095977c63c4432c8c892a5e3fd0..058fbee0e9c92900b87b04902e3f4c1553313b68 100644 --- a/crates/unified/src/server/player.rs +++ b/crates/unified/src/server/player.rs @@ -1,5 +1,5 @@ use crate::config::planet::Planet; -use crate::ecs::{DragRequestEvent, Part, Player, PlayerThrust, ThrustEvent}; +use crate::ecs::{DragRequestEvent, Part, Player, PlayerStorage, PlayerThrust, ThrustEvent}; use crate::server::part::SpawnPartRequest; use crate::server::system_sets::PlayerInputSet; use crate::server::world_config::WorldConfigResource; @@ -66,6 +66,12 @@ fn handle_new_players( asset_server.load("config/parts/hearty.part.toml"), )) .insert(PlayerThrust::default()) + .insert(PlayerStorage { + fuel_capacity: 25.0, + fuel: 25.0, + power_capacity: 25.0, + power: 25.0, + }) .insert(Player { client: joined_player, }); @@ -73,7 +79,7 @@ fn handle_new_players( } fn player_thrust( - mut players: Query<(&Transform, &mut ExternalForce, &mut PlayerThrust)>, + mut players: Query<(&Transform, &Part, &mut ExternalForce, &mut PlayerThrust, &mut PlayerStorage)>, clients: Query<&ConnectedNetworkEntity>, mut thrust_event: EventReader>, world_config: Res, @@ -85,7 +91,7 @@ fn player_thrust( { let ConnectedNetworkEntity { game_entity } = clients.get(*client_entity).unwrap(); - let Ok((_, _, mut thrust)) = players.get_mut(*game_entity) else { + let Ok((_, _, _, mut thrust, _)) = players.get_mut(*game_entity) else { continue; }; @@ -96,7 +102,7 @@ fn player_thrust( ThrustEvent::Right(on) => thrust.right = on, } } - for (transform, mut force, thrust) in &mut players { + for (transform, part, mut force, thrust, mut storage) in &mut players { let Some(world_config) = &world_config.config else { return; }; @@ -154,5 +160,7 @@ fn player_thrust( transform.translation.xy(), ); *force += external_force; + + storage.fuel -= thrusters.iter().sum::() * part.strong_config.thruster.as_ref().unwrap().flow_rate; } } diff --git a/crates/unified/src/shared_plugins.rs b/crates/unified/src/shared_plugins.rs index 02e9221318148108538057b1c2d95a381428a6d9..2a8f042f0246f6bdae9644591b3d88d474e12205 100644 --- a/crates/unified/src/shared_plugins.rs +++ b/crates/unified/src/shared_plugins.rs @@ -1,6 +1,6 @@ use crate::attachment::{Joint, JointOf, PartInShip, Peer, Ship, SnapOf, SnapOfJoint}; use crate::config::planet::Planet; -use crate::ecs::{DragRequestEvent, Part, Particles, Player, ThrustEvent}; +use crate::ecs::{DragRequestEvent, Part, Particles, Player, PlayerStorage, ThrustEvent}; use bevy::app::{App, PluginGroup, PluginGroupBuilder}; use bevy::prelude::*; use bevy_rapier2d::prelude::*; @@ -35,7 +35,8 @@ pub fn register_everything(app: &mut App) { .replicate::() .replicate::() .replicate::() - .replicate::(); + .replicate::() + .replicate::(); } fn physics_setup_plugin(app: &mut App) {