extract GameState
This commit is contained in:
parent
78c199b61e
commit
6cd10329df
14 changed files with 118 additions and 28 deletions
|
|
@ -24,22 +24,13 @@ use crate::{
|
|||
},
|
||||
tile::{self},
|
||||
};
|
||||
use jong_types::GameState;
|
||||
|
||||
pub mod hand;
|
||||
pub mod player;
|
||||
pub mod round;
|
||||
pub mod wall;
|
||||
|
||||
#[derive(States, Default, Hash, Clone, Eq, Debug, PartialEq, Copy)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
None,
|
||||
Setup,
|
||||
Deal,
|
||||
Play,
|
||||
Exit,
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
pub enum GameMessage {
|
||||
Discarded(Entity),
|
||||
|
|
@ -85,6 +76,7 @@ impl Plugin for Riichi {
|
|||
.add_systems(Update, on_connect)
|
||||
.add_systems(Update, on_disconnect)
|
||||
.add_systems(Update, on_player_insert_update)
|
||||
// .add_systems(Update, on_lobby_insert_update)
|
||||
.add_systems(OnEnter(GameState::Setup), join_or_create_lobby)
|
||||
.add_systems(OnEnter(GameState::Deal), ||todo!())
|
||||
// semicolon stopper
|
||||
|
|
@ -148,14 +140,18 @@ fn join_or_create_lobby(
|
|||
) {
|
||||
if player.lobby_id == 0 {
|
||||
stdb.reducers().join_or_create_lobby(None).unwrap();
|
||||
stdb.subscription_builder()
|
||||
.on_applied(|_| trace!("subbed to lobby table"))
|
||||
let sub = stdb
|
||||
.subscription_builder()
|
||||
.on_applied(|ctx| trace!("subbed to lobby table"))
|
||||
.on_error(|_, err| error!("sub to lobby table failed: {}", err))
|
||||
.subscribe(["SELECT l.* FROM lobby l JOIN player p ON l.host_id = p.id"]);
|
||||
// JOIN player p ON l.host_id = p.id
|
||||
.subscribe([format!(
|
||||
"SELECT l.*
|
||||
FROM lobby l
|
||||
WHERE l.host_id = {}",
|
||||
player.id
|
||||
)]);
|
||||
} else {
|
||||
debug!("already in lobby")
|
||||
}
|
||||
|
||||
// TODO how can this trigger with a reducer or automatically after all players join/ready
|
||||
next_gamestate.set(GameState::Deal);
|
||||
}
|
||||
|
|
|
|||
24
jong/src/stdb/game_state_type.rs
Normal file
24
jong/src/stdb/game_state_type.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// 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 GameState {
|
||||
None,
|
||||
|
||||
Setup,
|
||||
|
||||
Deal,
|
||||
|
||||
Play,
|
||||
|
||||
Exit,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for GameState {
|
||||
type Module = super::RemoteModule;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
// WILL NOT BE SAVED. MODIFY TABLES IN YOUR MODULE SOURCE CODE INSTEAD.
|
||||
|
||||
#![allow(unused, clippy::all)]
|
||||
use super::game_state_type::GameState;
|
||||
use super::lobby_type::Lobby;
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@
|
|||
#![allow(unused, clippy::all)]
|
||||
use spacetimedb_sdk::__codegen::{self as __sdk, __lib, __sats, __ws};
|
||||
|
||||
use super::game_state_type::GameState;
|
||||
|
||||
#[derive(__lib::ser::Serialize, __lib::de::Deserialize, Clone, PartialEq, Debug)]
|
||||
#[sats(crate = __lib)]
|
||||
pub struct Lobby {
|
||||
pub id: u32,
|
||||
pub host_id: u32,
|
||||
pub game_state: GameState,
|
||||
}
|
||||
|
||||
impl __sdk::InModule for Lobby {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ pub mod bot_table;
|
|||
pub mod bot_type;
|
||||
pub mod deal_hands_reducer;
|
||||
pub mod dragon_type;
|
||||
pub mod game_state_type;
|
||||
pub mod hand_table;
|
||||
pub mod hand_type;
|
||||
pub mod join_or_create_lobby_reducer;
|
||||
|
|
@ -35,6 +36,7 @@ pub use bot_table::*;
|
|||
pub use bot_type::Bot;
|
||||
pub use deal_hands_reducer::{deal_hands, set_flags_for_deal_hands, DealHandsCallbackId};
|
||||
pub use dragon_type::Dragon;
|
||||
pub use game_state_type::GameState;
|
||||
pub use hand_table::*;
|
||||
pub use hand_type::Hand;
|
||||
pub use join_or_create_lobby_reducer::{
|
||||
|
|
|
|||
|
|
@ -2,14 +2,15 @@ use std::time::Duration;
|
|||
|
||||
use bevy::{app::ScheduleRunnerPlugin, prelude::*, state::app::StatesPlugin};
|
||||
use bevy_ratatui::RatatuiPlugins;
|
||||
use jong::game::{
|
||||
GameMessage, GameState,
|
||||
hand::{Drawn, Hand},
|
||||
player::{CurrentPlayer, Player},
|
||||
};
|
||||
use tui_logger::TuiWidgetState;
|
||||
|
||||
use crate::tui::{input::ConfirmSelect, states::ConsoleWidget};
|
||||
use jong::game::{
|
||||
GameMessage,
|
||||
hand::{Drawn, Hand},
|
||||
player::{CurrentPlayer, Player},
|
||||
};
|
||||
use jong_types::GameState;
|
||||
|
||||
mod input;
|
||||
mod layout;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,10 @@ use bevy_ratatui::event::KeyMessage;
|
|||
// use ratatui::crossterm::event::KeyCode;
|
||||
use tui_logger::TuiWidgetEvent;
|
||||
|
||||
use jong::game::GameState;
|
||||
|
||||
use crate::tui::layout::Overlays;
|
||||
use crate::tui::states::ConsoleWidget;
|
||||
use crate::tui::states::TuiState;
|
||||
use jong_types::GameState;
|
||||
|
||||
pub(crate) fn keyboard(
|
||||
mut messages: MessageReader<KeyMessage>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue