@@ -6,6 +6,7 @@ use bevy::{
66 io:: { AssetSourceId , Reader } ,
77 } ,
88 prelude:: * ,
9+ render:: Extract ,
910} ;
1011use std:: path:: { Path , PathBuf } ;
1112
@@ -15,40 +16,54 @@ pub struct LivecodePlugin;
1516impl Plugin for LivecodePlugin {
1617 fn build ( & self , app : & mut App ) {
1718 app. init_asset :: < Sketch > ( )
18- . init_asset_loader :: < SketchLoader > ( )
19- . add_systems ( Startup , load_current_sketch) ;
19+ . init_asset_loader :: < SketchLoader > ( ) ;
20+
21+ app. add_systems ( PreStartup , load_current_sketch) ;
2022 // .add_systems(Update, test_system);
21- let render_app = app. sub_app_mut ( bevy:: render:: RenderApp ) ;
22- render_app. add_systems ( ExtractSchedule , test_system) ;
2323 }
2424}
2525
26- fn test_system ( ) {
27- info ! ( "DEBUG: calling test_system" ) ;
28- assert ! ( false ) ;
26+ fn test_system ( mut events : Extract < MessageReader < AssetEvent < Sketch > > > ) {
27+ for event in events. read ( ) {
28+ match event {
29+ AssetEvent :: Added { id } => {
30+ info ! ( "Added: {id}" )
31+ }
32+ AssetEvent :: Modified { id } => {
33+ info ! ( "Modified: {id}" )
34+ }
35+ AssetEvent :: Removed { id } => {
36+ info ! ( "Removed: {id}" )
37+ }
38+ AssetEvent :: Unused { id } => {
39+ info ! ( "Unused: {id}" )
40+ }
41+ AssetEvent :: LoadedWithDependencies { id } => {
42+ info ! ( "LoadedWithDependencies: {id}" )
43+ }
44+ }
45+ }
2946}
3047
31- fn load_current_sketch ( asset_server : Res < AssetServer > ) {
48+ fn load_current_sketch ( mut commands : Commands , asset_server : Res < AssetServer > ) {
3249 info ! ( "DEBUG: calling load_current_sketch" ) ;
3350 let path = Path :: new ( "rectangle.py" ) ;
3451 let source = AssetSourceId :: from ( "sketch_directory" ) ;
3552 let asset_path = AssetPath :: from_path ( path) . with_source ( source) ;
36- let _h: Handle < Sketch > = asset_server. load ( asset_path) ;
53+ let sketch_handle: Handle < Sketch > = asset_server. load ( asset_path) ;
54+ commands. spawn ( SketchRoot ( sketch_handle) ) ;
3755}
3856
57+ /// `SketchRoot` is what will be spawned and will contain a `Handle` to the `Sketch`
58+ #[ derive( Component ) ]
59+ pub struct SketchRoot ( pub Handle < Sketch > ) ;
60+
3961/// A sketch source file loaded as a Bevy asset.
4062///
4163/// The `Sketch` asset contains the raw source code as a string. It does not interpret
4264/// or execute the code — that responsibility belongs to language-specific crates.
4365#[ derive( Asset , TypePath , Debug ) ]
44- pub struct Sketch {
45- /// The source code contents of the sketch file.
46- pub source : String ,
47-
48- /// The original file path.
49- pub path : PathBuf ,
50- }
51-
66+ pub struct Sketch ;
5267/// Loads sketch files from disk.
5368///
5469/// Currently supports `.py` files, but the loader is designed to be extended
@@ -79,7 +94,7 @@ impl AssetLoader for SketchLoader {
7994 let asset_path = load_context. path ( ) ;
8095 let path: PathBuf = asset_path. path ( ) . to_path_buf ( ) ;
8196
82- Ok ( Sketch { source , path } )
97+ Ok ( Sketch )
8398 }
8499
85100 fn extensions ( & self ) -> & [ & str ] {
0 commit comments