~starkingdoms/starkingdoms

5cbe785de756610dbc159045ba44f459b5ae1ed8 — ghostlyzsh 1 year, 11 months ago 6ec56cc
module cap, just a little thing
2 files changed, 26 insertions(+), 21 deletions(-)

M server/src/component.rs
M server/src/main.rs
M server/src/component.rs => server/src/component.rs +1 -1
@@ 75,7 75,7 @@ pub struct PlayerBundle {
pub struct ModuleTimer(pub Timer);
impl ModuleTimer {
    pub fn new() -> Self {
        Self(Timer::from_seconds(3.0, TimerMode::Repeating))
        Self(Timer::from_seconds(0.03, TimerMode::Repeating))
    }
}
impl Default for ModuleTimer {

M server/src/main.rs => server/src/main.rs +25 -20
@@ 43,6 43,9 @@ const GRAVITY: f32 = 0.02;
const PART_HALF_SIZE: f32 = 25.0;
const THRUSTER_FORCE: f32 = 0.08;

// maybe make this only cargo modules later
const FREE_MODULE_CAP: usize = 30;

fn main() {
    App::new()
        .insert_resource(TwiteServerConfig {


@@ 104,7 107,7 @@ fn spawn_planets(mut commands: Commands) {
        .insert(ReadMassProperties::default())
        .insert(RigidBody::Fixed);
}
fn module_spawn(mut commands: Commands, time: Res<Time>, mut module_timer: ResMut<ModuleTimer>) {
fn module_spawn(mut commands: Commands, time: Res<Time>, mut module_timer: ResMut<ModuleTimer>, part_query: Query<&PartType, Without<Attach>>) {
    if module_timer.0.tick(time.delta()).just_finished() {
        let angle: f32 = {
            let mut rng = rand::thread_rng();


@@ 116,25 119,27 @@ fn module_spawn(mut commands: Commands, time: Res<Time>, mut module_timer: ResMu
            0.0,
        );
        transform.rotate_z(angle);
        commands
            .spawn(PartBundle {
                part_type: PartType::Cargo,
                transform: TransformBundle::from(transform),
            })
            .insert(RigidBody::Dynamic)
            .with_children(|children| {
                children
                    .spawn(Collider::cuboid(18.75 / SCALE, 23.4375 / SCALE))
                    .insert(TransformBundle::from(Transform::from_xyz(
                        0.,
                        1.5625 / SCALE,
                        0.,
                    )));
            })
            .insert(ExternalForce::default())
            .insert(ExternalImpulse::default())
            .insert(Velocity::default())
            .insert(ReadMassProperties::default());
        if part_query.iter().count() < FREE_MODULE_CAP {
            commands
                .spawn(PartBundle {
                    part_type: PartType::Cargo,
                    transform: TransformBundle::from(transform),
                })
                .insert(RigidBody::Dynamic)
                .with_children(|children| {
                    children
                        .spawn(Collider::cuboid(18.75 / SCALE, 23.4375 / SCALE))
                        .insert(TransformBundle::from(Transform::from_xyz(
                            0.,
                            1.5625 / SCALE,
                            0.,
                        )));
                })
                .insert(ExternalForce::default())
                .insert(ExternalImpulse::default())
                .insert(Velocity::default())
                .insert(ReadMassProperties::default());
        }
    }
}