test turn
This commit is contained in:
parent
0aa3cdd5cd
commit
2f1b6e9152
3 changed files with 84 additions and 84 deletions
|
|
@ -2,6 +2,7 @@ use bevy::prelude::*;
|
|||
|
||||
use crate::buttons;
|
||||
use crate::card;
|
||||
use crate::turns::try_confirm_turn;
|
||||
|
||||
const PANEL_BORDER: Color = Color::srgb_u8(36, 36, 143);
|
||||
const PANEL_BACKGROUND: Color = Color::srgb_u8(0, 0, 52);
|
||||
|
|
@ -55,60 +56,44 @@ fn setup_debug_menu(mut commands: Commands) {
|
|||
))
|
||||
.id();
|
||||
|
||||
commands
|
||||
.spawn((
|
||||
Button,
|
||||
Node {
|
||||
min_height: px(32),
|
||||
width: percent(100.),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
margin: UiRect::all(px(4)),
|
||||
border: UiRect::all(px(3)),
|
||||
..default()
|
||||
},
|
||||
BorderColor::all(BUTTON_BORDER),
|
||||
BackgroundColor(BUTTON_BACKGROUND),
|
||||
ChildOf(panel),
|
||||
children![(
|
||||
Text::new("Add card"),
|
||||
TextFont {
|
||||
font_size: 11.0,
|
||||
..default()
|
||||
},
|
||||
)],
|
||||
))
|
||||
.observe(
|
||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||
commands.trigger(card::AddCard)
|
||||
},
|
||||
);
|
||||
commands
|
||||
.spawn((
|
||||
Button,
|
||||
Node {
|
||||
min_height: px(32),
|
||||
width: percent(100.),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
margin: UiRect::all(px(4)),
|
||||
border: UiRect::all(px(3)),
|
||||
..default()
|
||||
},
|
||||
BorderColor::all(BUTTON_BORDER),
|
||||
BackgroundColor(BUTTON_BACKGROUND),
|
||||
ChildOf(panel),
|
||||
children![(
|
||||
Text::new("Clear cards"),
|
||||
TextFont {
|
||||
font_size: 11.0,
|
||||
..default()
|
||||
},
|
||||
)],
|
||||
))
|
||||
.observe(
|
||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||
commands.trigger(card::ClearCards)
|
||||
},
|
||||
);
|
||||
commands.spawn(button(panel, "AddCard")).observe(
|
||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||
commands.trigger(card::AddCard)
|
||||
},
|
||||
);
|
||||
commands.spawn(button(panel, "ClearCards")).observe(
|
||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||
commands.trigger(card::ClearCards)
|
||||
},
|
||||
);
|
||||
commands.spawn(button(panel, "ConfirmTurn")).observe(
|
||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||
commands.run_system_cached(try_confirm_turn);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn button(child_of: Entity, text: impl Into<String>) -> impl Bundle {
|
||||
(
|
||||
Button,
|
||||
Node {
|
||||
min_height: px(32),
|
||||
width: percent(100.),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
margin: UiRect::all(px(4)),
|
||||
border: UiRect::all(px(3)),
|
||||
..default()
|
||||
},
|
||||
BorderColor::all(BUTTON_BORDER),
|
||||
BackgroundColor(BUTTON_BACKGROUND),
|
||||
ChildOf(child_of),
|
||||
children![(
|
||||
Text::new(text),
|
||||
TextFont {
|
||||
font_size: 11.0,
|
||||
..default()
|
||||
},
|
||||
)],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
22
src/grid.rs
22
src/grid.rs
|
|
@ -16,13 +16,20 @@ pub struct Grid {
|
|||
bounds: Rect,
|
||||
columns: usize,
|
||||
rows: usize,
|
||||
elements: Vec<Option<Entity>>,
|
||||
elements: Vec<CellState>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum CellState {
|
||||
Empty,
|
||||
Filled(Entity),
|
||||
Part(Entity),
|
||||
}
|
||||
|
||||
impl Grid {
|
||||
pub fn square(start: Vec2, side: f32, cells: usize) -> Self {
|
||||
let mut elements: Vec<Option<Entity>> = Vec::new();
|
||||
elements.resize(cells * cells, None);
|
||||
let mut elements: Vec<CellState> = Vec::new();
|
||||
elements.resize(cells * cells, CellState::Empty);
|
||||
Grid {
|
||||
bounds: Rect::from_corners(
|
||||
start,
|
||||
|
|
@ -54,8 +61,9 @@ impl Grid {
|
|||
}
|
||||
|
||||
match self.elements[self.indexify_position(position)] {
|
||||
Some(_) => true,
|
||||
None => false,
|
||||
CellState::Filled(_) => true,
|
||||
CellState::Part(_) => true,
|
||||
CellState::Empty => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +73,7 @@ impl Grid {
|
|||
}
|
||||
let index = self.indexify_position(position);
|
||||
|
||||
self.elements[index] = Some(entity);
|
||||
self.elements[index] = CellState::Filled(entity);
|
||||
true
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +104,7 @@ fn snap_grid_elements(
|
|||
) {
|
||||
for grid in grid_query {
|
||||
for (index, el) in grid.elements.iter().enumerate() {
|
||||
let Some(entity) = el else {
|
||||
let CellState::Filled(entity) = el else {
|
||||
continue;
|
||||
};
|
||||
let Ok(mut transform) = transform_query.get_mut(entity.clone()) else {
|
||||
|
|
|
|||
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