1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use *;
use TypeId;
use HashMap;
/// A function used to merge effects with [`EffectMode::Merge`](crate::EffectMode::Merge),
/// which must be registered in the [registry](EffectMergeRegistry).
///
/// The component the function is registered for is guaranteed to exist on both provided entities.
/// Note that the incoming entity exists in a **separate world**.
///
/// # Example
/// ```rust
/// # use bevy_ecs::prelude::*;
/// # use bevy_alchemy::EffectMergeRegistry;
/// #[derive(Component, Clone)]
/// struct MyEffect(f32);
///
/// fn merge_my_effect(mut existing: EntityWorldMut, incoming: EntityRef) {
/// let mut existing = existing.get_mut::<MyEffect>().unwrap();
/// let incoming = incoming.get::<MyEffect>().unwrap();
/// existing.0 += incoming.0;
/// }
/// ```
pub type EffectMergeFn = fn;
/// Stores the effect merge logic for each registered component.
/// New components can be registered by providing a [`EffectMergeFn`] to the [`register`](EffectMergeRegistry::register) method.
/// This function will be run whenever an effect is applied twice to the same entity with [`EffectMode::Merge`](crate::EffectMode::Merge).
///
/// # Example
/// ```rust
/// # use bevy_ecs::prelude::*;
/// # use bevy_alchemy::EffectMergeRegistry;
/// #[derive(Component, Clone)]
/// struct MyEffect(f32);
///
/// fn main() {
/// let mut world = World::new();
///
/// world.get_resource_or_init::<EffectMergeRegistry>()
/// .register::<MyEffect>(merge_my_effect);
/// }
///
/// fn merge_my_effect(mut existing: EntityWorldMut, incoming: EntityRef) {
/// let mut existing = existing.get_mut::<MyEffect>().unwrap();
/// let incoming = incoming.get::<MyEffect>().unwrap();
/// existing.0 += incoming.0;
/// }
/// ```