M crates/unified/assets/config/ship_editor.se.toml => crates/unified/assets/config/ship_editor.se.toml +3 -0
@@ 1,3 1,6 @@
+[general]
+player_part = "Hearty"
+
[part_list]
Hub = { order = 0 }
Basic_Thruster = { order = 1 }
M crates/unified/src/shared/config/ship_editor.rs => crates/unified/src/shared/config/ship_editor.rs +6 -0
@@ 3,10 3,16 @@ use crate::prelude::*;
#[derive(Deserialize, Asset, TypePath, Component, Serialize, Clone, Debug)]
pub struct ShipEditorConfig {
+ pub general: GeneralShipEditor,
pub part_list: HashMap<String, PartIcon>,
}
#[derive(Deserialize, TypePath, Component, Serialize, Clone, Debug)]
+pub struct GeneralShipEditor {
+ pub player_part: String,
+}
+
+#[derive(Deserialize, TypePath, Component, Serialize, Clone, Debug)]
pub struct PartIcon {
pub order: usize,
}=
\ No newline at end of file
M crates/unified/src/ship_editor/components.rs => crates/unified/src/ship_editor/components.rs +15 -2
@@ 1,5 1,7 @@
use bevy::camera::visibility::RenderLayers;
-use crate::prelude::Component;
+use crate::prelude::{Component, Handle, Resource};
+use crate::shared::config::part::PartConfig;
+use crate::shared::config::ship_editor::ShipEditorConfig;
pub const MAIN_RENDER_LAYER: RenderLayers = RenderLayers::layer(0);
pub const GHOST_RENDER_LAYER: RenderLayers = RenderLayers::layer(1);
@@ 10,4 12,15 @@ pub struct GhostModule;
#[derive(Component)]
pub struct MainCamera;
#[derive(Component)]
-pub struct GhostCamera;>
\ No newline at end of file
+pub struct GhostCamera;
+#[derive(Component)]
+pub struct PlayerPartRequest;
+#[derive(Component)]
+pub struct SpawnPartRequest(pub Handle<PartConfig>);
+#[derive(Component)]
+pub struct Part(pub PartConfig);
+
+#[derive(Resource, Default)]
+pub struct ShipEditorConfigHolder {
+ pub handle: Option<Handle<ShipEditorConfig>>,
+}<
\ No newline at end of file
M crates/unified/src/ship_editor/mod.rs => crates/unified/src/ship_editor/mod.rs +43 -5
@@ 6,9 6,11 @@ pub mod components;
use bevy::input_focus::InputFocus;
use crate::client::colors;
use crate::prelude::*;
-use crate::ship_editor::components::{GhostCamera, MainCamera, GHOST_RENDER_LAYER, MAIN_RENDER_LAYER};
+use crate::shared::config::part::PartConfig;
+use crate::shared::config::ship_editor::ShipEditorConfig;
+use crate::ship_editor::components::{GhostCamera, MainCamera, Part, PlayerPartRequest, ShipEditorConfigHolder, SpawnPartRequest, GHOST_RENDER_LAYER, MAIN_RENDER_LAYER};
use crate::ship_editor::input::input_plugin;
-use crate::ship_editor::ui::ui_plugin;
+use crate::ship_editor::ui::{ui_plugin, PendingPart};
pub struct ShipEditorPlugin;
@@ 17,6 19,7 @@ impl Plugin for ShipEditorPlugin {
app
.init_resource::<InputFocus>()
.add_systems(Startup, setup)
+ .add_systems(Update, (spawn_player_part_request, spawn_parts))
.add_plugins(input_plugin)
.add_plugins(ui_plugin);
}
@@ 50,8 53,43 @@ fn setup(
));
let rectangle = meshes.add(Rectangle::new(50.0, 50.0));
commands.spawn((
- Mesh2d(rectangle),
- MeshMaterial2d(materials.add(Color::linear_rgb(0.0, 0.0, 0.0))),
- Transform::from_xyz(0.0, 0.0, 0.0)
+ PlayerPartRequest,
+ Transform::from_xyz(0.0, 0.0, 0.0),
));
+}
+
+fn spawn_player_part_request(
+ player_part_request_query: Query<Entity, With<PlayerPartRequest>>,
+ ship_editor_config_holder: Res<ShipEditorConfigHolder>,
+ ship_editor_config: Res<Assets<ShipEditorConfig>>,
+ mut commands: Commands,
+ asset_server: Res<AssetServer>,
+) {
+ let Some(handle) = ship_editor_config_holder.handle.clone() else { return };
+ if let Some(strong_ship_editor_config) = ship_editor_config.get(&handle) {
+ let player_part = &strong_ship_editor_config.general.player_part;
+ for entity in player_part_request_query {
+ commands.entity(entity)
+ .insert(SpawnPartRequest(asset_server.load(format!("config/parts/{}.part.toml", player_part.to_lowercase()))))
+ .remove::<PlayerPartRequest>();
+ }
+ }
+}
+fn spawn_parts(
+ spawn_part_query: Query<(Entity, &SpawnPartRequest)>,
+ part_config: Res<Assets<PartConfig>>,
+ asset_server: Res<AssetServer>,
+ mut commands: Commands,
+) {
+ for (entity, request) in spawn_part_query.iter() {
+ if let Some(strong_part_config) = part_config.get(&request.0) {
+ let mut sprite = Sprite::from_image(asset_server.load(strong_part_config.part.sprite_connected.clone()));
+ sprite.custom_size = Some(vec2(strong_part_config.physics.width as f32, strong_part_config.physics.height as f32));
+
+ commands.entity(entity)
+ .insert(sprite)
+ .insert(Part(strong_part_config.clone()))
+ .remove::<SpawnPartRequest>();
+ }
+ }
}=
\ No newline at end of file
M crates/unified/src/ship_editor/ui.rs => crates/unified/src/ship_editor/ui.rs +1 -9
@@ 1,11 1,8 @@
-use bevy::input_focus::InputFocus;
use crate::client::colors;
use bevy::prelude::*;
-use bevy::ui::FocusPolicy;
-use bevy::ui::widget::ImageNodeSize;
use crate::shared::config::part::PartConfig;
-use crate::shared::config::recipe::RecipesConfig;
use crate::shared::config::ship_editor::ShipEditorConfig;
+use crate::ship_editor::components::ShipEditorConfigHolder;
pub fn ui_plugin(app: &mut App) {
app
@@ 23,11 20,6 @@ pub struct PartList;
#[derive(Component)]
pub struct PartEntry(pub PartConfig);
-#[derive(Resource, Default)]
-struct ShipEditorConfigHolder {
- handle: Option<Handle<ShipEditorConfig>>,
-}
-
fn load_ship_editor_config(
mut config: ResMut<ShipEditorConfigHolder>,
asset_server: Res<AssetServer>,