From 09a95bccfc227ed49342791a153cf50cbaa47f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Lescaudey=20de=20Maneville?= Date: Thu, 11 Jul 2024 12:54:51 +0200 Subject: [PATCH] Bevy 0.14 (#24) --- .github/workflows/rust.yml | 14 +++---- CHANGELOG.md | 6 +++ Cargo.toml | 16 +++++--- README.md | 7 ++-- examples/2d_cyclic_colors.rs | 9 +++-- examples/2d_game_of_life.rs | 2 +- examples/2d_immigration_game.rs | 2 +- examples/2d_rainbow_game.rs | 2 +- examples/2d_rock_paper_scissor.rs | 10 ++--- src/components/cell/hexagon_2d_cell.rs | 5 ++- src/components/cell/moore_2d_cell.rs | 5 ++- src/components/cell/moore_3d_cell.rs | 5 ++- src/components/cell/neumann_2d_cell.rs | 5 ++- src/components/cell/neumann_3d_cell.rs | 5 ++- src/components/cell_state/conway_state.rs | 7 ++-- src/components/cell_state/conway_state_3d.rs | 7 ++-- .../cell_state/cyclic_color_state.rs | 39 +++++++------------ .../cell_state/immigration_state.rs | 16 ++++++-- src/components/cell_state/mod.rs | 2 +- src/components/cell_state/rainbow_state.rs | 9 +++-- .../cell_state/wire_world_cell_state.rs | 16 +++++--- src/lib.rs | 15 ++++--- 22 files changed, 113 insertions(+), 91 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 23feee3..99c349e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: build run: cargo build --verbose @@ -21,7 +21,7 @@ jobs: build_features: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: all features run: cargo build --verbose --all-features @@ -39,7 +39,7 @@ jobs: build_examples: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: build 2d game of life run: cargo clippy --all-features --example 2d_game_of_life @@ -57,7 +57,7 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: test run: cargo test --tests --all-features @@ -65,7 +65,7 @@ jobs: fmt: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly with: components: "rustfmt" @@ -75,7 +75,7 @@ jobs: clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: Cargo clippy installation run: rustup component add clippy @@ -85,7 +85,7 @@ jobs: rustdoc: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable - name: rustdoc run: cargo rustdoc --all-features -- -D warnings diff --git a/CHANGELOG.md b/CHANGELOG.md index 29d6023..15ed934 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## [Unreleased] +* Bevy 0.14 +* (**BREAKING**) `CyclicColorState` now takes a `const N: usize` generic instead +of hard coded `9` +* `2d_cyclic_colors` example is now in grayscale +* Reflection is now optional through `bevy_reflect` feature gate + ## 0.9.0 * Added rustfmt config (#19) diff --git a/Cargo.toml b/Cargo.toml index 99935e8..bbfe6c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,32 +14,38 @@ categories = ["game-engines", "game-development"] resolver = "2" [features] -default = ["2D"] +default = ["2D", "bevy_reflect"] 2D = [] 3D = [] -auto-coloring = ["bevy/bevy_sprite"] +auto-coloring = ["bevy/bevy_sprite", "bevy/bevy_color"] +bevy_reflect = ["dep:bevy_reflect"] [dependencies.bevy] -version = "0.13" +version = "0.14" default-features = false features = ["bevy_render"] +[dependencies.bevy_reflect] +version = "0.14" +optional = true + [dev-dependencies] rand = "0.8" [dev-dependencies.bevy] -version = "0.13" +version = "0.14" features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", "bevy_pbr", + "bevy_color", "bevy_render", "bevy_sprite", "png", "x11", "tonemapping_luts", - "multi-threaded", + "multi_threaded", # Faster compilation "dynamic_linking" ] diff --git a/README.md b/README.md index 202a2db..a6690d9 100644 --- a/README.md +++ b/README.md @@ -100,10 +100,9 @@ No feature is required for the plugin to work and the main traits `Cell` and * plugin presets: `GameOfLife3dPlugin`, `ImmigrationGame3dPlugin`, `RainbowGame3dPlugin`, `WireWorld3dPlugin`, `CyclicAutomaton3dPlugin` * `auto-coloring` (Example or debug purpose): - * Enables `CellStateMaterials` resource to contain material handles - * The `CellState` type now requires to build a `CellStateMaterials` - * All `CellState` components with materials will be colored according to - their type. + * The `CellState` trait now requires a `color` method +* `bevy_reflect` (enabled by default): Enable support for reflection for + common types ## Disclaimer diff --git a/examples/2d_cyclic_colors.rs b/examples/2d_cyclic_colors.rs index c7e607b..521f431 100644 --- a/examples/2d_cyclic_colors.rs +++ b/examples/2d_cyclic_colors.rs @@ -2,6 +2,8 @@ use bevy::prelude::*; use bevy_life::{CyclicColorCellState, CyclicColors2dPlugin, MooreCell2d, SimulationBatch}; use rand::Rng; +const N: usize = 9; + fn main() { App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { @@ -12,7 +14,7 @@ fn main() { }), ..default() })) - .add_plugins(CyclicColors2dPlugin::new().with_time_step(0.05)) + .add_plugins(CyclicColors2dPlugin::::new().with_time_step(0.05)) .insert_resource(SimulationBatch) .add_systems(Startup, (setup_camera, setup_map)) .run(); @@ -32,7 +34,6 @@ fn spawn_map(commands: &mut Commands) { let (size_x, size_y) = (300, 200); let sprite_size = 4.; - let max_index = CyclicColorCellState::max_index(); commands .spawn(SpatialBundle::from_transform(Transform::from_xyz( -(size_x as f32 * sprite_size) / 2., @@ -42,8 +43,8 @@ fn spawn_map(commands: &mut Commands) { .with_children(|builder| { for y in 0..=size_y { for x in 0..=size_x { - let color_index = rng.gen_range(0..max_index); - let state = CyclicColorCellState(color_index); + let color_index = rng.gen_range(0..N); + let state = CyclicColorCellState::(color_index); builder.spawn(( SpriteBundle { sprite: Sprite { diff --git a/examples/2d_game_of_life.rs b/examples/2d_game_of_life.rs index 87217ae..2274161 100644 --- a/examples/2d_game_of_life.rs +++ b/examples/2d_game_of_life.rs @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) { let mut rng = rand::thread_rng(); let (size_x, size_y) = (600, 400); let sprite_size = 2.; - let color = Color::rgba(0., 0., 0., 0.); + let color = Color::srgba(0., 0., 0., 0.); commands .spawn(SpatialBundle::from_transform(Transform::from_xyz( diff --git a/examples/2d_immigration_game.rs b/examples/2d_immigration_game.rs index 0953c43..ef31c54 100644 --- a/examples/2d_immigration_game.rs +++ b/examples/2d_immigration_game.rs @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) { let mut rng = rand::thread_rng(); let (size_x, size_y) = (600, 400); let sprite_size = 2.; - let color = Color::rgba(0., 0., 0., 0.); + let color = Color::srgba(0., 0., 0., 0.); commands .spawn(SpatialBundle::from_transform(Transform::from_xyz( diff --git a/examples/2d_rainbow_game.rs b/examples/2d_rainbow_game.rs index e7d3d6d..1c83a29 100644 --- a/examples/2d_rainbow_game.rs +++ b/examples/2d_rainbow_game.rs @@ -31,7 +31,7 @@ fn spawn_map(commands: &mut Commands) { let mut rng = rand::thread_rng(); let (size_x, size_y) = (600, 400); let sprite_size = 2.; - let color = Color::rgba(1., 0., 0., 1.); + let color = Color::srgba(1., 0., 0., 1.); commands .spawn(SpatialBundle::from_transform(Transform::from_xyz( diff --git a/examples/2d_rock_paper_scissor.rs b/examples/2d_rock_paper_scissor.rs index 439ccc3..ce80666 100644 --- a/examples/2d_rock_paper_scissor.rs +++ b/examples/2d_rock_paper_scissor.rs @@ -1,4 +1,4 @@ -use bevy::prelude::*; +use bevy::{color::palettes::css::*, prelude::*}; use bevy_life::{CellState, CellularAutomatonPlugin, MooreCell2d, SimulationBatch}; use rand::Rng; @@ -61,7 +61,7 @@ fn spawn_map(commands: &mut Commands) { let mut rng = rand::thread_rng(); let (size_x, size_y) = (300, 200); let sprite_size = 4.; - let color = Color::rgba(0., 0., 0., 0.); + let color = Color::srgba(0., 0., 0., 0.); commands .spawn(SpatialBundle::from_transform(Transform::from_xyz( @@ -106,8 +106,8 @@ pub fn color_sprites( query .par_iter_mut() .for_each(|(state, mut sprite)| match state { - RockPaperScissor::Rock => sprite.color = Color::BLUE, - RockPaperScissor::Paper => sprite.color = Color::BEIGE, - RockPaperScissor::Scissor => sprite.color = Color::RED, + RockPaperScissor::Rock => sprite.color = Color::Srgba(BLUE), + RockPaperScissor::Paper => sprite.color = Color::Srgba(BEIGE), + RockPaperScissor::Scissor => sprite.color = Color::Srgba(RED), }); } diff --git a/src/components/cell/hexagon_2d_cell.rs b/src/components/cell/hexagon_2d_cell.rs index f178221..715ad7a 100644 --- a/src/components/cell/hexagon_2d_cell.rs +++ b/src/components/cell/hexagon_2d_cell.rs @@ -1,5 +1,5 @@ use crate::components::Cell; -use bevy::prelude::{Component, IVec3, Reflect}; +use bevy::prelude::{Component, IVec3}; use std::ops::Deref; const NEIGHBOR_COORDINATES: [IVec3; 6] = [ @@ -34,7 +34,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 6] = [ /// \_____/ /// /// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct HexagonCell2d { /// The 2D cell coordinates pub coords: IVec3, diff --git a/src/components/cell/moore_2d_cell.rs b/src/components/cell/moore_2d_cell.rs index 4febfcf..4f2c1c3 100644 --- a/src/components/cell/moore_2d_cell.rs +++ b/src/components/cell/moore_2d_cell.rs @@ -1,5 +1,5 @@ use crate::components::Cell; -use bevy::prelude::{Component, IVec2, Reflect}; +use bevy::prelude::{Component, IVec2}; use std::ops::Deref; const NEIGHBOR_COORDINATES: [IVec2; 8] = [ @@ -40,7 +40,8 @@ const NEIGHBOR_COORDINATES: [IVec2; 8] = [ /// ``` /// /// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct MooreCell2d { /// The 2D cell coordinates pub coords: IVec2, diff --git a/src/components/cell/moore_3d_cell.rs b/src/components/cell/moore_3d_cell.rs index 217af94..64b762f 100644 --- a/src/components/cell/moore_3d_cell.rs +++ b/src/components/cell/moore_3d_cell.rs @@ -1,5 +1,5 @@ use crate::components::Cell; -use bevy::prelude::{Component, IVec3, Reflect}; +use bevy::prelude::{Component, IVec3}; use std::ops::Deref; const NEIGHBOR_COORDINATES: [IVec3; 26] = [ @@ -66,7 +66,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 26] = [ /// [Moore] 3D cell, it has 26 neighbors and uses `IVec3` coordinates /// /// [Moore]: https://en.wikipedia.org/wiki/Moore_neighborhood -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct MooreCell3d { /// The 3D cell coordinates pub coords: IVec3, diff --git a/src/components/cell/neumann_2d_cell.rs b/src/components/cell/neumann_2d_cell.rs index 6cac38a..e3e35d1 100644 --- a/src/components/cell/neumann_2d_cell.rs +++ b/src/components/cell/neumann_2d_cell.rs @@ -1,5 +1,5 @@ use crate::components::Cell; -use bevy::prelude::{Component, IVec2, Reflect}; +use bevy::prelude::{Component, IVec2}; use std::ops::Deref; const NEIGHBOR_COORDINATES: [IVec2; 4] = [ @@ -31,7 +31,8 @@ const NEIGHBOR_COORDINATES: [IVec2; 4] = [ /// +-------+ /// ``` /// [Neumann]: https://en.wikipedia.org/wiki/Von_Neumann_neighborhood -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct NeumannCell2d { /// The 2D cell coordinates pub coords: IVec2, diff --git a/src/components/cell/neumann_3d_cell.rs b/src/components/cell/neumann_3d_cell.rs index 054fdc5..8f2e3d5 100644 --- a/src/components/cell/neumann_3d_cell.rs +++ b/src/components/cell/neumann_3d_cell.rs @@ -1,5 +1,5 @@ use crate::components::Cell; -use bevy::prelude::{Component, IVec3, Reflect}; +use bevy::prelude::{Component, IVec3}; use std::ops::Deref; const NEIGHBOR_COORDINATES: [IVec3; 6] = [ @@ -27,7 +27,8 @@ const NEIGHBOR_COORDINATES: [IVec3; 6] = [ /// coordinates /// /// [Neumann]: https://en.wikipedia.org/wiki/Von_Neumann_neighborhood -#[derive(Debug, Clone, Component, Reflect)] +#[derive(Debug, Clone, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct NeumannCell3d { /// The 3D cell coordinates pub coords: IVec3, diff --git a/src/components/cell_state/conway_state.rs b/src/components/cell_state/conway_state.rs index 3e2c847..85d3c04 100644 --- a/src/components/cell_state/conway_state.rs +++ b/src/components/cell_state/conway_state.rs @@ -1,7 +1,7 @@ use crate::components::CellState; -use bevy::prelude::{Component, Reflect}; #[cfg(feature = "auto-coloring")] -use bevy::render::color::Color; +use bevy::prelude::Color; +use bevy::prelude::Component; use std::ops::{Deref, DerefMut}; /// Classic cellular automation state and rules following Conway's game of life @@ -17,7 +17,8 @@ use std::ops::{Deref, DerefMut}; /// if by reproduction. /// /// A dead cell is `false`, a live cell is `true` -#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component, Reflect)] +#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct ConwayCellState(pub bool); impl CellState for ConwayCellState { diff --git a/src/components/cell_state/conway_state_3d.rs b/src/components/cell_state/conway_state_3d.rs index 4638363..2f5bcaf 100644 --- a/src/components/cell_state/conway_state_3d.rs +++ b/src/components/cell_state/conway_state_3d.rs @@ -1,7 +1,7 @@ use crate::components::CellState; -use bevy::prelude::{Component, Reflect}; #[cfg(feature = "auto-coloring")] -use bevy::render::color::Color; +use bevy::prelude::Color; +use bevy::prelude::Component; use std::ops::{Deref, DerefMut}; /// Classic cellular automation state and rules following Conway's game of life @@ -17,7 +17,8 @@ use std::ops::{Deref, DerefMut}; /// by reproduction. /// /// A dead cell is `false`, a live cell is `true` -#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component, Reflect)] +#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub struct ConwayCell4555State(pub bool); impl CellState for ConwayCell4555State { diff --git a/src/components/cell_state/cyclic_color_state.rs b/src/components/cell_state/cyclic_color_state.rs index f52b2a2..91d1a55 100644 --- a/src/components/cell_state/cyclic_color_state.rs +++ b/src/components/cell_state/cyclic_color_state.rs @@ -1,37 +1,26 @@ use crate::CellState; -use bevy::prelude::{Color, Component, Reflect}; - -const CYCLIC_COLORS: [Color; 9] = [ - Color::BLUE, - Color::CYAN, - Color::GREEN, - Color::LIME_GREEN, - Color::YELLOW, - Color::ORANGE, - Color::ORANGE_RED, - Color::RED, - Color::PURPLE, -]; +#[cfg(feature = "auto-coloring")] +use bevy::color::Color; +use bevy::prelude::Component; /// Basic cyclic cellular automaton state and rules. The rules are the /// following: /// /// > As with any cellular automaton, the cyclic cellular automaton consists of /// > a regular grid of cells in one or more dimensions. -/// > The cells can take on any of `n` states, ranging from `0`to `n − 1`. The +/// > The cells can take on any of `N` states, ranging from `0`to `N − 1`. The /// > first generation starts out with random states in each of the cells. /// > In each subsequent generation, if a cell has a neighboring cell whose /// > value is the successor of the cell's value, the cell is *consumed* and /// > takes on the succeeding value. /// > (Note that `0` is the successor of `n − 1`. -/// -/// For this type we use `9` for `n` and arbitrary colors. -#[derive(Debug, Copy, Clone, PartialEq, Eq, Component, Reflect, Default)] -pub struct CyclicColorCellState(pub usize); +#[derive(Debug, Copy, Clone, PartialEq, Eq, Component, Default)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] +pub struct CyclicColorCellState(pub usize); -impl CellState for CyclicColorCellState { +impl CellState for CyclicColorCellState { fn new_cell_state<'a>(&self, neighbor_cells: impl Iterator) -> Self { - let new_index = (self.0 + 1) % CYCLIC_COLORS.len(); + let new_index = (self.0 + 1) % N; for neighbor_cell in neighbor_cells { if neighbor_cell.0 == new_index { return *neighbor_cell; @@ -41,16 +30,18 @@ impl CellState for CyclicColorCellState { } #[cfg(feature = "auto-coloring")] + #[allow(clippy::cast_precision_loss)] fn color(&self) -> Option { - Some(CYCLIC_COLORS[self.0]) + let r = self.0 as f32 / N as f32; + Some(Color::srgb(r, r, r)) } } -impl CyclicColorCellState { - /// Return the available colors +impl CyclicColorCellState { + /// Return the available colors count #[must_use] #[inline] pub const fn max_index() -> usize { - CYCLIC_COLORS.len() + N } } diff --git a/src/components/cell_state/immigration_state.rs b/src/components/cell_state/immigration_state.rs index b7099c8..954cbbf 100644 --- a/src/components/cell_state/immigration_state.rs +++ b/src/components/cell_state/immigration_state.rs @@ -1,10 +1,14 @@ use crate::components::CellState; -use bevy::prelude::{Component, Reflect}; #[cfg(feature = "auto-coloring")] -use bevy::render::color::Color; +use bevy::color::{ + palettes::css::{AQUA, ORANGE}, + Color, +}; +use bevy::prelude::Component; use std::fmt::Debug; -#[derive(Debug, Copy, Clone, Eq, PartialEq, Component, Reflect)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] /// Classic cellular automation state and rules following Conway's game of life /// variation: The immigration game. /// @@ -54,7 +58,11 @@ impl CellState for ImmigrationCellState { fn color(&self) -> Option { match self { Self::Dead => None, - Self::Alive(b) => Some(if *b { Color::CYAN } else { Color::ORANGE }), + Self::Alive(b) => Some(if *b { + Color::Srgba(AQUA) + } else { + Color::Srgba(ORANGE) + }), } } } diff --git a/src/components/cell_state/mod.rs b/src/components/cell_state/mod.rs index 29206a5..e1f4f60 100644 --- a/src/components/cell_state/mod.rs +++ b/src/components/cell_state/mod.rs @@ -29,5 +29,5 @@ pub trait CellState: Component + Sized + Clone + PartialEq { #[cfg(feature = "auto-coloring")] /// Color of the state, to use with `auto-coloring` feature #[must_use] - fn color(&self) -> Option; + fn color(&self) -> Option; } diff --git a/src/components/cell_state/rainbow_state.rs b/src/components/cell_state/rainbow_state.rs index 411e4fa..4532458 100644 --- a/src/components/cell_state/rainbow_state.rs +++ b/src/components/cell_state/rainbow_state.rs @@ -1,10 +1,11 @@ use crate::components::CellState; -use bevy::prelude::{Component, Reflect}; #[cfg(feature = "auto-coloring")] -use bevy::render::color::Color; +use bevy::prelude::Color; +use bevy::prelude::Component; use std::fmt::Debug; -#[derive(Debug, Copy, Clone, PartialEq, Component, Reflect)] +#[derive(Debug, Copy, Clone, PartialEq, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] /// Classic cellular automation state and rules following Conway's game of life /// variation: The immigration game. /// @@ -47,7 +48,7 @@ impl CellState for RainbowCellState { fn color(&self) -> Option { match self { Self::Dead => None, - Self::Alive(v) => Some(Color::rgb(*v, *v, *v)), + Self::Alive(v) => Some(Color::srgb(*v, *v, *v)), } } } diff --git a/src/components/cell_state/wire_world_cell_state.rs b/src/components/cell_state/wire_world_cell_state.rs index 88aff72..2cc750e 100644 --- a/src/components/cell_state/wire_world_cell_state.rs +++ b/src/components/cell_state/wire_world_cell_state.rs @@ -1,7 +1,10 @@ use crate::components::CellState; -use bevy::prelude::{Component, Reflect}; #[cfg(feature = "auto-coloring")] -use bevy::render::color::Color; +use bevy::color::{ + palettes::css::{AQUA, GOLD, WHITE}, + Color, +}; +use bevy::prelude::Component; /// Wireworld is a cellular automaton that simulates electronic devices and /// logic gates by having cells represent electrons traveling across conductors. @@ -13,7 +16,8 @@ use bevy::render::color::Color; /// - Conductors (`Conductor`) become electron heads if exactly one or two /// neighboring cells are electron heads. Otherwise, they remain as /// conductors. -#[derive(Copy, Clone, Debug, Eq, PartialEq, Component, Reflect)] +#[derive(Copy, Clone, Debug, Eq, PartialEq, Component)] +#[cfg_attr(feature = "bevy_reflect", derive(bevy_reflect::Reflect))] pub enum WireWorldCellState { /// Conductor cell state Conductor, @@ -48,9 +52,9 @@ impl CellState for WireWorldCellState { #[cfg(feature = "auto-coloring")] fn color(&self) -> Option { Some(match self { - Self::Conductor => Color::GOLD, - Self::ElectronHead => Color::CYAN, - Self::ElectronTail => Color::WHITE, + Self::Conductor => Color::Srgba(GOLD), + Self::ElectronHead => Color::Srgba(AQUA), + Self::ElectronTail => Color::Srgba(WHITE), }) } } diff --git a/src/lib.rs b/src/lib.rs index b13a8dd..9628c4f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,10 +88,9 @@ //! * plugin presets: `GameOfLife3dPlugin`, `ImmigrationGame3dPlugin`, //! `RainbowGame3dPlugin`, `WireWorld3dPlugin`, `CyclicAutomaton3dPlugin` //! * `auto-coloring` (Example or debug purpose): -//! * Enables `CellStateMaterials` resource to contain material handles -//! * The `CellState` type now requires to build a `CellStateMaterials` -//! * All `CellState` components with materials will be colored according to -//! their type. +//! * The `CellState` trait now requires a `color` method +//! * `bevy_reflect` (enabled by default): Enable support for reflection for +//! common types //! //! ## Disclaimer //! @@ -164,13 +163,13 @@ pub type WireWorld3dPlugin = #[cfg(feature = "2D")] /// Cellular automaton plugin type for Colored Cyclic cellular automaton in 2D -pub type CyclicColors2dPlugin = - CellularAutomatonPlugin; +pub type CyclicColors2dPlugin = + CellularAutomatonPlugin>; #[cfg(feature = "3D")] /// Cellular automaton plugin type for Colored Cyclic cellular automaton in 3D -pub type CyclicColors3dPlugin = - CellularAutomatonPlugin; +pub type CyclicColors3dPlugin = + CellularAutomatonPlugin>; /// Generic Cellular Automaton plugin. It will register systems for the matching /// `Cell` and `CellState` types.