~starkingdoms/starkingdoms

eac4455ff210458bcc625d450cf5b64e79e7c1dd — core 1 year, 11 months ago 93b31a0
module lights 2
M server/src/component.rs => server/src/component.rs +2 -3
@@ 74,15 74,14 @@ pub struct PlanetBundle {

#[derive(Component, Copy, Clone)]
pub struct PartFlags {
    pub attached: bool
    pub attached: bool,
}


#[derive(Bundle)]
pub struct PartBundle {
    pub transform: TransformBundle,
    pub part_type: PartType,
    pub flags: PartFlags
    pub flags: PartFlags,
}

#[derive(Bundle)]

M server/src/main.rs => server/src/main.rs +34 -22
@@ 173,7 173,7 @@ fn module_spawn(
            let mut entity = commands.spawn(PartBundle {
                part_type: PartType::Cargo,
                transform: TransformBundle::from(transform),
                flags
                flags,
            });
            entity
                .insert(RigidBody::Dynamic)


@@ 201,7 201,7 @@ fn module_spawn(
                part: Part {
                    part_type: PartType::Cargo,
                    transform: proto_transform!(transform),
                    flags: proto_part_flags!(flags)
                    flags: proto_part_flags!(flags),
                },
            };
            let buf = serde_json::to_vec(&packet).unwrap();


@@ 234,7 234,7 @@ fn on_message(
            &Velocity,
            Option<&CanAttach>,
            Option<&LooseAttach>,
            &mut PartFlags
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>),
    >,


@@ 287,7 287,7 @@ fn on_message(
                            part: PartBundle {
                                part_type: PartType::Hearty,
                                transform: TransformBundle::from(transform),
                                flags: PartFlags { attached: false }
                                flags: PartFlags { attached: false },
                            },
                            player: Player {
                                addr: *addr,


@@ 379,7 379,7 @@ fn on_message(
                                transform: proto_transform!(Transform::from_translation(
                                    transform.translation * SCALE
                                )),
                                flags: proto_part_flags!(flags)
                                flags: proto_part_flags!(flags),
                            },
                        ));
                    }


@@ 391,7 391,7 @@ fn on_message(
                                transform: proto_transform!(Transform::from_translation(
                                    transform.translation * SCALE
                                )),
                                flags: proto_part_flags!(flags)
                                flags: proto_part_flags!(flags),
                            },
                        ));
                    }


@@ 403,7 403,7 @@ fn on_message(
                                transform.translation * SCALE
                            )
                            .with_rotation(transform.rotation)),
                            flags: ProtoPartFlags { attached: false }
                            flags: ProtoPartFlags { attached: false },
                        },
                    ));
                    let packet = Packet::PartPositions { parts };


@@ 916,7 916,7 @@ fn detach_recursive(
            &Velocity,
            Option<&CanAttach>,
            Option<&LooseAttach>,
            &mut PartFlags
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>),
    >,


@@ 944,7 944,6 @@ fn detach_recursive(
                    commands.entity(parent).insert(LooseAttach {
                        children: parent_attach.children,
                    });

                } else {
                    flags.attached = false;
                    commands.entity(entity).remove::<ImpulseJoint>();


@@ 985,7 984,7 @@ fn attach_on_module_tree(
            &Velocity,
            Option<&CanAttach>,
            Option<&LooseAttach>,
            &mut PartFlags
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>),
    >,


@@ 996,7 995,7 @@ fn attach_on_module_tree(
            &mut Transform,
            &mut Velocity,
            Option<&LooseAttach>,
            &mut PartFlags
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>, Without<Attach>),
    >,


@@ 1165,7 1164,14 @@ fn convert_modules(
    planet_query: Query<(Entity, &PlanetType, &Children)>,
    player_query: Query<&Attach, With<Player>>,
    mut attached_query: Query<
        (Entity, &mut PartType, &mut Attach, &Children, &Transform, &PartFlags),
        (
            Entity,
            &mut PartType,
            &mut Attach,
            &Children,
            &Transform,
            &PartFlags,
        ),
        Without<Player>,
    >,
    mut collider_query: Query<


@@ 1227,7 1233,14 @@ fn convert_modules_recursive(
    planet_type: PlanetType,
    attach: Attach,
    attached_query: &mut Query<
        (Entity, &mut PartType, &mut Attach, &Children, &Transform, &PartFlags),
        (
            Entity,
            &mut PartType,
            &mut Attach,
            &Children,
            &Transform,
            &PartFlags,
        ),
        Without<Player>,
    >,
    collider_query: &mut Query<


@@ 1266,7 1279,7 @@ fn convert_modules_recursive(
                            part: Part {
                                part_type: PartType::Hub,
                                transform: proto_transform!(transform),
                                flags: proto_part_flags!(part_flags)
                                flags: proto_part_flags!(part_flags),
                            },
                        };
                        let buf = serde_json::to_vec(&packet).unwrap();


@@ 1289,7 1302,7 @@ fn convert_modules_recursive(
                        let mut suspension = commands.spawn(PartBundle {
                            transform: TransformBundle::from(*module_transform),
                            part_type: PartType::LandingThrusterSuspension,
                            flags: PartFlags { attached: false }
                            flags: PartFlags { attached: false },
                        });
                        suspension
                            .insert(RigidBody::Dynamic)


@@ 1328,7 1341,7 @@ fn convert_modules_recursive(
                            part: Part {
                                part_type: PartType::LandingThruster,
                                transform: proto_transform!(transform),
                                flags: proto_part_flags!(part_flags)
                                flags: proto_part_flags!(part_flags),
                            },
                        };
                        let buf = serde_json::to_vec(&packet).unwrap();


@@ 1340,7 1353,7 @@ fn convert_modules_recursive(
                            part: Part {
                                part_type: PartType::LandingThrusterSuspension,
                                transform: proto_transform!(transform),
                                flags: proto_part_flags!(part_flags)
                                flags: proto_part_flags!(part_flags),
                            },
                        };
                        let buf = serde_json::to_vec(&packet).unwrap();


@@ 1375,7 1388,7 @@ fn break_modules(
            &Velocity,
            Option<&CanAttach>,
            Option<&LooseAttach>,
            &mut PartFlags
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>),
    >,


@@ 1403,10 1416,9 @@ fn break_modules(
            });
            if (attach.children[2].is_some()) {
                commands
                .entity(attach.children[2].unwrap())
                .remove::<Attach>();
                    .entity(attach.children[2].unwrap())
                    .remove::<Attach>();
            }

        } else {
            detach_recursive(&mut commands, attach.clone(), &mut attached_query);
        }


@@ 1568,7 1580,7 @@ fn on_position_change(
                    transform.translation * SCALE
                )
                .with_rotation(transform.rotation)),
                flags: proto_part_flags!(flags)
                flags: proto_part_flags!(flags),
            },
        ));
    }

M server/src/packet.rs => server/src/packet.rs +4 -4
@@ 43,21 43,21 @@ pub struct Planet {
pub struct Part {
    pub part_type: PartType,
    pub transform: ProtoTransform,
    pub flags: ProtoPartFlags
    pub flags: ProtoPartFlags,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ProtoPartFlags {
    pub attached: bool
    pub attached: bool,
}

#[macro_export]
macro_rules! proto_part_flags {
    ($e:expr) => {
        $crate::packet::ProtoPartFlags {
            attached: $e.attached
            attached: $e.attached,
        }
    }
    };
}

#[derive(Debug, Serialize, Deserialize)]

M starkingdoms-client/src/hub.ts => starkingdoms-client/src/hub.ts +5 -1
@@ 204,7 204,11 @@ export async function hub_connect(
          let new_part = p.parts[i][1];

          let old_part = global.parts_map.get(id);
          if (old_part !== undefined && (old_part.part_type !== new_part.part_type || old_part.flags !== new_part.flags)) {
          if (
            old_part !== undefined &&
            (old_part.part_type !== new_part.part_type ||
              old_part.flags !== new_part.flags)
          ) {
            global.rendering?.part_sprites_need_texture_change.push(id);
          }


M starkingdoms-client/src/rendering.ts => starkingdoms-client/src/rendering.ts +8 -4
@@ 25,7 25,7 @@ export function startRender() {
    player_text_map: new Map(),
    planet_sprite_map: new Map(),
    part_sprite_map: new Map(),
    part_sprites_need_texture_change: []
    part_sprites_need_texture_change: [],
  };

  app.ticker.add(() => {


@@ 35,16 35,20 @@ export function startRender() {
      -player()?.transform.y! + window.innerHeight / 2;

    for (let [id, part] of global.parts_map) {
      let part_sprite
      let part_sprite;

      if (global.rendering!.part_sprite_map.has(id)) {
        part_sprite = global.rendering!.part_sprite_map.get(id)!;
        if (global.rendering!.part_sprites_need_texture_change.includes(id)) {
          // slow :(
          part_sprite.texture = PIXI.Texture.from(part_texture_url(part.part_type, part.flags.attached));
          part_sprite.texture = PIXI.Texture.from(
            part_texture_url(part.part_type, part.flags.attached),
          );
        }
      } else {
        part_sprite = PIXI.Sprite.from(part_texture_url(part.part_type, part.flags.attached));
        part_sprite = PIXI.Sprite.from(
          part_texture_url(part.part_type, part.flags.attached),
        );
        global.rendering!.part_sprite_map.set(id, part_sprite);
        global.rendering!.app.stage.addChild(part_sprite);
      }