cleanup
Some checks failed
Rust / build (push) Failing after 4s

This commit is contained in:
2026-03-13 18:02:11 -04:00
parent e3ddd3b5d4
commit b567dd00fd
24 changed files with 456 additions and 299 deletions

View File

@@ -1,5 +1,5 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_rapier3d::{plugin::RapierContext, prelude::QueryFilter};
use bevy_rapier3d::{plugin::ReadRapierContext, prelude::QueryFilter};
use shared::{
resources::{TileContact, TileUnderCursor},
tags::MainCamera,
@@ -7,8 +7,10 @@ use shared::{
use world_generation::{hex_utils::HexCoord, prelude::Map, states::GeneratorState};
pub struct TileSelectionPlugin;
impl Plugin for TileSelectionPlugin {
fn build(&self, app: &mut App) {
impl Plugin for TileSelectionPlugin
{
fn build(&self, app: &mut App)
{
app.init_resource::<TileUnderCursor>();
app.add_systems(
PreUpdate,
@@ -20,42 +22,53 @@ impl Plugin for TileSelectionPlugin {
fn update_tile_under_cursor(
cam_query: Single<(&GlobalTransform, &Camera), With<MainCamera>>,
window: Single<&Window, With<PrimaryWindow>>,
// rapier_context: RapierContext,
rapier: ReadRapierContext,
map: Res<Map>,
mut tile_under_cursor: ResMut<TileUnderCursor>,
) {
)
{
let (cam_transform, camera) = cam_query.into_inner();
let Some(cursor_pos) = window.cursor_position() else {
let Some(cursor_pos) = window.cursor_position()
else
{
return;
};
let Ok(cam_ray) = camera.viewport_to_world(cam_transform, cursor_pos) else {
let Ok(cam_ray) = camera.viewport_to_world(cam_transform, cursor_pos)
else
{
return;
};
// let collision = rapier_context.cast_ray(
// cam_ray.origin,
// cam_ray.direction.into(),
// 500.,
// true,
// QueryFilter::only_fixed(),
// );
let ctx = rapier.single().expect("Failed to get rapier read context");
// if let Some((_e, dist)) = collision {
// let contact_point = cam_ray.get_point(dist);
// let contact_coord = HexCoord::from_world_pos(contact_point);
// //todo: handle correct tile detection when contacting a tile from the side
// if !map.is_in_bounds(&contact_coord) {
// tile_under_cursor.0 = None;
// return;
// }
// let surface = map.sample_height(&contact_coord);
// tile_under_cursor.0 = Some(TileContact::new(
// contact_coord,
// contact_point,
// contact_coord.to_world(surface),
// ));
// } else {
// tile_under_cursor.0 = None;
// }
let collision = ctx.cast_ray(
cam_ray.origin,
cam_ray.direction.into(),
500.,
true,
QueryFilter::only_fixed(),
);
if let Some((_e, dist)) = collision
{
let contact_point = cam_ray.get_point(dist);
let contact_coord = HexCoord::from_world_pos(contact_point);
//todo: handle correct tile detection when contacting a tile from the side
if !map.is_in_bounds(&contact_coord)
{
tile_under_cursor.0 = None;
return;
}
let surface = map.sample_height(&contact_coord);
tile_under_cursor.0 = Some(TileContact::new(
contact_coord,
contact_point,
contact_coord.to_world(surface),
));
}
else
{
tile_under_cursor.0 = None;
}
}