jong/src/game/round.rs

128 lines
2.8 KiB
Rust
Raw Normal View History

2026-01-13 00:01:38 -08:00
use bevy::prelude::*;
2026-01-13 12:38:41 -08:00
use strum::{EnumCount, FromRepr};
2026-01-13 00:01:38 -08:00
2026-01-13 13:07:21 -08:00
use crate::{
EnumNextCycle,
game::{GameState, hand::DrawnTile, wall::Wall},
};
2026-01-13 00:01:38 -08:00
#[derive(Component)]
pub(crate) struct Dice(u8, u8);
#[derive(Resource)]
pub(crate) struct Compass {
pub(crate) prevalent_wind: Wind,
pub(crate) round: u8,
pub(crate) dealer_wind: Wind,
pub(crate) riichi: usize,
pub(crate) honba: usize,
}
impl Default for Compass {
fn default() -> Self {
Self {
prevalent_wind: Wind::Ton,
round: 1,
dealer_wind: Wind::Ton,
riichi: 0,
honba: 0,
}
}
}
#[derive(Resource)]
pub(crate) struct MatchSettings {
pub(crate) starting_points: isize,
pub(crate) player_count: u8,
}
impl Default for MatchSettings {
fn default() -> Self {
Self {
starting_points: 25000,
player_count: 4,
}
}
}
2026-01-13 12:38:41 -08:00
2026-01-15 14:00:55 -08:00
#[derive(Component, Clone, Copy, FromRepr, EnumCount, PartialEq)]
2026-01-13 12:38:41 -08:00
pub enum Wind {
Ton,
Nan,
Shaa,
Pei,
}
2026-01-15 14:00:55 -08:00
pub enum WindRelation {
Shimocha,
Toimen,
Kamicha,
}
2026-01-13 12:38:41 -08:00
impl EnumNextCycle for Wind {
fn next(&self) -> Self {
if (*self as usize + 1) >= Self::COUNT {
Self::from_repr(0).unwrap()
} else {
Self::from_repr(*self as usize + 1).unwrap()
}
}
}
2026-01-15 14:00:55 -08:00
impl Wind {
pub fn relate(&self, other: &Self) -> WindRelation {
if self.next() == *other {
WindRelation::Shimocha
} else if other.next() == *self {
WindRelation::Kamicha
} else {
WindRelation::Toimen
}
}
}
2026-01-13 12:38:41 -08:00
#[derive(Resource)]
pub(crate) struct CurrentPlayer(pub Entity);
#[derive(SubStates, Default, Clone, Copy, PartialEq, Eq, Hash, Debug, FromRepr, EnumCount)]
#[source(GameState = GameState::Play)]
pub(crate) enum TurnState {
#[default]
Tsumo,
Menzen,
RiichiKan,
Discard,
RonChiiPonKan,
End,
}
impl EnumNextCycle for TurnState {
fn next(&self) -> Self {
if (*self as usize + 1) >= Self::COUNT {
Self::from_repr(0).unwrap()
} else {
Self::from_repr(*self as usize + 1).unwrap()
}
}
}
2026-01-13 13:07:21 -08:00
pub(crate) fn tsumo(
mut commands: Commands,
curr_player: Res<CurrentPlayer>,
// players: Populated<Entity, With<Player>>,
wall_ent: Single<Entity, With<Wall>>,
walltiles: Single<&Children, With<Wall>>,
curr_turnstate: Res<State<TurnState>>,
mut next_turnstate: ResMut<NextState<TurnState>>,
) {
2026-01-15 14:00:55 -08:00
debug!("tsumo for: {:?}", curr_player.0);
2026-01-13 13:07:21 -08:00
let drawn = walltiles.last().unwrap();
commands.entity(*wall_ent).remove_child(*drawn);
commands.entity(curr_player.0).insert(DrawnTile(*drawn));
debug!("drew: {:?}", drawn);
next_turnstate.set(curr_turnstate.next());
}