generated from tipragot/rust
Adding a map creation plugin #57
|
@ -28,7 +28,7 @@ pub struct StartMapGeneration {
|
||||||
pub seed: u32,
|
pub seed: u32,
|
||||||
|
|
||||||
/// The radius of the map.
|
/// The radius of the map.
|
||||||
pub radius: usize,
|
pub radius: u16,
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// An event send when the map is generated.
|
/// An event send when the map is generated.
|
||||||
|
@ -41,12 +41,12 @@ fn generate_map(
|
||||||
mut end_map_event: EventWriter<EndMapGeneration>,
|
mut end_map_event: EventWriter<EndMapGeneration>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut noise: Local<Option<Perlin>>,
|
mut noise: Local<Option<Perlin>>,
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
tipragot
commented
Perlin isn't a function Perlin isn't a function
|
|||||||
mut map_iterator: Local<Option<HexSpiral<isize>>>,
|
mut map_iterator: Local<Option<HexSpiral<i32>>>,
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
tipragot
commented
Isize will not be great to use for networking because it's length depend on the system that runs the program. 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.
CoCo_Sol
commented
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 ?
tipragot
commented
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
CoCo_Sol
commented
ok, you've convinced me ok, you've convinced me
|
|||||||
) {
|
) {
|
||||||
// Handle map generation events.
|
// Handle map generation events.
|
||||||
for event in event.read() {
|
for event in event.read() {
|
||||||
*noise = Some(Perlin::new(event.seed));
|
*noise = Some(Perlin::new(event.seed));
|
||||||
*map_iterator = Some(HexPosition(0, 0).spiral(event.radius));
|
*map_iterator = Some(HexPosition(0, 0).spiral(event.radius as usize));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
|
if let (Some(perlin), Some(spiral)) = (noise.as_ref(), map_iterator.as_mut()) {
|
||||||
CoCo_Sol marked this conversation as resolved
Outdated
tipragot
commented
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.
CoCo_Sol
commented
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
tipragot
commented
No because you do an early return No because you do an early return
CoCo_Sol
commented
I have to write an unwrap so ? I have to write an unwrap so ?
tipragot
commented
No, an let else No, an let else
|
|||||||
|
|
Loading…
Reference in a new issue
Put an UPPERCASE "s"