M server/src/component.rs => server/src/component.rs +14 -0
@@ 17,6 17,7 @@ use std::net::SocketAddr;
use bevy::prelude::*;
use serde::{Deserialize, Serialize};
+use starkingdoms_common::PartType as c_PartType;
#[derive(Component, Clone, Copy, Serialize, Deserialize, Debug)]
pub enum PlanetType {
@@ 27,12 28,25 @@ pub enum PlanetType {
#[derive(Component, Clone, Copy, PartialEq, Serialize, Deserialize, Debug)]
pub enum PartType {
+ Placeholder,
Hearty,
Cargo,
Hub,
LandingThruster,
LandingThrusterSuspension,
}
+impl From<PartType> for starkingdoms_common::PartType {
+ fn from(value: PartType) -> Self {
+ match value {
+ PartType::Placeholder => c_PartType::Placeholder,
+ PartType::Hearty => c_PartType::Hearty,
+ PartType::Cargo => c_PartType::Cargo,
+ PartType::Hub => c_PartType::Hub,
+ PartType::LandingThruster => c_PartType::LandingThruster,
+ PartType::LandingThrusterSuspension => c_PartType::LandingThrusterSuspension,
+ }
+ }
+}
#[derive(Component, Clone, Debug)]
pub struct Attach {
M server/src/main.rs => server/src/main.rs +46 -9
@@ 26,6 26,7 @@ use component::Input;
use component::*;
use packet::*;
use rand::Rng;
+use starkingdoms_common::SaveModule;
use starkingdoms_common::{pack_savefile, unpack_savefile, SaveData};
use std::f32::consts::PI;
@@ 868,15 869,20 @@ fn on_message(
}
}
Packet::RequestSave {} => {
- // HEY! GHOSTLY! PLEASE FILL THIS STRUCT WITH DATA!
- // THANKS!
- let save = SaveData {};
- let save_string = pack_savefile(&app_keys.app_key, save);
- let packet = Packet::SaveData {
- payload: save_string,
- };
- let buf = serde_json::to_vec(&packet).unwrap();
- event_queue.push(ServerEvent::Broadcast(MessageType::Text, buf));
+ for (_, q_player, _, _, attach) in &mut player_query
+ {
+ if q_player.addr == *addr {
+ // HEY! GHOSTLY! PLEASE FILL THIS STRUCT WITH DATA!
+ // THANKS!
+ let save = SaveData { module: construct_save_data(attach.clone(), &attached_query) };
+ let save_string = pack_savefile(&app_keys.app_key, save);
+ let packet = Packet::SaveData {
+ payload: save_string,
+ };
+ let buf = serde_json::to_vec(&packet).unwrap();
+ event_queue.push(ServerEvent::Broadcast(MessageType::Text, buf));
+ }
+ }
}
_ => continue,
}
@@ 887,6 893,37 @@ fn on_message(
}
}
+fn construct_save_data(
+ attach: Attach,
+ attached_query: &Query<
+ (
+ Entity,
+ &PartType,
+ &mut Transform,
+ &mut Attach,
+ &Velocity,
+ Option<&CanAttach>,
+ Option<&LooseAttach>,
+ ),
+ (Without<PlanetType>, Without<Player>),
+ >,
+) -> SaveModule {
+ let mut save_module = SaveModule {
+ part_type: starkingdoms_common::PartType::Placeholder,
+ children: vec![None, None, None, None],
+ };
+ for (i, child) in attach.children.iter().enumerate() {
+ if let Some(child) = child {
+ let (_, part_type, _, attach, _, _, _) = attached_query.get(*child).unwrap();
+ if *part_type == PartType::LandingThrusterSuspension { continue }
+ let child_save_module = construct_save_data(attach.clone(), attached_query);
+ save_module.part_type = (*part_type).into();
+ save_module.children[i] = Some(child_save_module);
+ }
+ }
+ save_module
+}
+
fn detach_recursive(
commands: &mut Commands,
attach: Attach,
M starkingdoms-common/src/lib.rs => starkingdoms-common/src/lib.rs +17 -0
@@ 29,6 29,23 @@ pub struct SaveData {
// FILL THIS WITH STUFF
// ----------------------------------------------------------------------
// THANKS! -core
+ pub module: SaveModule,
+}
+
+#[derive(Serialize, Deserialize, Debug)]
+pub struct SaveModule {
+ pub part_type: PartType,
+ pub children: Vec<Option<SaveModule>>,
+}
+
+#[derive(Clone, Copy, PartialEq, Serialize, Deserialize, Debug)]
+pub enum PartType {
+ Placeholder,
+ Hearty,
+ Cargo,
+ Hub,
+ LandingThruster,
+ LandingThrusterSuspension,
}
// no touchy. this is the struct that savefiles are actually represented in