hack for player-lobby and Res<Player> race?
This commit is contained in:
parent
9f6a5b6423
commit
47735931b4
34 changed files with 536 additions and 1340 deletions
53
spacetimedb/src/game/hand.rs
Normal file
53
spacetimedb/src/game/hand.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
use spacetimedb::{ReducerContext, Table, ViewContext, reducer, view};
|
||||
|
||||
use crate::tables::*;
|
||||
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);
|
||||
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;
|
||||
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;
|
||||
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))?
|
||||
}
|
||||
|
||||
// #[reducer]
|
||||
// pub fn sort_hand(ctx: &ReducerContext) {
|
||||
// todo!()
|
||||
// }
|
||||
Loading…
Add table
Add a link
Reference in a new issue