~starkingdoms/starkingdoms

04beb9f36db6a39a3be1263a79cdf80af900dbe0 — core 5 months ago 87c16b9
fix: anchors
M crates/unified/src/attachment.rs => crates/unified/src/attachment.rs +5 -5
@@ 30,11 30,11 @@ pub struct JointOf(#[entities] pub Entity);
#[relationship_target(relationship = JointOf)]
pub struct Joints(#[entities] Vec<Entity>);
#[derive(Component, Serialize, Deserialize, MapEntities)]
#[relationship(relationship_target = JointSnaps)]
pub struct JointSnapOf(#[entities] pub Entity);
#[relationship(relationship_target = Snaps)]
pub struct SnapOf(#[entities] pub Entity);
#[derive(Component, Serialize, Deserialize, MapEntities)]
#[relationship_target(relationship = JointSnapOf)]
pub struct JointSnaps(#[entities] Vec<Entity>);
#[relationship_target(relationship = SnapOf)]
pub struct Snaps(#[entities] Vec<Entity>);

#[derive(Serialize, Deserialize)]
pub struct JointId(pub String);


@@ 45,4 45,4 @@ impl JointId {
}

#[derive(Serialize, Deserialize, Component, MapEntities)]
pub struct JointSnapFor(#[entities] pub Entity);
pub struct SnapOfJoint(#[entities] pub Entity);

M crates/unified/src/client/key_input.rs => crates/unified/src/client/key_input.rs +3 -2
@@ 1,4 1,4 @@
use crate::attachment::{Joint, JointSnapFor};
use crate::attachment::{Joint, SnapOfJoint};
use crate::ecs::ThrustEvent;
use bevy::color::palettes::css::{FUCHSIA, GREEN};
use bevy::dev_tools::picking_debug::DebugPickingMode;


@@ 12,6 12,7 @@ use bevy::{
    ecs::{event::EventWriter, system::Res},
    input::{ButtonInput, keyboard::KeyCode},
};
use bevy::log::debug;
use bevy_rapier2d::render::DebugRenderContext;

pub fn key_input_plugin(app: &mut App) {


@@ 69,7 70,7 @@ fn directional_keys(keys: Res<ButtonInput<KeyCode>>, mut thrust_event: EventWrit

fn draw_attachment_debug(
    joints: Query<&GlobalTransform, With<Joint>>,
    snaps: Query<&GlobalTransform, With<JointSnapFor>>,
    snaps: Query<&GlobalTransform, With<SnapOfJoint>>,
    mut gizmos: Gizmos,
    state: ResMut<AttachmentDebugRes>,
) {

M crates/unified/src/server/part.rs => crates/unified/src/server/part.rs +43 -1
@@ 1,7 1,10 @@
use bevy::ecs::spawn::SpawnRelatedBundle;
use bevy::prelude::Component;
use bevy::prelude::*;
use bevy_rapier2d::prelude::{AdditionalMassProperties, Collider};
use crate::config::part::PartConfig;
use bevy_replicon::prelude::Replicated;
use crate::attachment::{Joint, JointId, JointOf, SnapOf, SnapOfJoint};
use crate::config::part::{JointConfig, PartConfig};
use crate::ecs::{Part, PartHandle};

pub fn part_management_plugin(app: &mut App) {


@@ 25,6 28,7 @@ pub fn handle_ready_parts(loading_parts: Query<(Entity, &SpawnPartRequest)>, mut
            commands.entity(entity)
                .insert(calculate_bundle(strong_config, &loading_part.0))
                .remove::<SpawnPartRequest>();
            spawn_joints(strong_config, entity, commands.reborrow());
        }
    }
}


@@ 42,5 46,43 @@ fn calculate_bundle(config: &PartConfig, handle: &Handle<PartConfig>) -> impl Bu
        part_handle,
        collider,
        additional_mass_properties,
        Replicated
    )
}
fn spawn_joint_bundle(joint: &JointConfig, part: &PartConfig, parent: &Entity) -> impl Bundle {
    let j_comp = Joint {
        id: JointId::from_part_and_joint_id(part.part.name.clone(), joint.id.clone()),
        transform: joint.target.into(),
    };
    let joint_transform: Transform = j_comp.transform;
    let joint_of = JointOf(*parent);
    let child_of = ChildOf(*parent);

    (
        j_comp,
        joint_transform,
        joint_of,
        child_of,
        Replicated
    )
}
fn spawn_snap_bundle(joint: &JointConfig, parent: &Entity, p_joint: &Entity) -> impl Bundle {
    let snap_transform: Transform = joint.snap.into();
    let snap_for = SnapOf(*parent);
    let snap_of = SnapOfJoint(*p_joint);
    let child_of = ChildOf(*parent);

    (
        snap_transform,
        snap_for,
        snap_of,
        child_of,
        Replicated
    )
}
fn spawn_joints(config: &PartConfig, parent: Entity, mut commands: Commands) {
    for joint in &config.joints {
        let joint_id = commands.spawn(spawn_joint_bundle(joint, config, &parent)).id();
        commands.spawn(spawn_snap_bundle(joint, &parent, &joint_id));
    }
}
\ No newline at end of file

M crates/unified/src/shared_plugins.rs => crates/unified/src/shared_plugins.rs +2 -2
@@ 1,4 1,4 @@
use crate::attachment::{Joint, JointOf, JointSnapFor, PartInShip, Peer, Ship};
use crate::attachment::{Joint, JointOf, SnapOfJoint, PartInShip, Peer, Ship};
use crate::config::planet::Planet;
use crate::ecs::{DragRequestEvent, Part, Particles, Player, ThrustEvent};
use bevy::app::{App, PluginGroup, PluginGroupBuilder};


@@ 34,7 34,7 @@ pub fn register_everything(app: &mut App) {
        .replicate::<Joint>()
        .replicate::<Peer>()
        .replicate::<JointOf>()
        .replicate::<JointSnapFor>();
        .replicate::<SnapOfJoint>();
}

fn physics_setup_plugin(app: &mut App) {