Skip to content

Commit a019405

Browse files
committed
Make Config a bevy Resource; remove python feature
1 parent bd30e88 commit a019405

File tree

6 files changed

+28
-12
lines changed

6 files changed

+28
-12
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ workspace = true
1111
default = ["wayland"]
1212
wayland = ["processing_render/wayland"]
1313
x11 = ["processing_render/x11"]
14-
python = ["processing_render/python"]
1514

1615
[workspace]
1716
resolver = "3"

crates/processing_pyo3/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ x11 = ["processing/x11"]
1717

1818
[dependencies]
1919
pyo3 = "0.27.0"
20-
processing = { workspace = true, features = ["python"] }
20+
processing = { workspace = true }
2121
bevy = { workspace = true }
2222
glfw = { version = "0.60.0"}
2323

crates/processing_render/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ workspace = true
1010
default = []
1111
wayland = ["bevy/wayland"]
1212
x11 = ["bevy/x11"]
13-
python = []
1413

1514
[dependencies]
1615
bevy = { workspace = true }

crates/processing_render/src/config.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,33 @@
22
//!
33
//! To add a new Config just add a new enum with associated value
44
5+
use bevy::prelude::Resource;
56
use std::collections::HashMap;
67

7-
#[derive(Hash, Eq, PartialEq)]
8+
#[derive(Clone, Hash, Eq, PartialEq)]
89
pub enum ConfigKey {
910
AssetRootPath,
1011
}
12+
1113
// TODO: Consider Box<dyn Any> instead of String
12-
pub type ConfigMap = HashMap<ConfigKey, String>;
14+
#[derive(Resource)]
1315
pub struct Config {
14-
map: ConfigMap,
16+
map: HashMap<ConfigKey, String>,
17+
}
18+
19+
impl Clone for Config {
20+
fn clone(&self) -> Self {
21+
Config {
22+
map: self.map.clone(),
23+
}
24+
}
1525
}
1626

1727
impl Config {
1828
pub fn new() -> Self {
1929
// TODO consider defaults
2030
Config {
21-
map: ConfigMap::new(),
31+
map: HashMap::new(),
2232
}
2333
}
2434

crates/processing_render/src/image.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33
//! It can be created from raw pixel data, loaded from disk, resized, and read back to CPU memory.
44
use std::path::PathBuf;
55

6-
#[cfg(feature = "python")]
7-
use bevy::asset::{AssetPath, io::AssetSourceId};
86
use bevy::{
97
asset::{
10-
LoadState, RenderAssetUsages, handle_internal_asset_events, io::embedded::GetAssetServer,
8+
AssetPath, LoadState, RenderAssetUsages, handle_internal_asset_events,
9+
io::{AssetSourceId, embedded::GetAssetServer},
1110
},
1211
ecs::{entity::EntityHashMap, system::RunSystemOnce},
1312
prelude::*,
@@ -25,6 +24,7 @@ use bevy::{
2524
};
2625
use half::f16;
2726

27+
use crate::config::{Config, ConfigKey};
2828
use crate::error::{ProcessingError, Result};
2929

3030
pub struct ImagePlugin;
@@ -140,10 +140,16 @@ pub fn from_handle(
140140
}
141141

142142
pub fn load(In(path): In<PathBuf>, world: &mut World) -> Result<Entity> {
143-
#[cfg(feature = "python")]
144-
let path = AssetPath::from_path_buf(path).with_source(AssetSourceId::from("assets_directory"));
143+
let config = world.resource_mut::<Config>();
144+
let path: AssetPath = match config.get(ConfigKey::AssetRootPath) {
145+
Some(_) => {
146+
AssetPath::from_path_buf(path).with_source(AssetSourceId::from("assets_directory"))
147+
}
148+
None => AssetPath::from_path_buf(path),
149+
};
145150

146151
let handle: Handle<bevy::image::Image> = world.get_asset_server().load(path);
152+
147153
while let LoadState::Loading = world.get_asset_server().load_state(&handle) {
148154
world.run_system_once(handle_internal_asset_events).unwrap();
149155
}

crates/processing_render/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@ pub fn surface_resize(graphics_entity: Entity, width: u32, height: u32) -> error
208208
fn create_app(config: Config) -> App {
209209
let mut app = App::new();
210210

211+
app.insert_resource(config.clone());
212+
211213
#[cfg(not(target_arch = "wasm32"))]
212214
let plugins = DefaultPlugins
213215
.build()

0 commit comments

Comments
 (0)