generated from tipragot/rust
Adding a map creation plugin #57
No reviewers
Labels
No labels
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Fix
Kind/Security
Kind/Testing
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: fish-cannard/border-wars#57
Loading…
Reference in a new issue
No description provided.
Delete branch "map-generation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
closes: #26
The system needs to clean the last generated map, and I think it will be usefull to add an event to tell when the generation is ended.
@ -0,0 +28,4 @@
pub radius: usize,
}
/// spawns the tiles if the event is received.
Put an UPPERCASE "s"
@ -0,0 +33,4 @@
/// An event send when the map is generated.
#[derive(Event)]
pub struct EndMapGenerationEvent;
You should follow the bevy convention. Events in bevy doen't finish with "Event".
@ -0,0 +23,4 @@
/// An event to trigger the generation of the map.
#[derive(Event)]
pub struct MapGeneration {
If the End event start with "End" why this don't start with "Start" ?
@ -0,0 +41,4 @@
mut end_map_event: EventWriter<EndMapGeneration>,
mut commands: Commands,
mut noise: Local<Option<Perlin>>,
mut map_iterator: Local<Option<HexSpiral<isize>>>,
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 ?
You will use it every time you want to make a Query on the HexPosition
ok, you've convinced me
@ -0,0 +49,4 @@
*map_iterator = Some(HexPosition(0, 0).spiral(event.radius));
}
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
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
No because you do an early return
I have to write an unwrap so ?
No, an let else
@ -0,0 +62,4 @@
}
/// Returns the type of the tile at the given position with the given noise.
fn get_type_tile(position: (f32, f32), noise: &Perlin) -> Tile {
Why don't you use HexPosition here?
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 are right
@ -0,0 +71,4 @@
}
}
/// Despawns the tiles if the event : [EndMapGenerationEvent] is received.
This comment is wrong.
@ -0,0 +62,4 @@
// If the map is generated, we send [EndMapGeneration] and set the local
// variables to None.
if let Some(position) = spiral.next() {
let pixel_position = position.to_pixel_coordinates() * 0.2;
This should be in the get_type function and the value shouldn't be hard coded
@ -0,0 +72,4 @@
}
/// Returns the type of the position with the given noise.
fn get_type(position: Vec2, noise: &Perlin) -> Tile {
I still think you should take an HexPosition, this will be simpler and will make this function simpler to use.
@ -0,0 +81,4 @@
}
}
/// Despawns the tiles if the event : [StartMapGeneration] is received.
What this ":" doing here ?
@ -0,0 +40,4 @@
/// Generate each tiles of the map if the [StartMapGeneration] is received.
///
/// The map is generated using the [Perlin] noise function and the [HexSpiral].
Perlin isn't a function
@ -0,0 +74,4 @@
}
/// Returns the type of the [HexPosition] with the given noise.
fn get_type_tile(position: HexPosition<i32>, noise: &Perlin) -> Tile {
get_tile_type
@ -0,0 +75,4 @@
/// Returns the type of the [HexPosition] with the given noise.
fn get_tile_type(position: HexPosition<i32>, noise: &Perlin) -> Tile {
let pixel_position = position.to_pixel_coordinates() / MAP_GENERATION_ZOOM;
This is not a Zoom, it is a Scale