Skip to content

Commit

Permalink
Fix inline children not being stored as dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Apr 29, 2023
1 parent e9122c2 commit e654af9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 4 additions & 4 deletions bevy_proto_backend/src/children/builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::path::Path;

use bevy::asset::{AssetIo, AssetPath, Handle, LoadedAsset};
use bevy::asset::{AssetIo, Handle, LoadedAsset};

use crate::load::ProtoLoadContext;
use crate::path::{ProtoPath, ProtoPathContext};
Expand All @@ -11,15 +11,13 @@ use crate::proto::Prototypical;
/// [prototype's]: Prototypical
pub struct ProtoChildBuilder<'ctx, 'load_ctx, T: Prototypical> {
pub(crate) context: ProtoLoadContext<'ctx, 'load_ctx, T>,
pub(crate) child_paths: Vec<AssetPath<'static>>,
child_count: usize,
}

impl<'ctx, 'load_ctx, T: Prototypical> ProtoChildBuilder<'ctx, 'load_ctx, T> {
pub(crate) fn new(context: ProtoLoadContext<'ctx, 'load_ctx, T>) -> Self {
Self {
context,
child_paths: Vec::new(),
child_count: 0,
}
}
Expand All @@ -40,7 +38,9 @@ impl<'ctx, 'load_ctx, T: Prototypical> ProtoChildBuilder<'ctx, 'load_ctx, T> {

/// Add the child with the given path to the parent.
pub fn add_child_path(&mut self, child_path: ProtoPath) -> Result<Handle<T>, T::Error> {
self.child_paths.push(child_path.asset_path().to_owned());
self.context
.child_paths_mut()
.push(child_path.asset_path().to_owned());

self.child_count += 1;

Expand Down
7 changes: 3 additions & 4 deletions bevy_proto_backend/src/load/load_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a, 'ctx, T: Prototypical> ProtoLoadContext<'a, 'ctx, T> {
&mut self,
f: F,
) -> Result<(), E> {
let ctx = Self {
let mut ctx = Self {
registry: self.registry,
load_context: self.load_context.take(),
extensions: self.extensions,
Expand All @@ -68,17 +68,16 @@ impl<'a, 'ctx, T: Prototypical> ProtoLoadContext<'a, 'ctx, T> {
_phantom: Default::default(),
};

std::mem::swap(&mut ctx.child_paths, &mut self.child_paths);
self.depth += 1;

let mut builder = ProtoChildBuilder::new(ctx);
let result = f(&mut builder);
self.load_context = builder.context.load_context;
let children = builder.child_paths;
self.child_paths = builder.context.child_paths;

self.depth -= 1;

self.child_paths.extend(children);

result
}

Expand Down

0 comments on commit e654af9

Please sign in to comment.