Skip to content

Commit

Permalink
Merge pull request #24 from CatThingy/bevy_0.9
Browse files Browse the repository at this point in the history
Update to Bevy 0.9
  • Loading branch information
MrGVSV authored Nov 13, 2022
2 parents 1edbd5f + 230e280 commit 59805ae
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 28 deletions.
7 changes: 3 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@ exclude = ["assets/**/*", ".github/**/*"]

[dependencies]
bevy_proto_derive = { version = "0.2", path = "bevy_proto_derive" }
bevy = { version = "0.8", default-features = false, features = ["bevy_asset"] }
bevy = { version = "0.9", default-features = false, features = ["bevy_asset"] }
serde = "1.0"
typetag = "0.2"
serde_yaml = "0.9"
dyn-clone = "1.0"
indexmap = "1.9"
crossbeam-channel = { version = "0.5", optional = true }
notify = { version = "=5.0.0-pre.15", optional = true }
notify = { version = "5.0", optional = true }

[dev-dependencies]
bevy = "0.8"

bevy = "0.9"
[features]
default = ["analysis"]
# If enabled, analyses prototype dependencies and logging (or panicking if `no_cycles` is enabled) on error
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn spawn_person(mut commands: Commands, data: Res<ProtoData>, asset_server: Res<
proto.spawn(&mut commands, &data, &asset_server);

// Insert on an existing entity!
let entity = commands.spawn().id();
let entity = commands.spawn_empty().id();
let entity_cmds = commands.entity(entity);
proto.insert(entity_cmds, &data, &asset_server);

Expand Down
4 changes: 2 additions & 2 deletions examples/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn spawn_sprites_programmatic(mut commands: Commands, asset_server: Res<AssetSer

for _ in 0..BATCH_COUNT {
for _ in 0..BATCH_SIZE {
commands.spawn_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
texture: asset_server.load("textures/sprite.png"),
..Default::default()
});
Expand Down Expand Up @@ -94,7 +94,7 @@ impl ProtoComponent for SpriteBundleDef {
};

// === Insert Generated Bundle === //
commands.insert_bundle(my_bundle);
commands.insert(my_bundle);
}

fn prepare(&self, world: &mut World, prototype: &dyn Prototypical, data: &mut ProtoData) {
Expand Down
4 changes: 2 additions & 2 deletions examples/bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl ProtoComponent for SpriteBundleDef {
};

// === Insert Generated Bundle === //
commands.insert_bundle(my_bundle);
commands.insert(my_bundle);
}

/// Here, we prepare any assets that this bundle/component might need that require additional setup.
Expand All @@ -46,7 +46,7 @@ impl ProtoComponent for SpriteBundleDef {
}

fn spawn_sprite(mut commands: Commands, data: Res<ProtoData>, asset_server: Res<AssetServer>) {
commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());

/// Here, we attempt to get our prototype by name.
/// We'll raise an exception if it's not found, just so we can fail fast.
Expand Down
7 changes: 4 additions & 3 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::{Deref, DerefMut};

use bevy::asset::{Asset, HandleId, HandleUntyped};
use bevy::ecs::prelude::World;
use bevy::ecs::system::EntityCommands;
use bevy::ecs::system::{EntityCommands, Resource};
use bevy::prelude::{FromWorld, Handle};
use bevy::reflect::Uuid;
use bevy::utils::HashMap;
Expand Down Expand Up @@ -37,6 +37,7 @@ impl From<&HandlePath> for HandleId {
type UuidHandleMap = HashMap<Uuid, HandleUntyped>;

/// A resource containing data for all prototypes that need data stored
#[derive(Resource)]
pub struct ProtoData {
/// Maps Prototype Name -> Component Type -> HandleId -> Asset Type -> HandleUntyped
handles: HashMap<
Expand Down Expand Up @@ -119,7 +120,7 @@ impl ProtoData {
let comp_map = proto_map
.entry(component.type_id())
.or_insert_with(HashMap::default);
let path_map = comp_map.entry(handle.id).or_insert_with(HashMap::default);
let path_map = comp_map.entry(handle.id()).or_insert_with(HashMap::default);
path_map.insert(T::TYPE_UUID, handle.clone_untyped());
}

Expand Down Expand Up @@ -458,7 +459,7 @@ pub trait ProtoDeserializer: DynClone {
dyn_clone::clone_trait_object!(ProtoDeserializer);

/// Options for controlling how prototype data is handled.
#[derive(Clone)]
#[derive(Clone, Resource)]
pub struct ProtoDataOptions {
/// Directories containing prototype data.
pub directories: Vec<String>,
Expand Down
14 changes: 9 additions & 5 deletions src/hot_reload.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use bevy::prelude::{App, Plugin, Res, ResMut};
use bevy::prelude::{App, Plugin, Res, ResMut, Resource};
use crossbeam_channel::Receiver;
use notify::{Event, RecommendedWatcher, RecursiveMode, Result, Watcher};
use notify::{Config, Event, RecommendedWatcher, RecursiveMode, Result, Watcher};

use crate::prelude::{ProtoData, ProtoDataOptions};

// Copied from bevy_asset's implementation
// https://github.com/bevyengine/bevy/blob/main/crates/bevy_asset/src/filesystem_watcher.rs
#[derive(Resource)]
struct FilesystemWatcher {
watcher: RecommendedWatcher,
receiver: Receiver<Result<Event>>,
Expand All @@ -21,9 +22,12 @@ impl FilesystemWatcher {
impl Default for FilesystemWatcher {
fn default() -> Self {
let (sender, receiver) = crossbeam_channel::unbounded();
let watcher: RecommendedWatcher = RecommendedWatcher::new(move |res| {
sender.send(res).expect("Watch event send failure.");
})
let watcher: RecommendedWatcher = RecommendedWatcher::new(
move |res| {
sender.send(res).expect("Watch event send failure.");
},
Config::default(),
)
.expect("Failed to create filesystem watcher.");
FilesystemWatcher { watcher, receiver }
}
Expand Down
18 changes: 8 additions & 10 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,16 @@ impl ProtoPlugin {
impl Plugin for ProtoPlugin {
fn build(&self, app: &mut App) {
let opts = self.options.clone();
let opts = opts.unwrap_or(
ProtoDataOptions {
directories: vec![String::from("assets/prototypes")],
recursive_loading: false,
deserializer: Box::new(DefaultProtoDeserializer),
extensions: Some(vec!["yaml", "json"]),
}
);

let opts = opts.unwrap_or(ProtoDataOptions {
directories: vec![String::from("assets/prototypes")],
recursive_loading: false,
deserializer: Box::new(DefaultProtoDeserializer),
extensions: Some(vec!["yaml", "json"]),
});

#[cfg(feature = "hot_reloading")]
app.add_plugin(crate::hot_reload::HotReloadPlugin {
path: opts.directories[0].clone()
path: opts.directories[0].clone(),
});

app.insert_resource(opts);
Expand Down
2 changes: 1 addition & 1 deletion src/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub trait Prototypical: 'static + Send + Sync {
data: &Res<ProtoData>,
asset_server: &Res<AssetServer>,
) -> EntityCommands<'w, 's, 'a> {
let entity = commands.spawn();
let entity = commands.spawn_empty();
self.insert(entity, data, asset_server)
}

Expand Down

0 comments on commit 59805ae

Please sign in to comment.