2026-02-08 23:47:57 -08:00
|
|
|
use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view};
|
|
|
|
|
|
2026-02-11 10:14:02 -08:00
|
|
|
use crate::tables::{player::player, *};
|
2026-02-08 23:47:57 -08:00
|
|
|
use jong_types::*;
|
|
|
|
|
|
|
|
|
|
pub fn deal_hands(ctx: &ReducerContext, lobby_id: u32) {
|
|
|
|
|
let players = ctx.db.player().lobby_id().filter(lobby_id);
|
|
|
|
|
let bots = ctx.db.bot().lobby_id().filter(lobby_id);
|
|
|
|
|
|
|
|
|
|
let mut wall = ctx.db.wall().lobby_id().find(lobby_id).unwrap();
|
|
|
|
|
|
|
|
|
|
// FIXME rectify deal orders
|
|
|
|
|
for mut player in players {
|
|
|
|
|
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
|
|
|
|
wall = ctx.db.wall().lobby_id().update(wall);
|
2026-02-11 10:16:21 -08:00
|
|
|
tiles.sort();
|
|
|
|
|
player.hand = tiles;
|
2026-02-08 23:47:57 -08:00
|
|
|
ctx.db.player().id().update(player);
|
|
|
|
|
}
|
|
|
|
|
for mut bot in bots {
|
|
|
|
|
let mut tiles = wall.tiles.split_off(wall.tiles.len() - 13);
|
|
|
|
|
wall = ctx.db.wall().lobby_id().update(wall);
|
2026-02-11 10:16:21 -08:00
|
|
|
tiles.sort();
|
|
|
|
|
bot.hand = tiles;
|
2026-02-08 23:47:57 -08:00
|
|
|
ctx.db.bot().id().update(bot);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-11 10:16:21 -08:00
|
|
|
// #[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))?
|
|
|
|
|
// }
|
2026-02-08 23:47:57 -08:00
|
|
|
|
|
|
|
|
// #[reducer]
|
|
|
|
|
// pub fn sort_hand(ctx: &ReducerContext) {
|
|
|
|
|
// todo!()
|
|
|
|
|
// }
|