Debug shows world coordinates which is nice.

main
Elijah Voigt 1 year ago
parent 9aa028e2c4
commit 73af4d3706

@ -8,27 +8,40 @@ pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
app.add_observer(track_card_info)
.add_systems(Startup, init_ui);
.add_systems(Startup, init_ui)
.add_systems(Update, set_debug_location);
}
}
#[derive(Component)]
pub(crate) struct DebugText;
#[derive(Component)]
pub(crate) struct DebugCardText;
#[derive(Component)]
pub(crate) struct DebugLocationText;
fn init_ui(mut commands: Commands) {
commands
.spawn((
Sprite::from_color(Color::BLACK.with_alpha(0.9), [250.0, 150.0].into()),
Sprite::from_color(Color::BLACK.with_alpha(0.9), [250.0, 200.0].into()),
DebugText,
Visibility::Hidden,
Visibility::Inherited,
Transform::default().with_translation(Vec3::new(0.0, 0.0, 1.0)),
PickingBehavior::IGNORE,
))
.with_children(|parent| {
parent.spawn((
Text2d("...".to_string()),
DebugText,
Transform::default().with_translation(Vec3::new(0.0, 0.0, 2.0)),
DebugLocationText,
Transform::default().with_translation(Vec3::new(-50.0, 80.0, 2.0)),
PickingBehavior::IGNORE,
));
parent.spawn((
Text2d("...".to_string()),
DebugCardText,
Transform::default().with_translation(Vec3::new(10.0, -25.0, 2.0)),
PickingBehavior::IGNORE,
));
});
@ -51,13 +64,11 @@ fn track_card_info(
pub(crate) fn set_debug_card(
trigger: Trigger<Pointer<Over>>,
cards: Query<&Card>,
mut vis: Query<&mut Visibility, With<DebugText>>,
mut debug_text: Query<&mut Text2d, With<DebugText>>,
mut vis: Query<&mut Visibility, With<DebugCardText>>,
mut debug_text: Single<&mut Text2d, With<DebugCardText>>,
) {
let card = cards.get(trigger.entity()).unwrap();
debug_text.iter_mut().for_each(|mut text| {
text.0 = format!("{:#?}", card);
});
debug_text.0 = format!("{:#?}", card);
vis.iter_mut().for_each(|mut v| {
*v = Visibility::Inherited;
});
@ -65,9 +76,22 @@ pub(crate) fn set_debug_card(
pub(crate) fn hide_debug_card(
_trigger: Trigger<Pointer<Out>>,
mut vis: Query<&mut Visibility, With<DebugText>>,
mut vis: Query<&mut Visibility, With<DebugCardText>>,
) {
vis.iter_mut().for_each(|mut v| {
*v = Visibility::Hidden;
});
}
fn set_debug_location(
window: Single<&Window>,
camera: Single<(&Camera, &GlobalTransform)>,
mut text: Single<&mut Text2d, With<DebugLocationText>>,
) {
let (cam, gt) = *camera;
if let Some(pos) = window.cursor_position() {
if let Ok(world_pos) = cam.viewport_to_world_2d(gt, pos) {
text.0 = format!("{:.1},{:.1}", world_pos.x, world_pos.y);
}
}
}

@ -226,12 +226,33 @@ fn set_added(query: Query<Entity, Added<SetNumber>>) -> bool {
/// When a card is added to the board, place it on the screen
pub(crate) fn place_card(
trigger: Trigger<OnAdd, PlayLocation>,
mut query: Query<(&PlayLocation, &mut Visibility, &mut Transform)>,
mut query: Query<(
Entity,
&PlayLocation,
&mut Visibility,
&Name,
&mut AnimationPlayer,
)>,
animation_store: Res<AnimationStore>,
mut commands: Commands,
) {
let (pl, mut visibility, mut transform) = query.get_mut(trigger.entity()).unwrap();
let (entity, play_location, mut visibility, name, mut player) =
query.get_mut(trigger.entity()).unwrap();
let (graph_handle, animation_index) = animation_store
.store
.get(&format!("deck->{:?}", (play_location.x, play_location.y)))
.unwrap();
player.play(animation_index.clone());
// Set it's transform based on it's placement
transform.translation = card_placement(pl);
commands.entity(entity).insert((
graph_handle.clone(),
AnimationTarget {
id: AnimationTargetId::from_name(name),
player: entity,
},
));
// Set it to visible
*visibility = Visibility::Inherited;

@ -123,9 +123,9 @@ fn setup_animations(
// For each spot on board
RangeInclusive::<u8>::new(0, 3).for_each(|x| {
RangeInclusive::<u8>::new(0, 3).for_each(|y| {
let a = Vec3::new(-100.0, 0.0, 0.0);
let a = Vec3::new(-400.0, -200.0, 0.0);
let b = play::card_placement(&play::PlayLocation { x, y });
let c = Vec3::new(100.0, 0.0, 0.0);
let c = Vec3::new(-400.0, 200.0, 0.0);
// Serve Deck -> Spot Animation
{

Loading…
Cancel
Save