Skip to content

Commit dd57a85

Browse files
committed
fix AssetEvent handler for Sketch entities
1 parent 709cd4c commit dd57a85

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

crates/processing_render/src/sketch.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use bevy::{
66
io::{AssetSourceId, Reader},
77
},
88
prelude::*,
9-
render::Extract,
109
};
11-
use std::path::{Path, PathBuf};
10+
use std::path::Path;
1211

1312
/// Plugin that registers the Sketch asset type and its loader.
1413
pub struct LivecodePlugin;
@@ -18,12 +17,13 @@ impl Plugin for LivecodePlugin {
1817
app.init_asset::<Sketch>()
1918
.init_asset_loader::<SketchLoader>();
2019

21-
app.add_systems(PreStartup, load_current_sketch);
22-
// .add_systems(Update, test_system);
20+
app.add_systems(PreStartup, load_current_sketch)
21+
.add_systems(Update, sketch_update_handler);
2322
}
2423
}
2524

26-
fn test_system(mut events: Extract<MessageReader<AssetEvent<Sketch>>>) {
25+
// TODO: A better name is possible
26+
fn sketch_update_handler(mut events: MessageReader<AssetEvent<Sketch>>) {
2727
for event in events.read() {
2828
match event {
2929
AssetEvent::Added { id } => {
@@ -63,7 +63,10 @@ pub struct SketchRoot(pub Handle<Sketch>);
6363
/// The `Sketch` asset contains the raw source code as a string. It does not interpret
6464
/// or execute the code — that responsibility belongs to language-specific crates.
6565
#[derive(Asset, TypePath, Debug)]
66-
pub struct Sketch;
66+
pub struct Sketch {
67+
source: String,
68+
}
69+
6770
/// Loads sketch files from disk.
6871
///
6972
/// Currently supports `.py` files, but the loader is designed to be extended
@@ -80,7 +83,7 @@ impl AssetLoader for SketchLoader {
8083
&self,
8184
reader: &mut dyn Reader,
8285
_settings: &Self::Settings,
83-
load_context: &mut LoadContext<'_>,
86+
_load_context: &mut LoadContext<'_>,
8487
) -> Result<Self::Asset, Self::Error> {
8588
let mut source = String::new();
8689

@@ -91,10 +94,9 @@ impl AssetLoader for SketchLoader {
9194
source = utf8.to_string();
9295
}
9396

94-
let asset_path = load_context.path();
95-
let path: PathBuf = asset_path.path().to_path_buf();
97+
info!(source);
9698

97-
Ok(Sketch)
99+
Ok(Sketch { source })
98100
}
99101

100102
fn extensions(&self) -> &[&str] {

0 commit comments

Comments
 (0)