@@ -19,17 +19,18 @@ impl Plugin for LivecodePlugin {
1919 fn build ( & self , app : & mut App ) {
2020 app. init_asset :: < Sketch > ( )
2121 . init_asset_loader :: < SketchLoader > ( )
22+ // TODO: this could be switched to Message
2223 . insert_resource ( SketchNeedsReload ( false ) )
23- . add_systems ( PreStartup , load_current_sketch)
24- . add_systems ( Update , sketch_update_handler) ;
24+ . add_systems ( PreStartup , load_current_sketch) ;
25+ // .add_systems(Update, sketch_update_handler);
2526 }
2627}
2728
2829// TODO: A better name is possible
29- fn sketch_update_handler (
30+ pub fn sketch_update_handler (
3031 mut events : MessageReader < AssetEvent < Sketch > > ,
31- mut needs_reload : ResMut < SketchNeedsReload > ,
32- ) {
32+ sketches : Res < Assets < Sketch > > ,
33+ ) -> Option < Sketch > {
3334 for event in events. read ( ) {
3435 match event {
3536 AssetEvent :: Added { id } => {
@@ -38,7 +39,11 @@ fn sketch_update_handler(
3839 AssetEvent :: Modified { id } => {
3940 info ! ( "Modified: {id}" ) ;
4041 // we want to emit some event to bevy??
41- needs_reload. 0 = true ;
42+ // needs_reload.0 = true;
43+ if let Some ( sketch) = sketches. get ( * id) {
44+ let sketch = sketch. clone ( ) ;
45+ return Some ( sketch) ;
46+ }
4247 }
4348 AssetEvent :: Removed { id } => {
4449 info ! ( "Removed: {id}" )
@@ -51,6 +56,8 @@ fn sketch_update_handler(
5156 }
5257 }
5358 }
59+
60+ None
5461}
5562
5663fn load_current_sketch ( mut commands : Commands , asset_server : Res < AssetServer > ) {
@@ -70,9 +77,10 @@ pub struct SketchRoot(pub Handle<Sketch>);
7077///
7178/// The `Sketch` asset contains the raw source code as a string. It does not interpret
7279/// or execute the code — that responsibility belongs to language-specific crates.
73- #[ derive( Asset , TypePath , Debug ) ]
80+ #[ derive( Asset , Clone , TypePath , Debug ) ]
7481pub struct Sketch {
75- source : String ,
82+ // TODO: should this be &str ?
83+ pub source : String ,
7684}
7785
7886/// Loads sketch files from disk.
0 commit comments