webview displays in gps map with wry, happy 4th, boom boom (#4)

Co-authored-by: geoffsee <>
This commit is contained in:
Geoff Seemueller
2025-07-04 21:11:38 -04:00
committed by GitHub
parent 71efeb4c46
commit 73ee3add8d
8 changed files with 3060 additions and 116 deletions

14
.aiignore Normal file
View File

@@ -0,0 +1,14 @@
# An .aiignore file follows the same syntax as a .gitignore file.
# .gitignore documentation: https://git-scm.com/docs/gitignore
# Junie will ask for explicit approval before view or edit the file or file within a directory listed in .aiignore.
# Only files contents is protected, Junie is still allowed to view file names even if they are listed in .aiignore.
# Be aware that the files you included in .aiignore can still be accessed by Junie in two cases:
# - If Brave Mode is turned on.
# - If a command has been added to the Allowlist — Junie will not ask for confirmation, even if it accesses - files and folders listed in .aiignore.
target
**/**/dist
.idea
.github
Cargo.lock
LICENSE
yachtpit.png

1
.gitignore vendored
View File

@@ -33,3 +33,4 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
# Finder (MacOS) folder config
.DS_Store
/.junie/

3089
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -62,11 +62,14 @@ webbrowser = { version = "1", features = ["hardened"] }
systems = { path = "../systems" }
components = { path = "../components" }
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["Document", "Element", "HtmlElement", "Window"] }
reqwest = { version = "0.12", features = ["json"] }
web-sys = { version = "0.3.53", features = ["Document", "Element", "HtmlElement", "Window"] }
# Platform-specific tokio features
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.0", features = ["rt", "rt-multi-thread"] }
image = "0.25"
winit = "0.30"
bevy_webview_wry = { version = "0.4", default-features = false, features = ["api"] }
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { version = "1.0", features = ["rt"] }

View File

@@ -8,6 +8,7 @@ use bevy::prelude::*;
use std::collections::HashMap;
use systems::{VesselSystem, SystemInteraction, SystemStatus};
use components::{VesselData, SystemIndicator, SystemDisplayArea};
use crate::ui::{spawn_gps_map_window, GpsMapState};
// use crate::ui::{spawn_gps_map_window, GpsMapState};
/// Resource for managing all yacht systems
@@ -123,7 +124,7 @@ fn update_all_systems(
fn handle_system_indicator_interactions(
mut commands: Commands,
mut system_manager: ResMut<SystemManager>,
// mut gps_map_state: ResMut<GpsMapState>,
mut gps_map_state: ResMut<GpsMapState>,
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor, &SystemIndicator),
(Changed<Interaction>, With<Button>),
@@ -139,9 +140,9 @@ fn handle_system_indicator_interactions(
);
// If GPS system is selected, spawn the map window
// if indicator.system_id == "gps" {
// spawn_gps_map_window(&mut commands, &mut gps_map_state);
// }
if indicator.system_id == "gps" {
spawn_gps_map_window(&mut commands, &mut gps_map_state);
}
*background_color = BackgroundColor(Color::linear_rgb(0.0, 0.3, 0.5));
}

View File

@@ -45,6 +45,7 @@ impl Plugin for GamePlugin {
SystemManagerPlugin,
PlayerPlugin,
))
.add_systems(OnEnter(GameState::Playing), (setup_instrument_cluster, initialize_vessel_systems));
#[cfg(debug_assertions)]

View File

@@ -8,6 +8,7 @@ use bevy::winit::WinitWindows;
use bevy::DefaultPlugins;
use yachtpit::GamePlugin;
use std::io::Cursor;
use bevy_webview_wry::WebviewWryPlugin;
use winit::window::Icon;
fn main() {
@@ -33,9 +34,9 @@ fn main() {
)
.add_plugins(GamePlugin)
.add_systems(Startup, set_window_icon)
.add_plugins(WebviewWryPlugin::default())
.run();
}
// Sets the icon on windows and X11
fn set_window_icon(
windows: NonSend<WinitWindows>,

View File

@@ -1,6 +1,10 @@
use bevy::prelude::*;
use bevy::render::view::RenderLayers;
use bevy::window::Window;
use std::collections::HashMap;
use bevy_webview_wry::prelude::*;
/// Render layer for GPS map entities to isolate them from other cameras
const GPS_MAP_LAYER: usize = 1;
/// Component to mark the GPS map window
#[derive(Component)]
@@ -79,7 +83,7 @@ fn update_map_tiles(
// For now, we'll create a simple placeholder map
// In a full implementation, this would fetch actual OSM tiles
if map_tiles.is_empty() {
if map_tiles.is_empty() && gps_map_state.window_id.is_some() {
spawn_placeholder_map(&mut commands, &asset_server);
}
}
@@ -96,35 +100,34 @@ fn spawn_placeholder_map(commands: &mut Commands, _asset_server: &Res<AssetServe
};
commands.spawn((
GpsMapWindow,
Transform::from_translation(Vec3::new(x as f32 * 100.0, y as f32 * 100.0, 0.0)),
GlobalTransform::default(),
Sprite {
color,
custom_size: Some(Vec2::new(256.0, 256.0)),
custom_size: Some(Vec2::new(100.0, 100.0)),
..default()
},
Transform::from_translation(Vec3::new(
x as f32 * 256.0,
y as f32 * 256.0,
0.0,
)),
MapTile {
x,
y,
x: x as i32,
y: y as i32,
zoom: 10,
},
GpsMapWindow,
RenderLayers::layer(GPS_MAP_LAYER),
));
}
}
// Add a marker for the vessel position
commands.spawn((
Sprite {
color: Color::linear_rgb(1.0, 0.0, 0.0),
custom_size: Some(Vec2::new(20.0, 20.0)),
..default()
},
Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
// Sprite {
// color: Color::linear_rgb(1.0, 0.0, 0.0),
// custom_size: Some(Vec2::new(20.0, 20.0)),
// ..default()
// },
// Transform::from_translation(Vec3::new(0.0, 0.0, 1.0)),
GpsMapWindow,
RenderLayers::layer(GPS_MAP_LAYER),
));
}
@@ -158,10 +161,27 @@ pub fn spawn_gps_map_window(
target: bevy::render::camera::RenderTarget::Window(bevy::window::WindowRef::Entity(window_entity)),
..default()
},
RenderLayers::layer(GPS_MAP_LAYER),
GpsMapWindow,
));
gps_map_state.window_id = Some(window_entity);
spawn_gps_webview(commands, gps_map_state);
info!("GPS map window spawned with entity: {:?}", window_entity);
}
fn spawn_gps_webview(
commands: &mut Commands,
gps_map_state: &mut ResMut<GpsMapState>,
) {
if let Some(win) = gps_map_state.window_id {
commands
.entity(win)
.insert(Webview::Uri(WebviewUri::new(
"https://www.openstreetmap.org/", // or any URL you like
)));
}
}