better error handling on loading above map, TODOL: Optimise map parsing

This commit is contained in:
deadvey 2025-02-21 04:07:50 +00:00
parent 2b809d7450
commit 4fceee3856
6 changed files with 52 additions and 31 deletions

View File

@ -5,8 +5,8 @@
"mining": 0 "mining": 0
}, },
"coordinates": { "coordinates": {
"x": 41, "x": 100,
"z": 30, "z": 29,
"map": "world" "map": "world"
}, },
"inventory": [ "inventory": [

View File

@ -1,20 +1,20 @@
#### #### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #### #### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#### #### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ #### #### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
########################################### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ########################################### ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#### #%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%# #### ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ #### # # # # # #### ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^
# #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# # ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ # # # # ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
# #%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%# # ^ ^^^^^^^^^^^^^^^^^^^^^ # # # # # # # ^ ^^^^^^^^^^^^^^^^^^^^^
# #%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%# # ^ ^^^^^^^^^^^^^^^^^ # # # # # # # ^ ^^^^^^^^^^^^^^^^^
# ###################%%%%########## # ^^^ ^^^^^^^^^ # ################### ########## # ^^^ ^^^^^^^^^
# # ^ ^^^^^^^^^ # # ^ ^^^^^^^^^
######### ########## ########## # ^^^ ^^^^^^^^^ ######### ########## ########## # ^^^ ^^^^^^^^^
#%%%%%%%# #%%%%%%%%# #%%%%%%%%# # ^ ^^^^^^^^ # # # # # # # ^ ^^^^^^^^
#%%%%%%%# #%%%%%%%%# #%%%%%%%%# # ^^ ^^^^^^^ # # # # # # # ^^ ^^^^^^^
#######%# ####%%%%%# #%%%%%%%%# # ^ ^^^^^ ####### # #### # # # # ^ ^^^^^
# #%%%%%# #####%#### # ^^^ ^^^^^ # # # ##### #### # ^^^ ^^^^^
# ####### #%%%%%# # ^^ ^^^^^ # ####### # # # ^^ ^^^^^
#### ##%%%%%# ###%%## ####%### #### ^^^^^ ^^^^^ #### ## # ### ## #### ### #### ^^^^^ ^^^^^
#### #%%%%%%% #%%%%%%# #### ^ ^^^^^ #### # # # #### ^ ^^^^^
###################### ############## ^^^ ^^^^^ ###################### ############## ^^^ ^^^^^
#### #### ♣ ^^^^^^^^^^^^^^^ #### #### ♣ ^^^^^^^^^^^^^^^
♣ ♣ ^^^^^^^^^^ ♣ ♣ ^^^^^^^^^^

View File

@ -1,20 +1,20 @@
''''''''''''####'''''''''''''''''''''''''''''''''''####''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''####'''''''''''''''''''''''''''''''''''####''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''#;;#'''''''''''''''''''''''''''''''''''#;;#''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''#;;#'''''''''''''''''''''''''''''''''''#;;#''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''#;;;###################################;;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''#;;;###################################;;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''##;;;#;;;;;;;;#;;;;;;#;;;;;;;;;;#;;;;#;;;##''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''##;;;#%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%#;;;##''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#;;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#;;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;#;;;;;;;;#;;;;;;#;;;;;;;;;;#;;;;#;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;#%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%#;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;#;;;;;;;;#;;;;;;#;;;;;;;;;;#;;;;#;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;#%%%%%%%%#%%%%%%#%%%%%%%%%%#%%%%#;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;###################;;;;##########;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;###################%%%%##########;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#########;##########;;;;;;;##########;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#########;##########;;;;;;;##########;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;;;;;;#;#;;;;;;;;#;;;;;;;#;;;;;;;;#;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#%%%%%%%#;#%%%%%%%%#;;;;;;;#%%%%%%%%#;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;;;;;;#;#;;;;;;;;#;;;;;;;#;;;;;;;;#;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#%%%%%%%#;#%%%%%%%%#;;;;;;;#%%%%%%%%#;#''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#######;#;####;;;;;#;;;;;;;#;;;;;;;;#;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#######%#;####%%%%%#;;;;;;;#%%%%%%%%#;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;;;;;;;;;;;#;;;;;#;;;;;;;#####;####;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;;;;;;;;;;;#%%%%%#;;;;;;;#####%####;#'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''''#;;;#######;;#;;;;;#;;;;;;;;;;;;;;;;;;#''''''''''''''''''''''''''''''''''''''';;;;;;;;;'''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''''#;;;#######;;#%%%%%#;;;;;;;;;;;;;;;;;;#''''''''''''''''''''''''''''''''''''''';;;;;;;;;'''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''###;;##;;;;;#;;###;;##;;;;;;;;####;###;####''''''''''''''''''''''''''''''''';;;;;;'''''';;;;;;;;'''''''''[[[[[[[[[[[[[[[[[[[[[[[[ ''''''''''''###;;##%%%%%#;;###%%##;;;;;;;;####%###;####''''''''''''''''''''''''''''''''';;;;;;'''''';;;;;;;;'''''''''[[[[[[[[[[[[[[[[[[[[[[[[
''''''''''''#;;;;#;;;;;;;;;;;;;;;;;;;;;;;;#;;;;;;#;;;;#'''''''''''''''''''''''''';;;;;;;'''''''''''''''''';;;;;''''''''';;;;[[[[[[[[[[[[[[[[[ ''''''''''''#;;;;#%%%%%%%;;;;;;;;;;;;;;;;;#%%%%%%#;;;;#'''''''''''''''''''''''''';;;;;;;'''''''''''''''''';;;;;''''''''';;;;[[[[[[[[[[[[[[[[[
''''''''''''#;;###################;;;;;;;###########;;#'''''''''''''''''''''';;;;;;''''''''''''''''''''''''''';;;;;;;;;;;;;;[[[[[[[[[[[[[[[[[ ''''''''''''#;;###################;;;;;;;###########;;#'''''''''''''''''''''';;;;;;''''''''''''''''''''''''''';;;;;;;;;;;;;;[[[[[[[[[[[[[[[[[
''''''''''''####'''''''''''''''''';;;;;;;''''''''''####''''''''''''';;;;;;;;;;'''''''''''''''''''''''''''''''''''''''';;;;;;''[[[[[[[[[[[[[[[ ''''''''''''####'''''''''''''''''';;;;;;;''''''''''####''''''''''''';;;;;;;;;;'''''''''''''''''''''''''''''''''''''''';;;;;;''[[[[[[[[[[[[[[[
'''''''''''''''''''''''''''''''''';;;;;;;''''''''''''''''''''''''';;;''''''''''''''''''''''''''''''''''''''''''''''''''';;;''''''''[[[[[[[[[[ '''''''''''''''''''''''''''''''''';;;;;;;''''''''''''''''''''''''';;;''''''''''''''''''''''''''''''''''''''''''''''''''';;;''''''''[[[[[[[[[[

View File

@ -22,3 +22,19 @@ pub fn clear_screen()
.status() .status()
.expect("Failed to clear screen"); .expect("Failed to clear screen");
} }
pub fn read_element_from_map(vector: &Vec<Vec<char>>, index1: usize, index2: usize) -> Result<char, ()>
{
if vector.len() <= index1
{
Err(())
}
else if vector[index1].len() <= index2
{
Err(())
}
else
{
Ok(vector[index1][index2])
}
}

View File

@ -55,7 +55,7 @@ fn main()
{ // Parse the map file into a vector { // Parse the map file into a vector
if DEBUG_MODE == false if DEBUG_MODE == false
{ {
function::clear_screen; function::clear_screen();
} }
output_map::output_map // Call output_map fuctino from output_map.rs output_map::output_map // Call output_map fuctino from output_map.rs
( (

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use crate::Coordinates; use crate::Coordinates;
use crate::DEBUG_MODE; use crate::DEBUG_MODE;
use crate::function;
// Output the map based on map vector // Output the map based on map vector
pub fn output_map( pub fn output_map(
@ -51,7 +51,11 @@ pub fn output_map(
if x >= 0 && x < ground_map[z as usize].len() as i16 if x >= 0 && x < ground_map[z as usize].len() as i16
{ {
let character: char = ground_map[z as usize][x as usize]; let character: char = ground_map[z as usize][x as usize];
let above_character: char = above_map[z as usize][x as usize]; let mut above_character: char = ' ';
if let Ok(above_element) = function::read_element_from_map(&above_map, z as usize, x as usize)
{
above_character = above_element;
}
// Check if the character is at the current coordinates // Check if the character is at the current coordinates
if z == player_coordinates.z && x == player_coordinates.x if z == player_coordinates.z && x == player_coordinates.x
{ {
@ -108,6 +112,7 @@ pub fn output_map(
) )
) )
} }
} }
} }
println!(""); println!("");