turn system
This commit is contained in:
parent
e354af68fd
commit
ef268aebef
4 changed files with 89 additions and 2 deletions
|
|
@ -4,4 +4,4 @@ version = "0.1.0"
|
|||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.18.0"
|
||||
bevy = { version = "0.18.0"}
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,3 +1,9 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
mod turn_system;
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins, turn_system::TurnSystemPlugin))
|
||||
.run();
|
||||
}
|
||||
|
|
|
|||
81
src/turn_system.rs
Normal file
81
src/turn_system.rs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
pub struct TurnSystemPlugin;
|
||||
|
||||
impl Plugin for TurnSystemPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_state::<TurnState>()
|
||||
.add_systems(OnEnter(TurnState::PreEffectProcess), pre_effect_setup)
|
||||
.add_systems(OnEnter(TurnState::UnitProcess), unit_setup)
|
||||
.add_systems(OnEnter(TurnState::PostEffectProcess), post_effect_setup)
|
||||
.add_systems(Update, process_busy_turnables);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnBusy(bool);
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnPreEffect;
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnUnit;
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnPostEffect;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
||||
enum TurnState {
|
||||
#[default]
|
||||
Turn,
|
||||
PreEffectProcess,
|
||||
UnitProcess,
|
||||
PostEffectProcess,
|
||||
}
|
||||
|
||||
fn pre_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPreEffect>>) {
|
||||
for effect in query {
|
||||
commands.entity(effect).insert(TurnBusy(false));
|
||||
}
|
||||
}
|
||||
fn unit_setup(mut commands: Commands, query: Query<Entity, With<TurnUnit>>) {
|
||||
for unit in query {
|
||||
commands.entity(unit).insert(TurnBusy(false));
|
||||
}
|
||||
}
|
||||
fn post_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPostEffect>>) {
|
||||
for effect in query {
|
||||
commands.entity(effect).insert(TurnBusy(false));
|
||||
}
|
||||
}
|
||||
fn process_busy_turnables(
|
||||
mut commands: Commands,
|
||||
query: Query<(Entity, &TurnBusy)>,
|
||||
state: Res<State<TurnState>>,
|
||||
) {
|
||||
let mut advance_flag: bool = true;
|
||||
for (turnable, component) in query {
|
||||
if component.0 {
|
||||
commands.entity(turnable).remove::<TurnBusy>();
|
||||
} else {
|
||||
advance_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
if advance_flag {
|
||||
match state.get() {
|
||||
TurnState::Turn => {
|
||||
commands.set_state(TurnState::PreEffectProcess);
|
||||
}
|
||||
TurnState::PreEffectProcess => {
|
||||
commands.set_state(TurnState::UnitProcess);
|
||||
}
|
||||
TurnState::UnitProcess => {
|
||||
commands.set_state(TurnState::PostEffectProcess);
|
||||
}
|
||||
TurnState::PostEffectProcess => {
|
||||
commands.set_state(TurnState::Turn);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue