From c5da1191095d474199cea4d6fd20c1dd3d122404 Mon Sep 17 00:00:00 2001 From: Amatsugu Date: Fri, 13 Mar 2026 23:19:49 -0400 Subject: [PATCH] Implement coords collection + footprint neightbors --- game/shared/src/coords.rs | 69 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 game/shared/src/coords.rs diff --git a/game/shared/src/coords.rs b/game/shared/src/coords.rs new file mode 100644 index 0000000..45c0987 --- /dev/null +++ b/game/shared/src/coords.rs @@ -0,0 +1,69 @@ +use bevy::prelude::*; +use world_generation::hex_utils::HexCoord; + +#[derive(Default, Debug, Reflect)] +pub struct CoordsCollection +{ + points: Vec, + origin: IVec2, + translation: IVec2, + rotation: i32, +} + +impl CoordsCollection +{ + pub fn from_hex(coords: Vec) -> Self + { + CoordsCollection { + points: coords.iter().map(|c| c.hex.xy()).collect(), + ..default() + } + } + + pub fn from_points(points: Vec) -> Self + { + CoordsCollection { points, ..default() } + } + + pub fn with_translation(mut self, translation: &HexCoord) -> Self + { + self.translation = translation.hex.xy(); + return self; + } + + pub fn with_translation_vec(mut self, translation: IVec2) -> Self + { + self.translation = translation; + return self; + } + + pub fn with_origin(mut self, orign: &HexCoord) -> Self + { + self.origin = orign.hex.xy(); + return self; + } + + pub fn with_rotation(mut self, rotation: i32) -> Self + { + self.rotation = rotation; + return self; + } + + pub fn get_coords(&self) -> Vec + { + let center = HexCoord::from_hex(self.origin); + return self + .points + .iter() + .map(|p| HexCoord::from_hex(p + self.origin).rotate_around(¢er, self.rotation)) + .collect(); + } +} + +impl Into> for CoordsCollection +{ + fn into(self) -> Vec + { + self.get_coords() + } +}