11use bevy:: {
22 app:: AppExit ,
3- prelude:: {
4- debug, App , AssetServer , Camera2dBundle , Color , Commands , Component , DefaultPlugins ,
5- Entity , EventReader , EventWriter , HorizontalAlign , ImagePlugin , ParamSet , PluginGroup ,
6- Query , Res , ResMut , Resource , SpriteBundle , Text as BevyText , Text2dBundle , TextAlignment ,
7- TextStyle , Transform , Vec2 , VerticalAlign , Windows ,
8- } ,
3+ prelude:: { Text as BevyText , * } ,
94 time:: Time ,
105 utils:: HashMap ,
11- window:: { close_on_esc, WindowPlugin } ,
6+ window:: { close_on_esc, PrimaryWindow , WindowPlugin } ,
127} ;
138use bevy_prototype_lyon:: prelude:: * ;
149use std:: {
@@ -29,7 +24,7 @@ use crate::{
2924} ;
3025
3126// Public re-export
32- pub use bevy:: window:: { WindowDescriptor , WindowMode , WindowResizeConstraints } ;
27+ pub use bevy:: window:: { Cursor , Window , WindowMode , WindowResolution } ;
3328
3429/// Engine is the primary way that you will interact with Rusty Engine. Each frame this struct
3530/// is provided to the "logic" functions (or closures) that you provided to [`Game::add_logic`]. The
@@ -172,11 +167,19 @@ fn add_collider_lines(commands: &mut Commands, sprite: &mut Sprite) {
172167 let line = path_builder. build ( ) ;
173168 let transform = sprite. bevy_transform ( ) ;
174169 commands
175- . spawn ( GeometryBuilder :: build_as (
176- & line,
177- DrawMode :: Stroke ( StrokeMode :: new ( Color :: WHITE , 1.0 / transform. scale . x ) ) ,
178- transform,
170+ . spawn ( (
171+ ShapeBundle {
172+ path : GeometryBuilder :: new ( ) . add ( & line) . build ( ) ,
173+ transform,
174+ ..Default :: default ( )
175+ } ,
176+ Stroke :: new ( Color :: WHITE , 1.0 / transform. scale . x ) ,
179177 ) )
178+ // .spawn(GeometryBuilder::build_as(
179+ // &line,
180+ // DrawMode::Stroke(StrokeMode::new(Color::WHITE, 1.0 / transform.scale.x)),
181+ // transform,
182+ // ))
180183 . insert ( ColliderLines {
181184 sprite_label : sprite. label . clone ( ) ,
182185 } ) ;
@@ -222,10 +225,7 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
222225 color : Color :: WHITE ,
223226 } ,
224227 )
225- . with_alignment ( TextAlignment {
226- vertical : VerticalAlign :: Center ,
227- horizontal : HorizontalAlign :: Center ,
228- } ) ,
228+ . with_alignment ( TextAlignment :: Center ) ,
229229 transform,
230230 ..Default :: default ( )
231231 } ,
@@ -235,14 +235,18 @@ pub fn add_texts(commands: &mut Commands, asset_server: &Res<AssetServer>, engin
235235
236236/// system - update current window dimensions in the engine, because people resize windows
237237#[ doc( hidden) ]
238- pub fn update_window_dimensions ( windows : Res < Windows > , mut engine : ResMut < Engine > ) {
239- // It's possible to not have window dimensions for the first frame or two
240- if let Some ( window) = windows. get_primary ( ) {
241- let screen_dimensions = Vec2 :: new ( window. width ( ) , window. height ( ) ) ;
242- if screen_dimensions != engine. window_dimensions {
243- engine. window_dimensions = screen_dimensions;
244- debug ! ( "Set window dimensions: {}" , engine. window_dimensions) ;
245- }
238+ pub fn update_window_dimensions (
239+ window_query : Query < & Window , With < PrimaryWindow > > ,
240+ mut engine : ResMut < Engine > ,
241+ ) {
242+ // It's possible to not have a window for the first frame or two
243+ let Ok ( window) = window_query. get_single ( ) else {
244+ return ;
245+ } ;
246+ let screen_dimensions = Vec2 :: new ( window. width ( ) , window. height ( ) ) ;
247+ if screen_dimensions != engine. window_dimensions {
248+ engine. window_dimensions = screen_dimensions;
249+ debug ! ( "Set window dimensions: {}" , engine. window_dimensions) ;
246250 }
247251}
248252
@@ -264,7 +268,7 @@ pub struct Game<S: Resource + Send + Sync + 'static> {
264268 app : App ,
265269 engine : Engine ,
266270 logic_functions : LogicFuncVec < S > ,
267- window_descriptor : WindowDescriptor ,
271+ window : Window ,
268272}
269273
270274impl < S : Resource + Send + Sync + ' static > Default for Game < S > {
@@ -273,7 +277,7 @@ impl<S: Resource + Send + Sync + 'static> Default for Game<S> {
273277 app : App :: new ( ) ,
274278 engine : Engine :: default ( ) ,
275279 logic_functions : LogicFuncVec ( vec ! [ ] ) ,
276- window_descriptor : WindowDescriptor {
280+ window : Window {
277281 title : "Rusty Engine" . into ( ) ,
278282 ..Default :: default ( )
279283 } ,
@@ -294,8 +298,8 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
294298 /// Use this to set properties of the native OS window before running the game. See the
295299 /// [window](https://github.com/CleanCut/rusty_engine/blob/main/examples/window.rs) example for
296300 /// more information.
297- pub fn window_settings ( & mut self , window_descriptor : WindowDescriptor ) -> & mut Self {
298- self . window_descriptor = window_descriptor ;
301+ pub fn window_settings ( & mut self , window : Window ) -> & mut Self {
302+ self . window = window ;
299303 self
300304 }
301305
@@ -307,7 +311,7 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
307311 . add_plugins (
308312 DefaultPlugins
309313 . set ( WindowPlugin {
310- window : self . window_descriptor . clone ( ) ,
314+ primary_window : Some ( self . window . clone ( ) ) ,
311315 ..Default :: default ( )
312316 } )
313317 . set ( ImagePlugin :: default_nearest ( ) ) ,
@@ -322,7 +326,7 @@ impl<S: Resource + Send + Sync + 'static> Game<S> {
322326 . add_plugin ( PhysicsPlugin )
323327 //.insert_resource(ReportExecutionOrderAmbiguities) // for debugging
324328 . add_system ( update_window_dimensions)
325- . add_system ( game_logic_sync :: < S > ) // TODO: ensure after update_window_dimensions
329+ . add_system ( game_logic_sync :: < S > ) // this should happen after all the rest of the systems
326330 . add_startup_system ( setup) ;
327331 self . app . world . spawn ( Camera2dBundle :: default ( ) ) ;
328332 let engine = std:: mem:: take ( & mut self . engine ) ;
@@ -359,7 +363,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
359363 mut query_set : ParamSet < (
360364 Query < ( Entity , & mut Sprite , & mut Transform ) > ,
361365 Query < ( Entity , & mut Text , & mut Transform , & mut BevyText ) > ,
362- Query < ( Entity , & mut DrawMode , & mut Transform , & ColliderLines ) > ,
366+ Query < ( Entity , & mut Stroke , & mut Transform , & ColliderLines ) > ,
363367 ) > ,
364368) {
365369 // Update this frame's timing info
@@ -429,7 +433,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
429433 }
430434 }
431435 // Update transform & line width
432- for ( _, mut draw_mode , mut transform, collider_lines) in query_set. p2 ( ) . iter_mut ( ) {
436+ for ( _, mut stroke , mut transform, collider_lines) in query_set. p2 ( ) . iter_mut ( ) {
433437 if let Some ( sprite) = engine. sprites . get ( & collider_lines. sprite_label ) {
434438 * transform = sprite. bevy_transform ( ) ;
435439 // We want collider lines to appear on top of the sprite they are for, so they need a
@@ -438,10 +442,7 @@ fn game_logic_sync<S: Resource + Send + Sync + 'static>(
438442 }
439443 // Stroke line width gets scaled with the transform, but we want it to appear to be the same
440444 // regardless of scale, so we have to counter the scale.
441- if let DrawMode :: Stroke ( ref mut stroke_mode) = * draw_mode {
442- let line_width = 1.0 / transform. scale . x ;
443- * stroke_mode = StrokeMode :: new ( Color :: WHITE , line_width) ;
444- }
445+ stroke. options . line_width = 1.0 / transform. scale . x ;
445446 }
446447 }
447448 engine. last_show_colliders = engine. show_colliders ;
0 commit comments