From eac4455ff210458bcc625d450cf5b64e79e7c1dd Mon Sep 17 00:00:00 2001 From: core Date: Sat, 6 Jan 2024 23:44:25 -0500 Subject: [PATCH] module lights 2 --- server/src/component.rs | 5 +-- server/src/main.rs | 56 +++++++++++++++++----------- server/src/packet.rs | 8 ++-- starkingdoms-client/src/hub.ts | 6 ++- starkingdoms-client/src/rendering.ts | 12 ++++-- 5 files changed, 53 insertions(+), 34 deletions(-) diff --git a/server/src/component.rs b/server/src/component.rs index 90cf50f19d27ce291aab764e4e2c311b5a074894..6465cc456b664ec3f11e3817d7be8af27830f978 100644 --- a/server/src/component.rs +++ b/server/src/component.rs @@ -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)] diff --git a/server/src/main.rs b/server/src/main.rs index d1ec4f97eaf5e40dba6108d1eb94eb0ab2a93c2d..c85d3127e40503149abf984c124b58a3beaee748 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -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, Without), >, @@ -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, Without), >, @@ -944,7 +944,6 @@ fn detach_recursive( commands.entity(parent).insert(LooseAttach { children: parent_attach.children, }); - } else { flags.attached = false; commands.entity(entity).remove::(); @@ -985,7 +984,7 @@ fn attach_on_module_tree( &Velocity, Option<&CanAttach>, Option<&LooseAttach>, - &mut PartFlags + &mut PartFlags, ), (Without, Without), >, @@ -996,7 +995,7 @@ fn attach_on_module_tree( &mut Transform, &mut Velocity, Option<&LooseAttach>, - &mut PartFlags + &mut PartFlags, ), (Without, Without, Without), >, @@ -1165,7 +1164,14 @@ fn convert_modules( planet_query: Query<(Entity, &PlanetType, &Children)>, player_query: Query<&Attach, With>, mut attached_query: Query< - (Entity, &mut PartType, &mut Attach, &Children, &Transform, &PartFlags), + ( + Entity, + &mut PartType, + &mut Attach, + &Children, + &Transform, + &PartFlags, + ), Without, >, 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, >, 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, Without), >, @@ -1403,10 +1416,9 @@ fn break_modules( }); if (attach.children[2].is_some()) { commands - .entity(attach.children[2].unwrap()) - .remove::(); + .entity(attach.children[2].unwrap()) + .remove::(); } - } 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), }, )); } diff --git a/server/src/packet.rs b/server/src/packet.rs index b3c832b15edabfd9c16305ee18b868ec0ae4c93b..5611c03b1134c8ba43c6cbde0f3100871d4edba0 100644 --- a/server/src/packet.rs +++ b/server/src/packet.rs @@ -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)] diff --git a/starkingdoms-client/src/hub.ts b/starkingdoms-client/src/hub.ts index 866869066cc25a76b80e4e6c5f7dd69b55af0964..96ab66f3168fc5a7ab2a4bbf18b0af48a9fa50cd 100644 --- a/starkingdoms-client/src/hub.ts +++ b/starkingdoms-client/src/hub.ts @@ -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); } diff --git a/starkingdoms-client/src/rendering.ts b/starkingdoms-client/src/rendering.ts index 5f77a7832d815b5395291b095c1eea348bb6045d..e160ccc2fea3d3fb336ad63ca9170eb978d93514 100644 --- a/starkingdoms-client/src/rendering.ts +++ b/starkingdoms-client/src/rendering.ts @@ -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); }