Compare commits
2 commits
b512e38b26
...
922413cc93
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
922413cc93 | ||
|
|
c274f6b807 |
5 changed files with 42 additions and 20 deletions
|
|
@ -15,6 +15,7 @@
|
|||
# paths = [./jong];
|
||||
# };
|
||||
};
|
||||
processes.tail_log.exec = "tail -f jong.log";
|
||||
|
||||
# https://devenv.sh/packages/
|
||||
packages = with pkgs; [
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
commands: Commands
|
||||
|
||||
tiles: Query<(&Tile, &TileId, Entity)>,
|
||||
player: Option<Single<&mut player::Player>>,
|
||||
hand_ent: Option<Single<Entity, With<Hand>>>,
|
||||
|
||||
|
|
@ -4,7 +4,7 @@ use bevy::{log::LogPlugin, prelude::*};
|
|||
use clap::{Parser, Subcommand};
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::{
|
||||
Layer,
|
||||
EnvFilter, Layer,
|
||||
fmt::{self, layer},
|
||||
layer::SubscriberExt,
|
||||
util::SubscriberInitExt,
|
||||
|
|
@ -40,7 +40,11 @@ fn main() {
|
|||
Mode::RunTui => {
|
||||
tracing_subscriber::registry()
|
||||
.with(tui_logger::TuiTracingSubscriberLayer)
|
||||
.with(fmt::layer().with_writer(File::create("jong.log").unwrap()))
|
||||
.with(
|
||||
fmt::layer()
|
||||
.with_writer(File::create("jong.log").unwrap())
|
||||
.with_filter(EnvFilter::from_default_env()),
|
||||
)
|
||||
.init();
|
||||
tui_logger::init_logger(tui_logger::LevelFilter::Trace).unwrap();
|
||||
tui_logger::set_env_filter_from_string(FILTERSTRING);
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
@ -174,11 +187,11 @@ fn spawn_main_hand(
|
|||
.iter()
|
||||
.map(|dbt| commands.spawn((Tile::from(&dbt.tile), TileId(dbt.id))).id())
|
||||
.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 hand = commands.spawn(Hand).add_children(&hand_tiles).id();
|
||||
let pond = commands.spawn(Pond).add_children(&pond_tiles).id();
|
||||
commands.entity(main_player).add_children(&[hand, pond]);
|
||||
|
||||
debug!("main_hand: {:?}\n main_pond: {:?}, children: {:?}", hand_tiles, pond_tiles, children);
|
||||
debug!("main_hand: {:?}\n main_pond: {:?}", hand_tiles, pond_tiles);
|
||||
|
||||
if player_hand.turn_state == jong_db::TurnState::Tsumo
|
||||
&& let Some(drawn_dbt) = &player_hand.working_tile
|
||||
|
|
@ -216,8 +229,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 +240,7 @@ fn on_player_insert_update(
|
|||
false
|
||||
}
|
||||
}) {
|
||||
trace!("spawn_other_player");
|
||||
spawn_other_player(&stdb, &mut commands, &msg.new);
|
||||
} else {
|
||||
// TODO update case
|
||||
|
|
@ -298,10 +313,10 @@ fn on_view_hand_update(
|
|||
) {
|
||||
// TODO can this and similar run at startup or on play/reconnect?
|
||||
for msg in messages.read() {
|
||||
trace!("new hand: {:?}", msg.new);
|
||||
// trace!("new hand: {:?}", msg.new);
|
||||
|
||||
if main_player.1.is_none() {
|
||||
trace!("spawn_main_hand, {:?}", *main_player);
|
||||
// trace!("spawn_main_hand, {:?}", *main_player);
|
||||
spawn_main_hand(&mut commands, &mut next_turnstate, main_player.0, &msg.new);
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@ pub(crate) fn render_main_hand(
|
|||
let mut frame = tui.get_frame();
|
||||
debug_blocks(layouts.clone(), &mut frame);
|
||||
|
||||
if hand.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let hand: Vec<_> = hand
|
||||
.iter()
|
||||
.find_map(|(c, e)| {
|
||||
|
|
@ -222,6 +226,10 @@ pub(crate) fn render_main_pond(
|
|||
) -> Result {
|
||||
let mut frame = tui.get_frame();
|
||||
|
||||
if pond.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let pond: Vec<_> = pond
|
||||
.iter()
|
||||
.find_map(|(c, e)| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue