Debug info, rotating cards, fixed backgrounds
parent
5c1de3525f
commit
0e492ea7df
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,10 +1,73 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use crate::deck::Card;
|
||||||
|
|
||||||
/// Debugging systems
|
/// Debugging systems
|
||||||
pub struct DebugPlugin;
|
pub struct DebugPlugin;
|
||||||
|
|
||||||
impl Plugin for DebugPlugin {
|
impl Plugin for DebugPlugin {
|
||||||
fn build(&self, _app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
// Nothing yet!
|
app.add_observer(track_card_info)
|
||||||
|
.add_systems(Startup, init_ui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub(crate) struct DebugText;
|
||||||
|
|
||||||
|
fn init_ui(mut commands: Commands) {
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
Sprite::from_color(Color::BLACK.with_alpha(0.9), [100.0, 100.0].into()),
|
||||||
|
DebugText,
|
||||||
|
Visibility::Hidden,
|
||||||
|
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)),
|
||||||
|
PickingBehavior::IGNORE,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn track_card_info(
|
||||||
|
trigger: Trigger<Pointer<Move>>,
|
||||||
|
mut transforms: Query<&mut Transform, (With<DebugText>, With<Sprite>)>,
|
||||||
|
window: Query<&Window>,
|
||||||
|
) {
|
||||||
|
let p = trigger.pointer_location.position;
|
||||||
|
transforms.iter_mut().for_each(|mut t| {
|
||||||
|
let offset = window.single().resolution.size() / 2.0;
|
||||||
|
let pos = p - offset + Vec2::new(-50.0, 50.0);
|
||||||
|
t.translation.x = pos.x;
|
||||||
|
t.translation.y = -pos.y;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
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>>,
|
||||||
|
) {
|
||||||
|
let card = cards.get(trigger.entity()).unwrap();
|
||||||
|
debug_text.iter_mut().for_each(|mut text| {
|
||||||
|
text.0 = format!("{}", card);
|
||||||
|
});
|
||||||
|
vis.iter_mut().for_each(|mut v| {
|
||||||
|
*v = Visibility::Inherited;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn hide_debug_card(
|
||||||
|
_trigger: Trigger<Pointer<Out>>,
|
||||||
|
mut vis: Query<&mut Visibility, With<DebugText>>,
|
||||||
|
) {
|
||||||
|
vis.iter_mut().for_each(|mut v| {
|
||||||
|
*v = Visibility::Hidden;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@ -1,9 +1,18 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
use crate::deck::Card;
|
||||||
|
|
||||||
pub struct PlayPlugin;
|
pub struct PlayPlugin;
|
||||||
|
|
||||||
impl Plugin for PlayPlugin {
|
impl Plugin for PlayPlugin {
|
||||||
fn build(&self, _app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
// Nothing yet!
|
app.add_systems(Update, rotate_cards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rotate_cards(mut query: Query<&mut Transform, With<Card>>, time: Res<Time>) {
|
||||||
|
let dt = time.delta().as_secs_f32();
|
||||||
|
query.iter_mut().for_each(|mut t| {
|
||||||
|
t.rotate_z(dt * 0.5);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue