This commit is contained in:
Tao Tien 2026-01-18 10:52:09 -08:00
parent faa653b012
commit 7cbe10c19e
3 changed files with 66 additions and 6 deletions

View file

@ -2,7 +2,7 @@ use bevy::prelude::*;
use crate::{
game::{
hand::Hand,
hand::{Hand, Pond},
player::{CurrentPlayer, MainPlayer},
round::{TurnState, Wind},
wall::Wall,
@ -27,6 +27,17 @@ pub enum GameState {
#[derive(Message)]
pub enum GameMessage {
Discarded(Entity),
CallPending,
Called { player: Entity, calltype: Entity },
}
impl GameMessage {
pub(crate) fn is_called(&self) -> bool {
match self {
GameMessage::Called { .. } => true,
_ => false,
}
}
}
pub struct Riichi;
@ -47,10 +58,9 @@ impl Plugin for Riichi {
.add_systems(OnEnter(TurnState::Menzen), round::menzen)
.add_systems(Update, round::riichi_kan.run_if(in_state(TurnState::RiichiKan)))
.add_systems(Update, round::discard.run_if(in_state(TurnState::Discard)))
.add_systems(Update, round::debug_discard.run_if(in_state(TurnState::Discard)))
.add_systems(Update, round::ron_chi_pon_kan.run_if(in_state(TurnState::RonChiiPonKan)))
.add_systems(OnEnter(TurnState::RonChiiPonKan), round::notify_callable)
.add_systems(Update, round::ron_chi_pon_kan.run_if(in_state(TurnState::RonChiiPonKan)).after(round::notify_callable))
.add_systems(OnEnter(TurnState::End), round::end)
// .add_systems(Update, systems)
// semicolon stopper
;
}
@ -73,6 +83,7 @@ pub(crate) fn setup(
player,
points,
Hand,
Pond,
Wind::from_repr((i - 1) as usize).unwrap(),
);

View file

@ -10,6 +10,9 @@ use crate::{
#[derive(Component)]
pub struct Hand;
#[derive(Component)]
pub struct Pond;
#[derive(Component)]
pub struct Drawn;

View file

@ -1,11 +1,13 @@
use bevy::prelude::*;
use std::rc::Weak;
use bevy::{platform::collections::HashMap, prelude::*};
use strum::{EnumCount, FromRepr};
use crate::{
EnumNextCycle,
game::{
GameMessage, GameState,
hand::{Discarded, Drawn, Hand},
hand::{Discarded, Drawn, Hand, Pond},
player::{CurrentPlayer, Player},
wall::Wall,
},
@ -58,6 +60,15 @@ pub(crate) enum TurnState {
End,
}
#[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum CallType {
Skip,
Ron,
Chii,
Pon,
Kan,
}
impl Default for MatchSettings {
fn default() -> Self {
Self {
@ -191,10 +202,45 @@ pub(crate) fn discard(
Ok(())
}
#[derive(Resource)]
pub struct PendingCalls {
eligible: Vec<Entity>,
calls: HashMap<Entity, CallType>,
}
pub(crate) fn notify_callable() {}
pub(crate) fn ron_chi_pon_kan(
mut commands: Commands,
mut reader: MessageReader<GameMessage>,
discarded: Single<Entity, With<Discarded>>,
mut ponds: Query<(&Children, Entity), (With<Pond>, Without<Player>)>,
calls: Query<&CallType>,
curr_turnstate: Res<State<TurnState>>,
mut next_turnstate: ResMut<NextState<TurnState>>,
) {
// check if can call?
// message players?
// collect then prioritize
// let mut received = vec![];
let mut received: Vec<_> = reader
.read()
.filter_map(|m| {
if let GameMessage::Called { player, calltype } = m
&& let Ok(calltype) = calls.get(*calltype)
{
Some((calltype, player))
} else {
None
}
})
.collect();
received.sort_unstable_by_key(|(c, t)| c);
// received.sort_unstable_by_key(|m| m.);
next_turnstate.set(curr_turnstate.next());
}