70 lines
2.6 KiB
Rust
70 lines
2.6 KiB
Rust
|
|
use bevy::color::Color;
|
||
|
|
use bevy::math::{Vec2, Vec3};
|
||
|
|
use bevy::prelude::{default, Commands, Gizmos, Text2d, TextColor, TextFont, Transform};
|
||
|
|
use crate::states::level::components::DebugSlotNumber;
|
||
|
|
use crate::states::level::system::{SHIFT, SLOT_SIZE};
|
||
|
|
use crate::{HEIGHT, WIDTH};
|
||
|
|
|
||
|
|
const GRID_COLS: f32 = WIDTH as f32 * SHIFT;
|
||
|
|
const GRID_ROWS: f32 = HEIGHT as f32 * SHIFT;
|
||
|
|
const SLOTS_IN_ROW: u32 = WIDTH * SHIFT as u32;
|
||
|
|
const SLOTS_IN_COL: u32 = HEIGHT * SHIFT as u32;
|
||
|
|
|
||
|
|
pub fn debug_draw_grid(mut gizmos: Gizmos, mut commands: Commands) {
|
||
|
|
let width = GRID_COLS * SLOT_SIZE;
|
||
|
|
let height = GRID_ROWS * SLOT_SIZE;
|
||
|
|
let half_w = width / 2.0;
|
||
|
|
let half_h = height / 2.0;
|
||
|
|
|
||
|
|
// Вертикальные линии сетки
|
||
|
|
for col in 0..=GRID_COLS as u32 {
|
||
|
|
let x = -half_w + col as f32 * SLOT_SIZE;
|
||
|
|
gizmos.line_2d(
|
||
|
|
Vec2::new(x, -half_h),
|
||
|
|
Vec2::new(x, half_h),
|
||
|
|
Color::srgba(0.4, 0.4, 0.4, 0.4),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Горизонтальные линии сетки
|
||
|
|
for row in 0..=GRID_ROWS as u32 {
|
||
|
|
let y = -half_h + row as f32 * SLOT_SIZE;
|
||
|
|
gizmos.line_2d(
|
||
|
|
Vec2::new(-half_w, y),
|
||
|
|
Vec2::new(half_w, y),
|
||
|
|
Color::srgba(0.4, 0.4, 0.4, 0.4),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Точки в центрах слотов (удобно для сверки логики)
|
||
|
|
for row in 0..GRID_ROWS as u32 {
|
||
|
|
for col in 0..GRID_COLS as u32 {
|
||
|
|
let cx = -half_w + col as f32 * SLOT_SIZE + SLOT_SIZE / 2.0;
|
||
|
|
let cy = -half_h + row as f32 * SLOT_SIZE + SLOT_SIZE / 2.0;
|
||
|
|
gizmos.circle_2d(Vec2::new(cx, cy), 4.0, Color::srgba(1.0, 0.9, 0.0, 0.7));
|
||
|
|
|
||
|
|
let coord_text = format!("{:.0}, {:.0}", cx, cy);
|
||
|
|
commands.spawn((
|
||
|
|
Text2d::new(cx.to_string()),
|
||
|
|
TextFont {
|
||
|
|
font_size: 14.0,
|
||
|
|
..default()
|
||
|
|
},
|
||
|
|
TextColor(Color::srgb(237.0 / 255.0, 21.0 / 255.0, 127.0 / 255.0)),
|
||
|
|
Transform::from_translation(Vec3::new(cx, cy + 8.0, 100.0)), // z=100, чтобы было поверх всего
|
||
|
|
DebugSlotNumber,
|
||
|
|
));
|
||
|
|
|
||
|
|
commands.spawn((
|
||
|
|
Text2d::new(cy.to_string()),
|
||
|
|
TextFont {
|
||
|
|
font_size: 14.0,
|
||
|
|
..default()
|
||
|
|
},
|
||
|
|
TextColor(Color::srgb(237.0 / 255.0, 21.0 / 255.0, 127.0 / 255.0)),
|
||
|
|
Transform::from_translation(Vec3::new(cx, cy - 8.0, 100.0)), // z=100, чтобы было поверх всего
|
||
|
|
DebugSlotNumber,
|
||
|
|
));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|