~starkingdoms/starkingdoms

2e454d889137d077596fd9b6971aca61617a4b48 — ghostlyzsh 1 year, 4 months ago eec3b48
module counts on load save, committing so i can work on other things
4 files changed, 27 insertions(+), 8 deletions(-)

M kabel/src/lexer.rs
M server/src/main.rs
M server/src/module/save.rs
M server/src/player/client_login.rs
M kabel/src/lexer.rs => kabel/src/lexer.rs +2 -2
@@ 161,7 161,7 @@ impl Lexer {
            '"' => {
                let mut contents = String::new();
                while self.read_char() != '"' {
                    if self.c == '\0'{
                    if self.c == '\0' {
                        self.errors.push(KabelError::new(
                            ErrorKind::UnexpectedEof,
                            "File ended before closing quote".to_string(),


@@ 225,7 225,7 @@ impl Lexer {
        true
    }

    pub fn read_char(&mut self) -> char{
    pub fn read_char(&mut self) -> char {
        if self.current >= self.input.len() {
            self.c = '\0'; // EOF
            return self.c;

M server/src/main.rs => server/src/main.rs +0 -1
@@ 28,7 28,6 @@ use module::component::{
    Attach, CanAttach, LooseAttach, ModuleTimer, PartBundle, PartFlags, PartType,
};
use packet::*;
use planet::PlanetType;
use serde::{Deserialize, Serialize};
use std::fs;


M server/src/module/save.rs => server/src/module/save.rs +24 -4
@@ 51,8 51,9 @@ pub fn load_savefile(
        Without<PlanetType>,
    >,
    player_comp: &mut Player,
) -> [Option<Entity>; 4] {
) -> ([Option<Entity>; 4], HashMap<PartType, usize>) {
    let mut ret = [None, None, None, None];
    let mut module_count = HashMap::new();
    for (i, child) in children.iter().enumerate() {
        if let Some(child) = child {
            let part_type = PartType::from(child.part_type);


@@ 102,7 103,7 @@ pub fn load_savefile(
            };

            let children = if part_type != PartType::LandingThruster {
                load_savefile(
                let (children, count) = load_savefile(
                    commands,
                    transform,
                    player_id,


@@ 112,10 113,29 @@ pub fn load_savefile(
                    part_query,
                    player_query,
                    player_comp,
                )
                );
                for (part_type, count) in count {
                    match module_count.get_mut(&part_type) {
                        Some(old_count) => {
                            *old_count += count;
                        }
                        None => {
                            module_count.insert(part_type, count);
                        }
                    }
                }
                children
            } else {
                [None, None, None, None]
            };
            match module_count.get_mut(&part_type) {
                Some(old_count) => {
                    *old_count += 1;
                }
                None => {
                    module_count.insert(part_type, 1);
                }
            }

            let mut module = commands.entity(module_id);



@@ 220,7 240,7 @@ pub fn load_savefile(
            player_comp.energy_capacity += capacity!(part_type);
        }
    }
    ret
    (ret, module_count)
}

pub fn construct_save_data(

M server/src/player/client_login.rs => server/src/player/client_login.rs +1 -1
@@ 157,7 157,7 @@ pub fn load_save(
            // HEY! GHOSTLY! THIS SAVE FILE IS VALID! PLEASE LOAD IT!
            // THANKS!

            let children = load_savefile(
            let (children, module_counts) = load_savefile(
                commands,
                transform,
                id,