|
1 | 1 | //! 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. |
10 | 2 |
|
11 | 3 | use bevy::{ |
12 | | - asset::{AssetLoader, LoadContext, io::Reader}, |
| 4 | + asset::{ |
| 5 | + AssetLoader, AssetPath, LoadContext, |
| 6 | + io::{AssetSourceId, Reader}, |
| 7 | + }, |
13 | 8 | prelude::*, |
14 | 9 | }; |
15 | | -use std::path::PathBuf; |
| 10 | +use std::path::{Path, PathBuf}; |
16 | 11 |
|
17 | 12 | /// Plugin that registers the Sketch asset type and its loader. |
18 | 13 | pub struct LivecodePlugin; |
19 | 14 |
|
20 | 15 | impl Plugin for LivecodePlugin { |
21 | 16 | fn build(&self, app: &mut App) { |
22 | 17 | app.init_asset::<Sketch>() |
23 | | - .init_asset_loader::<SketchLoader>(); |
| 18 | + .init_asset_loader::<SketchLoader>() |
| 19 | + .add_systems(Startup, load_current_sketch); |
24 | 20 | } |
25 | 21 | } |
26 | 22 |
|
| 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 | + |
27 | 33 | /// A sketch source file loaded as a Bevy asset. |
28 | 34 | /// |
29 | 35 | /// The `Sketch` asset contains the raw source code as a string. It does not interpret |
|
0 commit comments