|
|
|
@ -8,27 +8,40 @@ pub struct DebugPlugin;
|
|
|
|
impl Plugin for DebugPlugin {
|
|
|
|
impl Plugin for DebugPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_observer(track_card_info)
|
|
|
|
app.add_observer(track_card_info)
|
|
|
|
.add_systems(Startup, init_ui);
|
|
|
|
.add_systems(Startup, init_ui)
|
|
|
|
|
|
|
|
.add_systems(Update, set_debug_location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
pub(crate) struct DebugText;
|
|
|
|
pub(crate) struct DebugText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
|
|
|
pub(crate) struct DebugCardText;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
|
|
|
pub(crate) struct DebugLocationText;
|
|
|
|
|
|
|
|
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
fn init_ui(mut commands: Commands) {
|
|
|
|
commands
|
|
|
|
commands
|
|
|
|
.spawn((
|
|
|
|
.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,
|
|
|
|
DebugText,
|
|
|
|
Visibility::Hidden,
|
|
|
|
Visibility::Inherited,
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, 1.0)),
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, 1.0)),
|
|
|
|
PickingBehavior::IGNORE,
|
|
|
|
PickingBehavior::IGNORE,
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((
|
|
|
|
Text2d("...".to_string()),
|
|
|
|
Text2d("...".to_string()),
|
|
|
|
DebugText,
|
|
|
|
DebugLocationText,
|
|
|
|
Transform::default().with_translation(Vec3::new(0.0, 0.0, 2.0)),
|
|
|
|
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,
|
|
|
|
PickingBehavior::IGNORE,
|
|
|
|
));
|
|
|
|
));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -51,13 +64,11 @@ fn track_card_info(
|
|
|
|
pub(crate) fn set_debug_card(
|
|
|
|
pub(crate) fn set_debug_card(
|
|
|
|
trigger: Trigger<Pointer<Over>>,
|
|
|
|
trigger: Trigger<Pointer<Over>>,
|
|
|
|
cards: Query<&Card>,
|
|
|
|
cards: Query<&Card>,
|
|
|
|
mut vis: Query<&mut Visibility, With<DebugText>>,
|
|
|
|
mut vis: Query<&mut Visibility, With<DebugCardText>>,
|
|
|
|
mut debug_text: Query<&mut Text2d, With<DebugText>>,
|
|
|
|
mut debug_text: Single<&mut Text2d, With<DebugCardText>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let card = cards.get(trigger.entity()).unwrap();
|
|
|
|
let card = cards.get(trigger.entity()).unwrap();
|
|
|
|
debug_text.iter_mut().for_each(|mut text| {
|
|
|
|
debug_text.0 = format!("{:#?}", card);
|
|
|
|
text.0 = format!("{:#?}", card);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
vis.iter_mut().for_each(|mut v| {
|
|
|
|
vis.iter_mut().for_each(|mut v| {
|
|
|
|
*v = Visibility::Inherited;
|
|
|
|
*v = Visibility::Inherited;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
@ -65,9 +76,22 @@ pub(crate) fn set_debug_card(
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn hide_debug_card(
|
|
|
|
pub(crate) fn hide_debug_card(
|
|
|
|
_trigger: Trigger<Pointer<Out>>,
|
|
|
|
_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| {
|
|
|
|
vis.iter_mut().for_each(|mut v| {
|
|
|
|
*v = Visibility::Hidden;
|
|
|
|
*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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|