(stash)
This commit is contained in:
parent
d7b4221727
commit
222459f828
31 changed files with 870 additions and 135 deletions
|
|
@ -87,7 +87,8 @@ pub fn advance_game(ctx: &ReducerContext, mut game_timer: GameTimer) -> Result<(
|
|||
_ => Err(format!("lobby {} in impossible state", lobby.id))?,
|
||||
}
|
||||
|
||||
ctx.db.game_timer().id().update(game_timer);
|
||||
// ctx.db.game_timer().id().update(game_timer);
|
||||
ctx.db.lobby().id().update(lobby);
|
||||
} else {
|
||||
ctx.db.game_timer().id().delete(game_timer.id);
|
||||
Err(format!(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ pub fn join_or_create_lobby(ctx: &ReducerContext, mut lobby_id: u32) -> Result<(
|
|||
.ok_or(format!("cannot find player {}", ctx.sender))?;
|
||||
|
||||
if lobby_id == 0 {
|
||||
// TODO check first if player is already in a lobby
|
||||
|
||||
let lobby = ctx.db.lobby().insert(Lobby {
|
||||
id: 0,
|
||||
players: vec![PlayerOrBot::Player { id: player.id }],
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use spacetimedb::{SpacetimeType, table};
|
||||
use spacetimedb::{SpacetimeType, ViewContext, table, view};
|
||||
|
||||
use jong_types::{
|
||||
states::{GameState, TurnState},
|
||||
|
|
@ -47,7 +45,6 @@ pub enum PlayerOrBot {
|
|||
Bot { id: u32 },
|
||||
}
|
||||
|
||||
// FIXME this shant be public, use views
|
||||
#[table(name = player, public)]
|
||||
#[table(name = logged_out_player)]
|
||||
#[derive(Debug)]
|
||||
|
|
@ -98,7 +95,7 @@ pub struct PlayerHand {
|
|||
pub working_tile: Option<DbTile>,
|
||||
}
|
||||
|
||||
#[table(name = bot)]
|
||||
#[table(name = bot, public)]
|
||||
pub struct Bot {
|
||||
#[primary_key]
|
||||
#[auto_inc]
|
||||
|
|
@ -126,3 +123,12 @@ pub struct GameTimer {
|
|||
|
||||
pub scheduled_at: spacetimedb::ScheduleAt,
|
||||
}
|
||||
|
||||
#[view(name = view_hand, public)]
|
||||
fn view_hand(ctx: &ViewContext) -> Option<PlayerHand> {
|
||||
ctx.db
|
||||
.player()
|
||||
.identity()
|
||||
.find(ctx.sender)
|
||||
.and_then(|p| ctx.db.player_hand().player_id().find(p.id))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue