mirror of
https://github.com/kristoferssolo/hexlab.git
synced 2026-02-04 06:22:06 +00:00
feat(bevy): add component feature
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::{EdgeDirection, Hex};
|
||||
use rand::{seq::SliceRandom, thread_rng, Rng, RngCore, SeedableRng};
|
||||
use rand_chacha::ChaCha8Rng;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::HexMaze;
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
pub enum GeneratorType {
|
||||
#[default]
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
ops::{Deref, DerefMut},
|
||||
};
|
||||
|
||||
use hexx::{EdgeDirection, Hex};
|
||||
|
||||
use super::{HexTile, Walls};
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::utils::HashMap;
|
||||
use hexx::{EdgeDirection, Hex};
|
||||
#[cfg(not(feature = "bevy_reflect"))]
|
||||
use std::collections::HashMap;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
|
||||
/// Represents a hexagonal maze with tiles and walls
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct HexMaze(HashMap<Hex, HexTile>);
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
use std::fmt::Display;
|
||||
|
||||
use hexx::Hex;
|
||||
|
||||
#[cfg(feature = "bevy")]
|
||||
use hexx::HexLayout;
|
||||
|
||||
use super::Walls;
|
||||
#[cfg(feature = "bevy")]
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::Hex;
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use hexx::HexLayout;
|
||||
use std::fmt::Display;
|
||||
|
||||
/// Represents a single hexagonal tile in the maze
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[cfg_attr(feature = "bevy", derive(Reflect, Component))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Default, PartialEq, Eq)]
|
||||
pub struct HexTile {
|
||||
@@ -43,14 +41,14 @@ impl HexTile {
|
||||
self.pos
|
||||
}
|
||||
|
||||
#[cfg(feature = "bevy")]
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn to_vec2(&self, layout: &HexLayout) -> Vec2 {
|
||||
layout.hex_to_world_pos(self.pos)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bevy")]
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn to_vec3(&self, layout: &HexLayout) -> Vec3 {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#[cfg(feature = "bevy")]
|
||||
use bevy::prelude::{Component, Reflect, ReflectComponent};
|
||||
#[cfg(feature = "bevy_reflect")]
|
||||
use bevy::prelude::*;
|
||||
use hexx::EdgeDirection;
|
||||
|
||||
/// A bit-flag representation of walls in a hexagonal tile.
|
||||
@@ -43,9 +43,10 @@ use hexx::EdgeDirection;
|
||||
/// assert!(!walls.contains(EdgeDirection::FLAT_SOUTH));
|
||||
/// ```
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "bevy", derive(Reflect, Component))]
|
||||
#[cfg_attr(feature = "bevy_reflect", derive(Reflect))]
|
||||
#[cfg_attr(feature = "bevy", derive(Component))]
|
||||
#[cfg_attr(feature = "bevy", reflect(Component))]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Walls(u8);
|
||||
|
||||
impl Walls {
|
||||
|
||||
Reference in New Issue
Block a user