upgrade spacetimedb to v2.0.1

This commit is contained in:
Tao Tien 2026-02-25 15:22:10 -08:00
parent 5ebf3f6c05
commit baab16144b
38 changed files with 481 additions and 1647 deletions

View file

@ -6,10 +6,10 @@ use jong_types::{
tiles::Tile,
};
use crate::reducers::advance_game;
use crate::reducers::advance_game_private;
#[derive(Debug, Clone)]
#[table(name = lobby, public)]
#[table(accessor = lobby, public)]
pub struct Lobby {
#[primary_key]
#[auto_inc]
@ -23,7 +23,7 @@ pub struct Lobby {
// pub open_hands: bool,
}
#[table(name = wall)]
#[table(accessor = wall)]
pub struct DbWall {
#[primary_key]
pub lobby_id: u32,
@ -31,7 +31,7 @@ pub struct DbWall {
pub tiles: Vec<DbTile>,
}
#[table(name = tile)]
#[table(accessor = tile)]
#[derive(Debug, Clone, Copy)]
pub struct DbTile {
#[primary_key]
@ -41,8 +41,8 @@ pub struct DbTile {
pub tile: Tile,
}
#[table(name = player, public)]
#[table(name = logged_out_player)]
#[table(accessor = player, public)]
#[table(accessor = logged_out_player)]
#[derive(Debug)]
pub struct Player {
#[unique]
@ -61,7 +61,7 @@ pub struct Player {
pub sort: bool,
}
#[table(name = player_clock, public)]
#[table(accessor = player_clock, public)]
pub struct PlayerClock {
#[primary_key]
pub id: u32,
@ -73,7 +73,7 @@ pub struct PlayerClock {
pub total: u16,
}
#[table(name = player_hand)]
#[table(accessor = player_hand)]
pub struct PlayerHand {
#[primary_key]
#[auto_inc]
@ -91,7 +91,7 @@ pub struct PlayerHand {
pub working_tile: Option<DbTile>,
}
#[table(name = bot, public)]
#[table(accessor = bot, public)]
pub struct Bot {
#[primary_key]
#[auto_inc]
@ -108,7 +108,7 @@ pub struct Bot {
pub working_tile: Option<DbTile>,
}
#[table(name = game_timer, scheduled(advance_game), public)]
#[table(accessor = game_timer, scheduled(advance_game_private), public)]
pub struct GameTimer {
#[primary_key]
#[auto_inc]
@ -120,12 +120,12 @@ pub struct GameTimer {
pub scheduled_at: spacetimedb::ScheduleAt,
}
#[view(name = view_hand, public)]
#[view(accessor = view_hand, public)]
fn view_hand(ctx: &ViewContext) -> Option<PlayerHand> {
ctx.db
.player()
.identity()
.find(ctx.sender)
.find(ctx.sender())
.and_then(|p| ctx.db.player_hand().player_id().find(p.id))
}
@ -137,9 +137,9 @@ pub struct HandView {
pub drawn: bool,
}
#[view(name = view_closed_hands, public)]
#[view(accessor = view_closed_hands, public)]
fn view_closed_hands(ctx: &ViewContext) -> Vec<HandView> {
let this_player = ctx.db.player().identity().find(ctx.sender).unwrap();
let this_player = ctx.db.player().identity().find(ctx.sender()).unwrap();
if let Some(lobby) = ctx.db.lobby().id().find(this_player.lobby_id) {
lobby
.players