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::buttons;
|
||||||
use crate::card;
|
use crate::card;
|
||||||
|
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);
|
||||||
const PANEL_BACKGROUND: Color = Color::srgb_u8(0, 0, 52);
|
const PANEL_BACKGROUND: Color = Color::srgb_u8(0, 0, 52);
|
||||||
|
|
@ -55,60 +56,44 @@ fn setup_debug_menu(mut commands: Commands) {
|
||||||
))
|
))
|
||||||
.id();
|
.id();
|
||||||
|
|
||||||
commands
|
commands.spawn(button(panel, "AddCard")).observe(
|
||||||
.spawn((
|
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||||
Button,
|
commands.trigger(card::AddCard)
|
||||||
Node {
|
},
|
||||||
min_height: px(32),
|
);
|
||||||
width: percent(100.),
|
commands.spawn(button(panel, "ClearCards")).observe(
|
||||||
justify_content: JustifyContent::Center,
|
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||||
align_items: AlignItems::Center,
|
commands.trigger(card::ClearCards)
|
||||||
margin: UiRect::all(px(4)),
|
},
|
||||||
border: UiRect::all(px(3)),
|
);
|
||||||
..default()
|
commands.spawn(button(panel, "ConfirmTurn")).observe(
|
||||||
},
|
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
||||||
BorderColor::all(BUTTON_BORDER),
|
commands.run_system_cached(try_confirm_turn);
|
||||||
BackgroundColor(BUTTON_BACKGROUND),
|
},
|
||||||
ChildOf(panel),
|
);
|
||||||
children![(
|
}
|
||||||
Text::new("Add card"),
|
|
||||||
TextFont {
|
fn button(child_of: Entity, text: impl Into<String>) -> impl Bundle {
|
||||||
font_size: 11.0,
|
(
|
||||||
..default()
|
Button,
|
||||||
},
|
Node {
|
||||||
)],
|
min_height: px(32),
|
||||||
))
|
width: percent(100.),
|
||||||
.observe(
|
justify_content: JustifyContent::Center,
|
||||||
|_: On<buttons::ButtonPressedEvent>, mut commands: Commands| {
|
align_items: AlignItems::Center,
|
||||||
commands.trigger(card::AddCard)
|
margin: UiRect::all(px(4)),
|
||||||
},
|
border: UiRect::all(px(3)),
|
||||||
);
|
..default()
|
||||||
commands
|
},
|
||||||
.spawn((
|
BorderColor::all(BUTTON_BORDER),
|
||||||
Button,
|
BackgroundColor(BUTTON_BACKGROUND),
|
||||||
Node {
|
ChildOf(child_of),
|
||||||
min_height: px(32),
|
children![(
|
||||||
width: percent(100.),
|
Text::new(text),
|
||||||
justify_content: JustifyContent::Center,
|
TextFont {
|
||||||
align_items: AlignItems::Center,
|
font_size: 11.0,
|
||||||
margin: UiRect::all(px(4)),
|
..default()
|
||||||
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)
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
22
src/grid.rs
22
src/grid.rs
|
|
@ -16,13 +16,20 @@ pub struct Grid {
|
||||||
bounds: Rect,
|
bounds: Rect,
|
||||||
columns: usize,
|
columns: usize,
|
||||||
rows: 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 {
|
impl Grid {
|
||||||
pub fn square(start: Vec2, side: f32, cells: usize) -> Self {
|
pub fn square(start: Vec2, side: f32, cells: usize) -> Self {
|
||||||
let mut elements: Vec<Option<Entity>> = Vec::new();
|
let mut elements: Vec<CellState> = Vec::new();
|
||||||
elements.resize(cells * cells, None);
|
elements.resize(cells * cells, CellState::Empty);
|
||||||
Grid {
|
Grid {
|
||||||
bounds: Rect::from_corners(
|
bounds: Rect::from_corners(
|
||||||
start,
|
start,
|
||||||
|
|
@ -54,8 +61,9 @@ impl Grid {
|
||||||
}
|
}
|
||||||
|
|
||||||
match self.elements[self.indexify_position(position)] {
|
match self.elements[self.indexify_position(position)] {
|
||||||
Some(_) => true,
|
CellState::Filled(_) => true,
|
||||||
None => false,
|
CellState::Part(_) => true,
|
||||||
|
CellState::Empty => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,7 +73,7 @@ impl Grid {
|
||||||
}
|
}
|
||||||
let index = self.indexify_position(position);
|
let index = self.indexify_position(position);
|
||||||
|
|
||||||
self.elements[index] = Some(entity);
|
self.elements[index] = CellState::Filled(entity);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +104,7 @@ fn snap_grid_elements(
|
||||||
) {
|
) {
|
||||||
for grid in grid_query {
|
for grid in grid_query {
|
||||||
for (index, el) in grid.elements.iter().enumerate() {
|
for (index, el) in grid.elements.iter().enumerate() {
|
||||||
let Some(entity) = el else {
|
let CellState::Filled(entity) = el else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let Ok(mut transform) = transform_query.get_mut(entity.clone()) else {
|
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)]
|
#[derive(Component)]
|
||||||
struct TurnBusy(bool);
|
pub struct TurnBusy(pub bool);
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct TurnPreEffect;
|
pub struct TurnPreEffect;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct TurnUnit;
|
pub struct TurnUnit;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
struct TurnPostEffect;
|
pub struct TurnPostEffect;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)]
|
||||||
enum TurnState {
|
pub enum TurnState {
|
||||||
#[default]
|
#[default]
|
||||||
Turn,
|
Turn,
|
||||||
PreEffectProcess,
|
PreEffectProcess,
|
||||||
|
|
@ -51,11 +51,14 @@ fn post_effect_setup(mut commands: Commands, query: Query<Entity, With<TurnPostE
|
||||||
commands.entity(effect).insert(TurnBusy(false));
|
commands.entity(effect).insert(TurnBusy(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn process_busy_turnables(
|
|
||||||
mut commands: Commands,
|
pub fn try_confirm_turn(mut commands: Commands, turn_state: Res<State<TurnState>>) {
|
||||||
query: Query<(Entity, &TurnBusy)>,
|
if let TurnState::Turn = turn_state.get() {
|
||||||
state: Res<State<TurnState>>,
|
commands.set_state(TurnState::PreEffectProcess);
|
||||||
) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_busy_turnables(mut commands: Commands, query: Query<(Entity, &TurnBusy)>) {
|
||||||
let mut advance_flag: bool = true;
|
let mut advance_flag: bool = true;
|
||||||
for (turnable, component) in query {
|
for (turnable, component) in query {
|
||||||
if component.0 {
|
if component.0 {
|
||||||
|
|
@ -66,19 +69,23 @@ fn process_busy_turnables(
|
||||||
}
|
}
|
||||||
|
|
||||||
if advance_flag {
|
if advance_flag {
|
||||||
match state.get() {
|
commands.run_system_cached(try_advance);
|
||||||
TurnState::Turn => {
|
}
|
||||||
commands.set_state(TurnState::PreEffectProcess);
|
}
|
||||||
}
|
|
||||||
TurnState::PreEffectProcess => {
|
fn try_advance(mut commands: Commands, state: Res<State<TurnState>>) {
|
||||||
commands.set_state(TurnState::UnitProcess);
|
match state.get() {
|
||||||
}
|
TurnState::Turn => {
|
||||||
TurnState::UnitProcess => {
|
commands.set_state(TurnState::PreEffectProcess);
|
||||||
commands.set_state(TurnState::PostEffectProcess);
|
}
|
||||||
}
|
TurnState::PreEffectProcess => {
|
||||||
TurnState::PostEffectProcess => {
|
commands.set_state(TurnState::UnitProcess);
|
||||||
commands.set_state(TurnState::Turn);
|
}
|
||||||
}
|
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