Adding a map creation plugin #57

Merged
CoCo_Sol merged 39 commits from map-generation into main 2024-02-21 20:10:03 +00:00
Showing only changes of commit 74d81721c7 - Show all commits

View file

@ -41,25 +41,25 @@ fn generate_map(
mut event: EventReader<StartMapGeneration>, mut event: EventReader<StartMapGeneration>,
mut end_map_event: EventWriter<EndMapGeneration>, mut end_map_event: EventWriter<EndMapGeneration>,
mut commands: Commands, mut commands: Commands,
CoCo_Sol marked this conversation as resolved Outdated

Perlin isn't a function

Perlin isn't a function
mut noise: Local<Option<Perlin>>, mut local_noise: Local<Option<Perlin>>,
CoCo_Sol marked this conversation as resolved Outdated

Isize will not be great to use for networking because it's length depend on the system that runs the program.
Also you should use type to alias a specific type for the HexPosition used for the map.

Isize will not be great to use for networking because it's length depend on the system that runs the program. Also you should use `type` to alias a specific type for the HexPosition used for the map.

I use only one time the hex position, is it really better to create a new type ?

I use only one time the hex position, is it really better to create a new type ?

You will use it every time you want to make a Query on the HexPosition

You will use it every time you want to make a Query on the HexPosition

ok, you've convinced me

ok, you've convinced me
mut spiral: Local<Option<HexSpiral<i32>>>, mut local_spiral: Local<Option<HexSpiral<i32>>>,
) { ) {
// Handle map generation events. // Handle map generation events.
for event in event.read() { for event in event.read() {
*noise = Some(Perlin::new(event.seed)); *local_noise = Some(Perlin::new(event.seed));
*spiral = Some(TilePosition::new(0,0).spiral(event.radius as usize)); *local_spiral = Some(TilePosition::new(0,0).spiral(event.radius as usize));
} }
CoCo_Sol marked this conversation as resolved Outdated

You can use the let else syntax to remove one level of nesting.

You can use the let else syntax to remove one level of nesting.

if I use the "else let" keyword, the nesting level is the same

if I use the "else let" keyword, the nesting level is the same

No because you do an early return

No because you do an early return

I have to write an unwrap so ?

I have to write an unwrap so ?

No, an let else

No, an let else
if let (None, None) = (noise.as_ref(), spiral.as_mut()) { let (Some(noise), Some(spiral)) = (local_noise.as_ref(), local_spiral.as_mut()) else {
return; return;
} };
if let Some(position) = spiral.as_mut().unwrap().next() { if let Some(position) = spiral.next() {
let pixel_position = position.to_pixel_coordinates((0.2, 0.2)); let pixel_position = position.to_pixel_coordinates((0.2, 0.2));
commands.spawn((get_type(pixel_position, &noise.unwrap()), position as TilePosition)); commands.spawn((get_type(pixel_position, &noise), position as TilePosition));
} else { } else {
end_map_event.send(EndMapGeneration); end_map_event.send(EndMapGeneration);
*noise = None; *local_noise = None;
*spiral = None; *local_spiral = None;
} }
} }
CoCo_Sol marked this conversation as resolved Outdated

Why don't you use HexPosition here?

Why don't you use HexPosition here?

because is not a hex position in a hex grid but a position in orthogonal grid

because is not a hex position in a hex grid but a position in orthogonal grid

You need to change the name of the function or take an HexPosition and convert it in the function, because it can be confusing that you use "tile" to describe the orthogonal position of an HexPosition

You need to change the name of the function or take an HexPosition and convert it in the function, because it can be confusing that you use "tile" to describe the orthogonal position of an HexPosition

you are right

you are right
CoCo_Sol marked this conversation as resolved
Review

This should be in the get_type function and the value shouldn't be hard coded

This should be in the get_type function and the value shouldn't be hard coded