Skip to content

Commit 2098b83

Browse files
authored
Pyo3/some sketch reloading (#64)
1 parent f411d2d commit 2098b83

File tree

8 files changed

+390
-14
lines changed

8 files changed

+390
-14
lines changed

Cargo.lock

Lines changed: 169 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type_complexity = "allow"
2121
too_many_arguments = "allow"
2222

2323
[workspace.dependencies]
24-
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main" }
24+
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", features = ["file_watcher"] }
2525
processing = { path = "." }
2626
processing_pyo3 = { path = "crates/processing_pyo3" }
2727
processing_render = { path = "crates/processing_render" }

crates/processing_pyo3/examples/rectangle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def draw():
77
background(220)
88

99
fill(255, 0, 100)
10-
stroke(0)
10+
stroke(1)
1111
stroke_weight(2)
1212
rect(100, 100, 200, 150)
1313

crates/processing_pyo3/src/graphics.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ impl Topology {
6161
}
6262
}
6363

64+
#[pyclass]
65+
pub struct Sketch {
66+
pub source: String,
67+
}
68+
6469
#[pymethods]
6570
impl Geometry {
6671
#[new]
@@ -115,12 +120,20 @@ impl Drop for Graphics {
115120
#[pymethods]
116121
impl Graphics {
117122
#[new]
118-
pub fn new(width: u32, height: u32, asset_path: &str) -> PyResult<Self> {
123+
pub fn new(
124+
width: u32,
125+
height: u32,
126+
asset_path: &str,
127+
sketch_root_path: &str,
128+
sketch_file_name: &str,
129+
) -> PyResult<Self> {
119130
let glfw_ctx =
120131
GlfwContext::new(width, height).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
121132

122133
let mut config = Config::new();
123134
config.set(ConfigKey::AssetRootPath, asset_path.to_string());
135+
config.set(ConfigKey::SketchRootPath, sketch_root_path.to_string());
136+
config.set(ConfigKey::SketchFileName, sketch_file_name.to_string());
124137
init(config).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
125138

126139
let surface = glfw_ctx
@@ -141,6 +154,17 @@ impl Graphics {
141154
})
142155
}
143156

157+
pub fn poll_for_sketch_update(&self) -> PyResult<Sketch> {
158+
match poll_for_sketch_updates().map_err(|_| PyRuntimeError::new_err("SKETCH UPDATE ERR"))? {
159+
Some(sketch) => Ok(Sketch {
160+
source: sketch.source,
161+
}),
162+
None => Ok(Sketch {
163+
source: "".to_string(),
164+
}),
165+
}
166+
}
167+
144168
pub fn background(&self, args: Vec<f32>) -> PyResult<()> {
145169
let (r, g, b, a) = parse_color(&args)?;
146170
let color = bevy::color::Color::srgba(r, g, b, a);

0 commit comments

Comments
 (0)