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);
|
// commands.queue(command);
|
||||||
let (send, recv) = std::sync::mpsc::channel::<Subscribed>();
|
let (send, recv) = std::sync::mpsc::channel::<Subscribed>();
|
||||||
stdb.subscription_builder()
|
stdb.subscription_builder()
|
||||||
.on_applied(move |_| send.send(Subscribed).unwrap())
|
.on_applied(move |_| {
|
||||||
.on_error(|_, err| error!("sub failed: {err}"))
|
trace!("subs succeeded");
|
||||||
|
send.send(Subscribed).unwrap();
|
||||||
|
})
|
||||||
|
.on_error(|_, err| {
|
||||||
|
error!("subs failed: {err}");
|
||||||
|
})
|
||||||
.subscribe([
|
.subscribe([
|
||||||
// TODO change these to sub/unsub based on being in lobby and some such
|
// 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 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 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(),
|
"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_gamestate: ResMut<NextState<GameState>>,
|
||||||
mut next_turnstate: ResMut<NextState<TurnState>>,
|
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() {
|
if player.identity == stdb.identity() {
|
||||||
|
// trace!("spawn_main_player");
|
||||||
spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &player);
|
spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &player);
|
||||||
} else {
|
} else {
|
||||||
|
// trace!("spawn_other_player");
|
||||||
spawn_other_player(&stdb, &mut commands, &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 id = PlayerOrBot::Bot { id: bot.id };
|
||||||
let hand_view = stdb
|
let hand_view = stdb
|
||||||
.db()
|
.db()
|
||||||
|
|
@ -143,7 +156,7 @@ fn spawn_main_player(
|
||||||
|
|
||||||
player: &jong_db::Player,
|
player: &jong_db::Player,
|
||||||
) {
|
) {
|
||||||
trace!("spawn_main_player");
|
// trace!("spawn_main_player");
|
||||||
let main_player = commands
|
let main_player = commands
|
||||||
.spawn((
|
.spawn((
|
||||||
Player {
|
Player {
|
||||||
|
|
@ -176,9 +189,15 @@ fn spawn_main_hand(
|
||||||
.collect();
|
.collect();
|
||||||
let pond = commands.spawn(Hand).add_children(&pond_tiles).id();
|
let pond = commands.spawn(Hand).add_children(&pond_tiles).id();
|
||||||
let hand = commands.spawn(Pond).add_children(&hand_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
|
if player_hand.turn_state == jong_db::TurnState::Tsumo
|
||||||
&& let Some(drawn_dbt) = &player_hand.working_tile
|
&& 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>>,
|
mut next_turnstate: ResMut<NextState<jong_types::states::TurnState>>,
|
||||||
) {
|
) {
|
||||||
for msg in messages.read() {
|
for msg in messages.read() {
|
||||||
|
debug!("on_player_insert_update: {:?}", msg.new);
|
||||||
if main_player.is_none() && msg.new.identity == stdb.identity() {
|
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);
|
spawn_main_player(&stdb, &mut commands, &mut next_turnstate, &msg.new);
|
||||||
} else if other_players.iter().any(|p| {
|
} else if other_players.iter().any(|p| {
|
||||||
if let PlayerOrBot::Player { id } = &p.id {
|
if let PlayerOrBot::Player { id } = &p.id {
|
||||||
|
|
@ -226,6 +246,7 @@ fn on_player_insert_update(
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
trace!("spawn_other_player");
|
||||||
spawn_other_player(&stdb, &mut commands, &msg.new);
|
spawn_other_player(&stdb, &mut commands, &msg.new);
|
||||||
} else {
|
} else {
|
||||||
// TODO update case
|
// TODO update case
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue