diff --git a/Cargo.toml b/Cargo.toml index d006f1e..bc5f4fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" edition = "2024" [dependencies] -bevy = "0.18.0" +bevy = { version = "0.18.0"} diff --git a/assets/music/main.mp3 b/assets/music/main.mp3 deleted file mode 100644 index 0783846..0000000 Binary files a/assets/music/main.mp3 and /dev/null differ diff --git a/src/main.rs b/src/main.rs index e7a11a9..ee56903 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,9 @@ +use bevy::prelude::*; + +mod turn_system; + fn main() { - println!("Hello, world!"); + App::new() + .add_plugins((DefaultPlugins, turn_system::TurnSystemPlugin)) + .run(); } diff --git a/src/turn_system.rs b/src/turn_system.rs new file mode 100644 index 0000000..cce2eef --- /dev/null +++ b/src/turn_system.rs @@ -0,0 +1,81 @@ +use bevy::prelude::*; + +pub struct TurnSystemPlugin; + +impl Plugin for TurnSystemPlugin { + fn build(&self, app: &mut App) { + app.init_state::() + .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>) { + for effect in query { + commands.entity(effect).insert(TurnBusy(false)); + } +} +fn unit_setup(mut commands: Commands, query: Query>) { + for unit in query { + commands.entity(unit).insert(TurnBusy(false)); + } +} +fn post_effect_setup(mut commands: Commands, query: Query>) { + for effect in query { + commands.entity(effect).insert(TurnBusy(false)); + } +} +fn process_busy_turnables( + mut commands: Commands, + query: Query<(Entity, &TurnBusy)>, + state: Res>, +) { + let mut advance_flag: bool = true; + for (turnable, component) in query { + if component.0 { + commands.entity(turnable).remove::(); + } 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); + } + } + } +}