discard_tile is now observer. investigate drawn entity and tileid sychro?

This commit is contained in:
Tao Tien 2026-02-28 20:57:40 -08:00
parent a39ad4cf7c
commit 71ec40ee29
3 changed files with 12 additions and 14 deletions

View file

@ -72,7 +72,6 @@ impl Plugin for TuiPlugin {
open: true,
})
.init_state::<states::TuiState>()
.add_message::<ConfirmSelect>()
.configure_sets(
Update,
(TuiSet::Input, TuiSet::Layout, TuiSet::Render).chain(),
@ -92,28 +91,28 @@ impl Plugin for TuiPlugin {
.chain()
.in_set(TuiSet::Render),
)
.add_systems(Update, discard_tile.run_if(in_state(TurnState::Tsumo)));
// .add_systems(Update, discard_tile.run_if(in_state(TurnState::Tsumo)));
.add_observer(discard_tile) // TODO check run_if here feature is out
;
}
}
fn discard_tile(
selected: On<ConfirmSelect>,
stdb: SpacetimeDB,
mut commands: Commands,
mut selected: MessageReader<ConfirmSelect>,
// main_player: Single<&Children, With<MainPlayer>>,
// only main player will have a Drawn tile?
drawn: Single<(Entity, &TileId), With<Drawn>>,
tiles: Query<&TileId>,
) {
// FIXME why is this not consuming the messages? or is it just getting updated too frequently?
// TODO disable this when we're not current player?
while let Some(message) = selected.read().next() {
trace!("{message:?}");
if let Ok(tile_id) = tiles.get(message.0) {
if let Ok(tile_id) = tiles.get(selected.0) {
trace!("{:?}, {tile_id:?}", selected.0);
stdb.reducers().discard_tile(tile_id.0).unwrap();
stdb.reducers().advance_game().unwrap();
commands.entity(drawn.0).remove::<Drawn>();
}
}
}

View file

@ -12,5 +12,5 @@ pub(crate) struct Hovered;
#[derive(Component)]
pub(crate) struct StartSelect;
#[derive(Message, Debug)]
#[derive(Event, Debug)]
pub(crate) struct ConfirmSelect(pub(crate) Entity);

View file

@ -11,7 +11,6 @@ use crate::tui::{
pub(crate) fn mouse(
mut commands: Commands,
mut mouse_reader: MessageReader<MouseMessage>,
mut event_writer: MessageWriter<ConfirmSelect>,
entities: Query<(Entity, &PickRegion)>,
hovered: Query<(Entity, &PickRegion), With<Hovered>>,
startselected: Query<(Entity, &PickRegion), With<StartSelect>>,
@ -52,7 +51,7 @@ pub(crate) fn mouse(
for (entity, region) in &startselected {
if region.area.contains(position) {
commands.entity(entity).remove::<StartSelect>();
event_writer.write(ConfirmSelect(entity));
commands.trigger(ConfirmSelect(entity));
}
}
}