test turn
This commit is contained in:
parent
0aa3cdd5cd
commit
2f1b6e9152
3 changed files with 84 additions and 84 deletions
53
src/turns.rs
53
src/turns.rs
|
|
@ -16,19 +16,19 @@ impl Plugin for TurnSystemPlugin {
|
|||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnBusy(bool);
|
||||
pub struct TurnBusy(pub bool);
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnPreEffect;
|
||||
pub struct TurnPreEffect;
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnUnit;
|
||||
pub struct TurnUnit;
|
||||
|
||||
#[derive(Component)]
|
||||
struct TurnPostEffect;
|
||||
pub struct TurnPostEffect;
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
||||
enum TurnState {
|
||||
pub enum TurnState {
|
||||
#[default]
|
||||
Turn,
|
||||
PreEffectProcess,
|
||||
|
|
@ -51,11 +51,14 @@ fn post_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPostE
|
|||
commands.entity(effect).insert(TurnBusy(false));
|
||||
}
|
||||
}
|
||||
fn process_busy_turnables(
|
||||
mut commands: Commands,
|
||||
query: Query<(Entity, &TurnBusy)>,
|
||||
state: Res<State<TurnState>>,
|
||||
) {
|
||||
|
||||
pub fn try_confirm_turn(mut commands: Commands, turn_state: Res<State<TurnState>>) {
|
||||
if let TurnState::Turn = turn_state.get() {
|
||||
commands.set_state(TurnState::PreEffectProcess);
|
||||
}
|
||||
}
|
||||
|
||||
fn process_busy_turnables(mut commands: Commands, query: Query<(Entity, &TurnBusy)>) {
|
||||
let mut advance_flag: bool = true;
|
||||
for (turnable, component) in query {
|
||||
if component.0 {
|
||||
|
|
@ -66,19 +69,23 @@ fn process_busy_turnables(
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
commands.run_system_cached(try_advance);
|
||||
}
|
||||
}
|
||||
|
||||
fn try_advance(mut commands: Commands, state: Res<State<TurnState>>) {
|
||||
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