merge all extra tables back into player for now

This commit is contained in:
Tao Tien 2026-02-11 10:16:21 -08:00
parent 71ad4cada6
commit 9b01f6b96a
16 changed files with 66 additions and 579 deletions

View file

@ -50,8 +50,8 @@ pub fn add_bot(ctx: &ReducerContext, lobby_id: u32) -> Result<(), String> {
let bot = ctx.db.bot().insert(Bot {
id: 0,
lobby_id,
hand_id: 0,
pond_id: 0,
hand: vec![],
pond: vec![],
});
lobby.players.push(PlayerOrBot::Bot { id: bot.id });
ctx.db.lobby().id().update(lobby);

View file

@ -12,40 +12,28 @@ pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) {
// FIXME rectify deal orders
for mut player in players {
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
tiles.sort();
wall = ctx.db.wall().lobby_id().update(wall);
let hand = ctx.db.hand().insert(Hand {
id: 0,
owner: PlayerOrBot::Player { id: player.id },
sort: true,
tiles,
});
player.hand_id = hand.id;
tiles.sort();
player.hand = tiles;
ctx.db.player().id().update(player);
}
for mut bot in bots {
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
tiles.sort();
wall = ctx.db.wall().lobby_id().update(wall);
let hand = ctx.db.hand().insert(Hand {
id: 0,
owner: PlayerOrBot::Bot { id: bot.id },
sort: true,
tiles,
});
bot.hand_id = hand.id;
tiles.sort();
bot.hand = tiles;
ctx.db.bot().id().update(bot);
}
}
#[view(name = view_player_hand, public)]
pub fn view_player_hand(ctx: &ViewContext) -> Option<Hand> {
ctx.db
.player()
.identity()
.find(ctx.sender)
.map(|p| ctx.db.hand().id().find(p.hand_id))?
}
// #[view(name = view_player_hand, public)]
// pub fn view_player_hand(ctx: &ViewContext) -> Option<Hand> {
// ctx.db
// .player()
// .identity()
// .find(ctx.sender)
// .map(|p| ctx.db.hand().id().find(p.hand_id))?
// }
// #[reducer]
// pub fn sort_hand(ctx: &ReducerContext) {

View file

@ -16,9 +16,10 @@ pub fn login_or_add_player(ctx: &ReducerContext) {
id: 0,
name: None,
lobby_id: 0,
hand_id: 0,
pond_id: 0,
ready: false,
sort: true,
hand: vec![],
pond: vec![],
}) {
info!("added player: {:?}", player);
} else {

View file

@ -27,34 +27,3 @@ pub struct Wall {
pub tiles: Vec<Tile>,
}
// TODO temp use deprecated RLS instead of view until bevy_spacetimedb supp is better
#[client_visibility_filter]
const HAND_FILTER: Filter = Filter::Sql(
"SELECT h.* FROM hand h
JOIN player p ON h.id = p.hand_id
WHERE p.identity = :sender",
);
#[table(name = hand, public)]
pub struct Hand {
#[primary_key]
#[auto_inc]
pub id: u32,
pub owner: player::PlayerOrBot,
pub sort: bool,
pub tiles: Vec<Tile>,
}
#[table(name = pond, public)]
pub struct Pond {
#[primary_key]
#[auto_inc]
pub id: u32,
pub owner: player::PlayerOrBot,
pub tiles: Vec<Tile>,
}

View file

@ -1,6 +1,8 @@
use spacetimedb::Identity;
use spacetimedb::{SpacetimeType, table};
use jong_types::*;
#[derive(Debug)]
#[table(name = player, public)]
pub struct Player {
@ -15,10 +17,12 @@ pub struct Player {
#[index(btree)]
pub lobby_id: u32,
pub hand_id: u32,
pub pond_id: u32,
pub ready: bool,
pub sort: bool,
pub hand: Vec<Tile>,
pub pond: Vec<Tile>,
}
#[table(name = bot)]
@ -29,8 +33,9 @@ pub struct Bot {
#[index(btree)]
pub lobby_id: u32,
pub hand_id: u32,
pub pond_id: u32,
pub hand: Vec<Tile>,
pub pond: Vec<Tile>,
}
#[derive(Debug, Clone, SpacetimeType)]