turn debug

This commit is contained in:
Rendo 2026-01-30 23:05:54 +05:00
commit 007ddf56b1
3 changed files with 33 additions and 15 deletions

View file

@ -7,6 +7,7 @@ use crate::{
drag::{CardDropped, MousePosition}, drag::{CardDropped, MousePosition},
}, },
grid::Grid, grid::Grid,
turns::TurnUnit,
unit::UnitTextures, unit::UnitTextures,
}; };
@ -29,6 +30,7 @@ pub fn card_playing_system(
AnimatedTransform::identity(), AnimatedTransform::identity(),
Transform::from_translation(mouse_position.0), Transform::from_translation(mouse_position.0),
bundle, bundle,
TurnUnit,
)) ))
.id(); .id();
if grid.try_set(mouse_position.0.truncate(), unit) { if grid.try_set(mouse_position.0.truncate(), unit) {

View file

@ -2,6 +2,7 @@ use bevy::prelude::*;
use crate::buttons; use crate::buttons;
use crate::card; use crate::card;
use crate::turns::TurnState;
use crate::turns::try_confirm_turn; use crate::turns::try_confirm_turn;
const PANEL_BORDER: Color = Color::srgb_u8(36, 36, 143); const PANEL_BORDER: Color = Color::srgb_u8(36, 36, 143);
@ -13,10 +14,14 @@ pub struct DevToolsPlugin;
impl Plugin for DevToolsPlugin { impl Plugin for DevToolsPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
app.add_systems(Startup, setup_debug_menu); app.add_systems(Startup, setup_debug_menu)
.add_systems(Update, print_state);
} }
} }
#[derive(Component)]
struct TurnStateLabel;
fn setup_debug_menu(mut commands: Commands) { fn setup_debug_menu(mut commands: Commands) {
let root = commands let root = commands
.spawn(( .spawn((
@ -53,6 +58,14 @@ fn setup_debug_menu(mut commands: Commands) {
BorderColor::all(PANEL_BORDER), BorderColor::all(PANEL_BORDER),
BackgroundColor(PANEL_BACKGROUND), BackgroundColor(PANEL_BACKGROUND),
ChildOf(root), ChildOf(root),
children![(
Text::new(""),
TextFont {
font_size: 11.0,
..default()
},
TurnStateLabel
)],
)) ))
.id(); .id();
@ -73,6 +86,18 @@ fn setup_debug_menu(mut commands: Commands) {
); );
} }
fn print_state(
mut state_label: Single<&mut Text, With<TurnStateLabel>>,
state: Res<State<TurnState>>,
) {
state_label.0 = match state.get() {
TurnState::Turn => "Your turn".to_string(),
TurnState::PreEffectProcess => "Processing pre unit effects".to_string(),
TurnState::UnitProcess => "Processing units".to_string(),
TurnState::PostEffectProcess => "Processing post unit effects".to_string(),
}
}
fn button(child_of: Entity, text: impl Into<String>) -> impl Bundle { fn button(child_of: Entity, text: impl Into<String>) -> impl Bundle {
( (
Button, Button,

View file

@ -16,7 +16,7 @@ impl Plugin for TurnSystemPlugin {
} }
#[derive(Component)] #[derive(Component)]
pub struct TurnBusy(pub bool); pub struct TurnBusy;
#[derive(Component)] #[derive(Component)]
pub struct TurnPreEffect; pub struct TurnPreEffect;
@ -38,17 +38,17 @@ pub enum TurnState {
fn pre_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPreEffect>>) { fn pre_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPreEffect>>) {
for effect in query { for effect in query {
commands.entity(effect).insert(TurnBusy(false)); commands.entity(effect).insert(TurnBusy);
} }
} }
fn unit_setup(mut commands: Commands, query: Query<Entity, With<TurnUnit>>) { fn unit_setup(mut commands: Commands, query: Query<Entity, With<TurnUnit>>) {
for unit in query { for unit in query {
commands.entity(unit).insert(TurnBusy(false)); commands.entity(unit).insert(TurnBusy);
} }
} }
fn post_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPostEffect>>) { fn post_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPostEffect>>) {
for effect in query { for effect in query {
commands.entity(effect).insert(TurnBusy(false)); commands.entity(effect).insert(TurnBusy);
} }
} }
@ -59,16 +59,7 @@ pub fn try_confirm_turn(mut commands: Commands, turn_state: Res<State<TurnState>
} }
fn process_busy_turnables(mut commands: Commands, query: Query<(Entity, &TurnBusy)>) { fn process_busy_turnables(mut commands: Commands, query: Query<(Entity, &TurnBusy)>) {
let mut advance_flag: bool = true; if query.iter().len() == 0 {
for (turnable, component) in query {
if component.0 {
commands.entity(turnable).remove::<TurnBusy>();
} else {
advance_flag = false;
}
}
if advance_flag {
commands.run_system_cached(try_advance); commands.run_system_cached(try_advance);
} }
} }