Skip to content

Commit ea33487

Browse files
committed
Add SketchRootPath ConfigKey
1 parent 7871b99 commit ea33487

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

crates/processing_pyo3/src/graphics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ impl Graphics {
121121

122122
let mut config = Config::new();
123123
config.set(ConfigKey::AssetRootPath, asset_path.to_string());
124+
config.set(
125+
// TODO: this needs to be handed to us by python
126+
ConfigKey::SketchRootPath,
127+
"/home/moon/Code/libprocessing/crates/processing_pyo3/examples".to_string(),
128+
);
124129
init(config).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
125130

126131
let surface = glfw_ctx

crates/processing_render/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::collections::HashMap;
88
#[derive(Clone, Hash, Eq, PartialEq)]
99
pub enum ConfigKey {
1010
AssetRootPath,
11+
SketchRootPath,
1112
}
1213

1314
// TODO: Consider Box<dyn Any> instead of String

crates/processing_render/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ mod graphics;
55
pub mod image;
66
pub mod light;
77
pub mod render;
8+
pub mod sketch;
89
mod surface;
910
pub mod transform;
1011

@@ -245,6 +246,15 @@ fn create_app(config: Config) -> App {
245246
}
246247

247248
app.add_plugins(plugins);
249+
if let Some(sketch_path) = config.get(ConfigKey::SketchRootPath) {
250+
println!("DEBUG SKETCH PATH = {sketch_path}");
251+
app.register_asset_source(
252+
"sketch_directory",
253+
AssetSourceBuilder::platform_default(sketch_path, None),
254+
)
255+
.add_plugins(sketch::LivecodePlugin);
256+
}
257+
248258
app.add_plugins((
249259
ImagePlugin,
250260
GraphicsPlugin,

crates/processing_render/src/sketch.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,35 @@
11
//! A Sketch asset represents a source file containing user code for a Processing sketch.
2-
//!
3-
//! Sketches are loaded through Bevy's asset system, which provides automatic file watching
4-
//! and change detection. This enables hot-reloading workflows where artists can edit their
5-
//! sketch code and see changes reflected immediately without restarting.
6-
//!
7-
//! This module is intentionally language-agnostic — it only handles loading source text from
8-
//! disk. Language-specific crates (like `processing_pyo3`) are responsible for executing the
9-
//! source and binding it to the Processing API.
102
113
use bevy::{
12-
asset::{AssetLoader, LoadContext, io::Reader},
4+
asset::{
5+
AssetLoader, AssetPath, LoadContext,
6+
io::{AssetSourceId, Reader},
7+
},
138
prelude::*,
149
};
15-
use std::path::PathBuf;
10+
use std::path::{Path, PathBuf};
1611

1712
/// Plugin that registers the Sketch asset type and its loader.
1813
pub struct LivecodePlugin;
1914

2015
impl Plugin for LivecodePlugin {
2116
fn build(&self, app: &mut App) {
2217
app.init_asset::<Sketch>()
23-
.init_asset_loader::<SketchLoader>();
18+
.init_asset_loader::<SketchLoader>()
19+
.add_systems(Startup, load_current_sketch);
2420
}
2521
}
2622

23+
fn load_current_sketch(asset_server: Res<AssetServer>) {
24+
let path = Path::new("rectangle.py");
25+
let source = AssetSourceId::from("sketch_directory");
26+
let _asset_path = AssetPath::from_path(path).with_source(source);
27+
28+
dbg!("OKOKOKOK {:?}", _asset_path);
29+
30+
let _h: Handle<Sketch> = asset_server.load(path);
31+
}
32+
2733
/// A sketch source file loaded as a Bevy asset.
2834
///
2935
/// The `Sketch` asset contains the raw source code as a string. It does not interpret

0 commit comments

Comments
 (0)