2 Commits

Author SHA1 Message Date
c39b6d2120 Add a const OCTAGON and use it in map.rs
We could made a bunch of pre-built Card constatns for all the basic
shapes. That way we can `Card::OCTAGON` to create one, instead of typing
out the whole function call.
2025-08-27 12:57:02 -05:00
c0ed58e890 Give the Card an associated fn new()
So that we don't have to keep doing the `{ cells: ... ..default() }`
thing.
2025-08-27 12:52:58 -05:00
2 changed files with 19 additions and 14 deletions

View File

@@ -82,6 +82,24 @@ pub struct Card {
} }
impl Card { impl Card {
/// Create a new card from the given Cell array
pub const fn new(cells: [Cell; 9]) -> Self {
Self {
cells,
nw: false,
n: false,
ne: false,
w: false,
e: false,
sw: false,
s: false,
se: false,
}
}
// TODO: The other shapes
pub const OCTAGON: Self = Self::new(OCTAGON);
/// Produces a new card by stacking another on top of this one. /// Produces a new card by stacking another on top of this one.
pub fn merge(self, top: Self) -> (Self, Option<Self>) { pub fn merge(self, top: Self) -> (Self, Option<Self>) {
let mut new_card = Self::default(); let mut new_card = Self::default();

View File

@@ -11,20 +11,7 @@ pub fn setup_test_tilemap(mut commands: Commands, assets: Res<AssetLibrary>) {
let map_size = TilemapSize { x: 9, y: 9 }; let map_size = TilemapSize { x: 9, y: 9 };
let mut tile_storage = TileStorage::empty(map_size); let mut tile_storage = TileStorage::empty(map_size);
let card = Card { let card = Card::OCTAGON;
cells: [
Cell::NW,
Cell::Filled,
Cell::NE,
Cell::Filled,
Cell::Filled,
Cell::Filled,
Cell::SW,
Cell::Filled,
Cell::SE,
],
..Default::default()
};
add_card_to_tilemap( add_card_to_tilemap(
&card, &card,