Local resources don't create if already present (#745)

Local<T> will no longer insert the inner resource if it already exists.
This commit is contained in:
Oscar 2020-10-30 12:21:57 -07:00 committed by GitHub
parent dea05e9af5
commit b6004e44cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -295,9 +295,13 @@ impl<'a, T: Resource + FromResources> ResourceQuery for Local<'a, T> {
type Fetch = FetchResourceLocalMut<T>;
fn initialize(resources: &mut Resources, id: Option<SystemId>) {
let value = T::from_resources(resources);
let id = id.expect("Local<T> resources can only be used by systems");
resources.insert_local(id, value);
// Only add the local resource if it doesn't already exist for this system
if resources.get_local::<T>(id).is_none() {
let value = T::from_resources(resources);
resources.insert_local(id, value);
}
}
}