turn_state logic

This commit is contained in:
Tao Tien 2026-02-10 01:40:13 -08:00
parent f6361b9fa1
commit 1e6a3ca84b
10 changed files with 61 additions and 16 deletions

View file

@ -11,7 +11,7 @@ use derive_aliases::derive;
use bevy::prelude::*; use bevy::prelude::*;
use spacetimedb::SpacetimeType; use spacetimedb::SpacetimeType;
use strum::FromRepr; use strum::{EnumCount, FromRepr};
#[derive(..Base, Hash, Default)] #[derive(..Base, Hash, Default)]
#[derive(States, SpacetimeType)] #[derive(States, SpacetimeType)]
@ -112,3 +112,24 @@ pub fn tiles() -> Vec<Tile> {
} }
tiles tiles
} }
#[derive(
Default,
..Copy,
PartialEq,
Eq,
Hash,
Debug,
)]
#[derive(SubStates, FromRepr, EnumCount, SpacetimeType)]
#[source(GameState = GameState::Play)]
pub enum TurnState {
#[default]
None,
Tsumo,
Menzen,
RiichiKan,
Discard,
RonChiiPonKan,
End,
}

View file

@ -21,7 +21,7 @@ use crate::{
game::{ game::{
hand::{Hand, Pond}, hand::{Hand, Pond},
player::{CurrentPlayer, MainPlayer}, player::{CurrentPlayer, MainPlayer},
round::{TurnState, Wind}, round::Wind,
wall::Wall, wall::Wall,
}, },
tile::{self}, tile::{self},
@ -65,7 +65,7 @@ impl Plugin for Riichi {
app.add_plugins(plugins) app.add_plugins(plugins)
.init_state::<GameState>() .init_state::<GameState>()
// .add_sub_state::<TurnState>() .add_sub_state::<TurnState>()
// .init_resource::<round::MatchSettings>() // .init_resource::<round::MatchSettings>()
// .init_resource::<round::Compass>() // .init_resource::<round::Compass>()
.add_message::<GameMessage>() .add_message::<GameMessage>()

View file

@ -12,6 +12,7 @@ use crate::{
wall::Wall, wall::Wall,
}, },
}; };
use jong_types::TurnState;
// #[derive(Resource)] // #[derive(Resource)]
// pub struct CurrentPlayer(pub Entity); // pub struct CurrentPlayer(pub Entity);
@ -48,18 +49,6 @@ pub enum WindRelation {
Kamicha, Kamicha,
} }
#[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,
}
#[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)] #[derive(Component, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum CallType { pub(crate) enum CallType {
Skip, Skip,

View file

@ -5,6 +5,7 @@
use super::game_state_type::GameState; use super::game_state_type::GameState;
use super::lobby_type::Lobby; use super::lobby_type::Lobby;
use super::player_or_bot_type::PlayerOrBot; use super::player_or_bot_type::PlayerOrBot;
use super::turn_state_type::TurnState;
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws}; use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
/// Table handle for the table `lobby`. /// Table handle for the table `lobby`.

View file

@ -6,6 +6,7 @@ use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
use super::game_state_type::GameState; use super::game_state_type::GameState;
use super::player_or_bot_type::PlayerOrBot; use super::player_or_bot_type::PlayerOrBot;
use super::turn_state_type::TurnState;
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)] #[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)] #[sats(crate = __lib)]
@ -14,6 +15,7 @@ pub struct Lobby {
pub host_player_id: u32, pub host_player_id: u32,
pub players: Vec<PlayerOrBot>, pub players: Vec<PlayerOrBot>,
pub game_state: GameState, pub game_state: GameState,
pub turn_state: TurnState,
} }
impl __sdk::InModule for Lobby { impl __sdk::InModule for Lobby {

View file

@ -26,6 +26,7 @@ pub mod rank_type;
pub mod shuffle_deal_reducer; pub mod shuffle_deal_reducer;
pub mod suit_type; pub mod suit_type;
pub mod tile_type; pub mod tile_type;
pub mod turn_state_type;
pub mod view_player_hand_table; pub mod view_player_hand_table;
pub mod wall_table; pub mod wall_table;
pub mod wall_type; pub mod wall_type;
@ -55,6 +56,7 @@ pub use rank_type::Rank;
pub use shuffle_deal_reducer::{set_flags_for_shuffle_deal, shuffle_deal, ShuffleDealCallbackId}; pub use shuffle_deal_reducer::{set_flags_for_shuffle_deal, shuffle_deal, ShuffleDealCallbackId};
pub use suit_type::Suit; pub use suit_type::Suit;
pub use tile_type::Tile; pub use tile_type::Tile;
pub use turn_state_type::TurnState;
pub use view_player_hand_table::*; pub use view_player_hand_table::*;
pub use wall_table::*; pub use wall_table::*;
pub use wall_type::Wall; pub use wall_type::Wall;

View file

@ -0,0 +1,28 @@
// THIS FILE IS AUTOMATICALLY GENERATED BY SPACETIMEDB. EDITS TO THIS FILE
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
#![allow(unused, clippy::all)]
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
#[sats(crate = __lib)]
#[derive(Copy, Eq, Hash)]
pub enum TurnState {
None,
Tsumo,
Menzen,
RiichiKan,
Discard,
RonChiiPonKan,
End,
}
impl __sdk::InModule for TurnState {
type Module = super::RemoteModule;
}

View file

@ -23,6 +23,7 @@ pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<(
host_player_id: player.id, host_player_id: player.id,
players: vec![PlayerOrBot::Player { id: player.id }], players: vec![PlayerOrBot::Player { id: player.id }],
game_state: GameState::Setup, game_state: GameState::Setup,
turn_state: TurnState::None,
}); });
info!("created lobby: {:?}", lobby); info!("created lobby: {:?}", lobby);

View file

@ -13,7 +13,6 @@ pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
lobby.game_state = GameState::Deal; lobby.game_state = GameState::Deal;
let mut lobby = ctx.db.lobby().id().update(lobby); let mut lobby = ctx.db.lobby().id().update(lobby);
let tiles = new_shuffled_wall(ctx); let tiles = new_shuffled_wall(ctx);
ctx.db.wall().insert(Wall { ctx.db.wall().insert(Wall {
// id: 0, // id: 0,
@ -24,6 +23,7 @@ pub fn shuffle_deal(ctx: &ReducerContext, lobby_id: u32) {
deal_hands(ctx, lobby_id); deal_hands(ctx, lobby_id);
lobby.game_state = GameState::Play; lobby.game_state = GameState::Play;
lobby.turn_state = TurnState::Tsumo;
ctx.db.lobby().id().update(lobby); ctx.db.lobby().id().update(lobby);
} }

View file

@ -50,6 +50,7 @@ pub struct Lobby {
pub players: Vec<PlayerOrBot>, pub players: Vec<PlayerOrBot>,
pub game_state: GameState, pub game_state: GameState,
pub turn_state: TurnState,
} }
#[table(name = wall)] #[table(name = wall)]