1+ pub mod config;
12pub mod error;
23mod graphics;
34pub mod image;
@@ -6,6 +7,8 @@ mod surface;
67
78use std:: { cell:: RefCell , num:: NonZero , path:: PathBuf , sync:: OnceLock } ;
89
10+ use config:: * ;
11+
912#[ cfg( feature = "python" ) ]
1013use bevy:: asset:: io:: AssetSourceBuilder ;
1114#[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -204,7 +207,7 @@ pub fn surface_resize(graphics_entity: Entity, width: u32, height: u32) -> error
204207 } )
205208}
206209
207- fn create_app ( asset_path : Option < & str > ) -> App {
210+ fn create_app ( _config : Config ) -> App {
208211 let mut app = App :: new ( ) ;
209212
210213 #[ cfg( not( target_arch = "wasm32" ) ) ]
@@ -230,11 +233,13 @@ fn create_app(asset_path: Option<&str>) -> App {
230233 } ) ;
231234
232235 #[ cfg( feature = "python" ) ]
233- app. register_asset_source (
234- "assets_directory" ,
235- // TODO: set this path to the directory containing the main sketch file
236- AssetSourceBuilder :: platform_default ( asset_path. unwrap ( ) , None ) ,
237- ) ;
236+ {
237+ let asset_path = _config. get ( ConfigKey :: AssetRootPath ) . unwrap ( ) ;
238+ app. register_asset_source (
239+ "assets_directory" ,
240+ AssetSourceBuilder :: platform_default ( asset_path, None ) ,
241+ ) ;
242+ }
238243
239244 app. add_plugins ( plugins) ;
240245 app. add_plugins ( ( ImagePlugin , GraphicsPlugin , SurfacePlugin ) ) ;
@@ -268,13 +273,15 @@ fn set_app(app: App) {
268273/// be called concurrently from multiple threads.
269274/// asset_path is Optional because only python needs to use it.
270275#[ cfg( not( target_arch = "wasm32" ) ) ]
271- pub fn init ( asset_path : Option < & str > ) -> error:: Result < ( ) > {
276+ pub fn init ( config : Option < Config > ) -> error:: Result < ( ) > {
277+ let config = config. unwrap_or_else ( || Config :: new ( ) ) ;
278+
272279 setup_tracing ( ) ?;
273280 if is_already_init ( ) ? {
274281 return Ok ( ( ) ) ;
275282 }
276283
277- let mut app = create_app ( asset_path ) ;
284+ let mut app = create_app ( config ) ;
278285 app. finish ( ) ;
279286 app. cleanup ( ) ;
280287 set_app ( app) ;
0 commit comments