Implement coords collection + footprint neightbors
Some checks failed
Rust / build (push) Failing after 4s
Some checks failed
Rust / build (push) Failing after 4s
This commit is contained in:
@@ -1,32 +1,39 @@
|
|||||||
use bevy::math::{IVec2, Vec3Swizzles};
|
use bevy::math::{IVec2, Vec3Swizzles};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use shared::coords::CoordsCollection;
|
||||||
use world_generation::hex_utils::HexCoord;
|
use world_generation::hex_utils::HexCoord;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
pub struct BuildingFootprint {
|
pub struct BuildingFootprint
|
||||||
|
{
|
||||||
pub footprint: Vec<IVec2>,
|
pub footprint: Vec<IVec2>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BuildingFootprint {
|
impl BuildingFootprint
|
||||||
pub fn get_footprint(&self, center: &HexCoord) -> Vec<HexCoord> {
|
{
|
||||||
let c = center.hex.xy();
|
pub fn get_footprint(&self, position: &HexCoord) -> CoordsCollection
|
||||||
return self.footprint.iter().map(|p| HexCoord::from_hex(*p + c)).collect();
|
{
|
||||||
|
CoordsCollection::from_points(self.footprint.clone()).with_translation(position)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_footprint_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
|
pub fn get_neighbors(&self, position: &HexCoord) -> CoordsCollection
|
||||||
let c = center.hex.xy();
|
{
|
||||||
return self
|
let n_points: Vec<IVec2> = self
|
||||||
.footprint
|
.footprint
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| HexCoord::from_hex(*p + c).rotate_around(center, rotation))
|
.flat_map(|p| HexCoord::from_hex(*p).get_neighbors())
|
||||||
|
.map(|c| c.hex.xy())
|
||||||
|
.filter(|p| !self.footprint.contains(p))
|
||||||
.collect();
|
.collect();
|
||||||
|
let mut out_points: Vec<IVec2> = Vec::with_capacity(n_points.len());
|
||||||
|
for p in n_points
|
||||||
|
{
|
||||||
|
if out_points.contains(&p)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
out_points.push(p);
|
||||||
pub fn get_neighbors(&self, center: &HexCoord) -> Vec<HexCoord> {
|
|
||||||
todo!()
|
|
||||||
}
|
}
|
||||||
|
return CoordsCollection::from_points(out_points).with_translation(position);
|
||||||
pub fn get_neighbors_rotated(&self, center: &HexCoord, rotation: i32) -> Vec<HexCoord> {
|
|
||||||
todo!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use bevy::reflect::Reflect;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub mod building;
|
pub mod building;
|
||||||
|
pub mod coords;
|
||||||
pub mod despawn;
|
pub mod despawn;
|
||||||
pub mod events;
|
pub mod events;
|
||||||
pub mod identifiers;
|
pub mod identifiers;
|
||||||
@@ -14,7 +15,8 @@ pub mod tags;
|
|||||||
// pub mod component_defination;
|
// pub mod component_defination;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum Tier {
|
pub enum Tier
|
||||||
|
{
|
||||||
Zero,
|
Zero,
|
||||||
One,
|
One,
|
||||||
Two,
|
Two,
|
||||||
@@ -23,7 +25,8 @@ pub enum Tier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
#[derive(Serialize, Deserialize, Debug, Reflect)]
|
||||||
pub enum StatusEffect {
|
pub enum StatusEffect
|
||||||
|
{
|
||||||
UnitRange(f32),
|
UnitRange(f32),
|
||||||
UnitAttack(f32),
|
UnitAttack(f32),
|
||||||
UnitHealth(f32),
|
UnitHealth(f32),
|
||||||
|
|||||||
Reference in New Issue
Block a user