while .next() on db cache is infinite
This commit is contained in:
parent
b512e38b26
commit
c274f6b807
2 changed files with 29 additions and 14 deletions
|
|
@ -1,6 +0,0 @@
|
|||
commands: Commands
|
||||
|
||||
tiles: Query<(&Tile, &TileId, Entity)>,
|
||||
player: Option<Single<&mut player::Player>>,
|
||||
hand_ent: Option<Single<Entity, With<Hand>>>,
|
||||
|
||||
|
|
@ -83,10 +83,19 @@ fn subscriptions(stdb: SpacetimeDB, mut commands: Commands) {
|
|||
// commands.queue(command);
|
||||
let (send, recv) = std::sync::mpsc::channel::<Subscribed>();
|
||||
stdb.subscription_builder()
|
||||
.on_applied(move |_| send.send(Subscribed).unwrap())
|
||||
.on_error(|_, err| error!("sub failed: {err}"))
|
||||
.on_applied(move |_| {
|
||||
trace!("subs succeeded");
|
||||
send.send(Subscribed).unwrap();
|
||||
})
|
||||
.on_error(|_, err| {
|
||||
error!("subs failed: {err}");
|
||||
})
|
||||
.subscribe([
|
||||
// TODO change these to sub/unsub based on being in lobby and some such
|
||||
format!(
|
||||
"SELECT p.* FROM player p WHERE p.identity = '{}'",
|
||||
stdb.identity()
|
||||
),
|
||||
"SELECT p.* FROM player p JOIN lobby l ON p.lobby_id = l.id".to_string(),
|
||||
"SELECT l.* FROM lobby l JOIN player p ON l.id = p.lobby_id".to_string(),
|
||||
"SELECT c.* FROM player_clock c JOIN player p ON c.player_id = p.id".to_string(),
|
||||
|
|
@ -111,14 +120,18 @@ fn on_subscribed(
|
|||
mut next_gamestate: ResMut<NextState<GameState>>,
|
||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
||||
) {
|
||||
while let Some(player) = stdb.db().player().iter().next() {
|
||||
trace!("on_subscribed");
|
||||
for player in stdb.db().player().iter() {
|
||||
if player.identity == stdb.identity() {
|
||||
// trace!("spawn_main_player");
|
||||
spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &player);
|
||||
} else {
|
||||
// trace!("spawn_other_player");
|
||||
spawn_other_player(&stdb, &mut commands, &player);
|
||||
}
|
||||
}
|
||||
while let Some(bot) = stdb.db().bot().iter().next() {
|
||||
|
||||
for bot in stdb.db().bot().iter() {
|
||||
let id = PlayerOrBot::Bot { id: bot.id };
|
||||
let hand_view = stdb
|
||||
.db()
|
||||
|
|
@ -143,7 +156,7 @@ fn spawn_main_player(
|
|||
|
||||
player: &jong_db::Player,
|
||||
) {
|
||||
trace!("spawn_main_player");
|
||||
// trace!("spawn_main_player");
|
||||
let main_player = commands
|
||||
.spawn((
|
||||
Player {
|
||||
|
|
@ -176,9 +189,15 @@ fn spawn_main_hand(
|
|||
.collect();
|
||||
let pond = commands.spawn(Hand).add_children(&pond_tiles).id();
|
||||
let hand = commands.spawn(Pond).add_children(&hand_tiles).id();
|
||||
let children = commands.entity(main_player).add_children(&[pond, hand]).id();
|
||||
let children = commands
|
||||
.entity(main_player)
|
||||
.add_children(&[pond, hand])
|
||||
.id();
|
||||
|
||||
debug!("main_hand: {:?}\n main_pond: {:?}, children: {:?}", hand_tiles, pond_tiles, children);
|
||||
debug!(
|
||||
"main_hand: {:?}\n main_pond: {:?}, children: {:?}",
|
||||
hand_tiles, pond_tiles, children
|
||||
);
|
||||
|
||||
if player_hand.turn_state == jong_db::TurnState::Tsumo
|
||||
&& let Some(drawn_dbt) = &player_hand.working_tile
|
||||
|
|
@ -216,8 +235,9 @@ fn on_player_insert_update(
|
|||
mut next_turnstate: ResMut<NextState<jong_types::states::TurnState>>,
|
||||
) {
|
||||
for msg in messages.read() {
|
||||
debug!("on_player_insert_update: {:?}", msg.new);
|
||||
if main_player.is_none() && msg.new.identity == stdb.identity() {
|
||||
trace!("spawn_main_player");
|
||||
// trace!("spawn_main_player");
|
||||
spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &msg.new);
|
||||
} else if other_players.iter().any(|p| {
|
||||
if let PlayerOrBot::Player { id } = &p.id {
|
||||
|
|
@ -226,6 +246,7 @@ fn on_player_insert_update(
|
|||
false
|
||||
}
|
||||
}) {
|
||||
trace!("spawn_other_player");
|
||||
spawn_other_player(&stdb, &mut commands, &msg.new);
|
||||
} else {
|
||||
// TODO update case
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue