Skip to content

Commit 9d0947e

Browse files
committed
Add SketchRootPath ConfigKey
1 parent ecd8dea commit 9d0947e

4 files changed

Lines changed: 33 additions & 11 deletions

File tree

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
@@ -4,6 +4,7 @@ pub mod geometry;
44
mod graphics;
55
pub mod image;
66
pub mod render;
7+
pub mod sketch;
78
mod surface;
89

910
use std::{cell::RefCell, num::NonZero, path::PathBuf, sync::OnceLock};
@@ -242,6 +243,15 @@ fn create_app(config: Config) -> App {
242243
}
243244

244245
app.add_plugins(plugins);
246+
if let Some(sketch_path) = config.get(ConfigKey::SketchRootPath) {
247+
println!("DEBUG SKETCH PATH = {sketch_path}");
248+
app.register_asset_source(
249+
"sketch_directory",
250+
AssetSourceBuilder::platform_default(sketch_path, None),
251+
)
252+
.add_plugins(sketch::LivecodePlugin);
253+
}
254+
245255
app.add_plugins((
246256
ImagePlugin,
247257
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)