Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 15 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_alchemy"
version = "0.3.0"
version = "0.4.0"
edition = "2024"
description = "An experimental, status effects-as-entities system for Bevy."
categories = ["game-development"]
Expand All @@ -27,9 +27,9 @@ bevy_log = { version = "0.18", default-features = false }

[dev-dependencies]
bevy = "0.18"
bevy_auto_plugin = { version = "0.9" }
bevy_auto_plugin = { version = "0.10.0" }
criterion = { version = "0.8" }
immediate_stats = { version = "0.4", features = ["bevy_auto_plugin"] }
immediate_stats = { version = "0.5.0", features = ["bevy_auto_plugin"] }

[lints.rust]
missing_docs = "warn"
Expand Down
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,20 @@ An experimental, status effects-as-entities system for Bevy.
### Applying Effects
Effects can be applied using `with_effect` or `with_effects` (similar to `with_child` and `with_children` respectively).
```rust ignore
commands.entity(target).with_effect(EffectBundle {
name: Name::new("Effect"),
bundle: MyEffect,
..default()
});
commands.entity(target).with_effect((Name::new("Effect"), MyEffect));
```
They can also be added using spawn-style syntax.
```rust ignore
commands.spawn((
Name::new("Target"),
EffectedBy::spawn(EffectBundle {
name: Name::new("Effect"),
bundle: MyEffect,
..default()
}),
EffectedBy::spawn(
Effect((Name::new("Effect"), MyEffect))
),
));
```

Note that these methods *might* spawn a new entity, depending on what effects are already applied to the target.

### Effect Modes
For some effects it makes sense to allow stacking, so a single entity could be effected by an effect multiple times.
Other effects should only be applied once, either replacing or merging with the previous one.
Expand Down Expand Up @@ -78,5 +74,5 @@ A handful of components are included that are intended to make it easier to crea

| Bevy | Bevy Alchemy |
|--------|---------------|
| `0.18` | `0.2` - `0.3` |
| `0.18` | `0.2` - `0.4` |
| `0.17` | `0.1` |
37 changes: 17 additions & 20 deletions benches/insert_mode.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Benchmarks for applying insert-mode effects.

use bevy_alchemy::{AlchemyPlugin, EffectBundle, EffectCommandsExt, EffectMode, EffectedBy};
use bevy_alchemy::{AlchemyPlugin, Effect, EffectCommandsExt, EffectMode, EffectedBy};
use bevy_app::App;
use bevy_ecs::name::Name;
use bevy_ecs::prelude::{Component, Entity, SpawnRelated};
use criterion::{Criterion, criterion_group, criterion_main};

#[derive(Component)]
#[derive(Component, Clone)]
struct BenchEffect;

fn init_app() -> (App, Entity) {
Expand All @@ -17,11 +17,11 @@ fn init_app() -> (App, Entity) {
.world_mut()
.spawn((
Name::new("Target"),
EffectedBy::spawn(EffectBundle {
name: Name::new("Effect"),
mode: EffectMode::Insert,
bundle: BenchEffect,
}),
EffectedBy::spawn(Effect((
Name::new("Effect"),
EffectMode::Insert,
BenchEffect,
))),
))
.id();

Expand All @@ -33,14 +33,11 @@ fn with_effect(c: &mut Criterion) {

c.bench_function("Insert mode matched `with_effect`", |b| {
b.iter(|| {
app.world_mut()
.commands()
.entity(entity)
.with_effect(EffectBundle {
name: Name::new("Effect"),
mode: EffectMode::Insert,
bundle: BenchEffect,
});
app.world_mut().commands().entity(entity).with_effect((
Name::new("Effect"),
EffectMode::Insert,
BenchEffect,
));
app.world_mut().flush();
})
});
Expand All @@ -54,11 +51,11 @@ fn related_spawner(c: &mut Criterion) {
app.world_mut()
.commands()
.entity(entity)
.insert(EffectedBy::spawn(EffectBundle {
name: Name::new("Effect"),
mode: EffectMode::Insert,
bundle: BenchEffect,
}));
.insert(EffectedBy::spawn(Effect((
Name::new("Effect"),
EffectMode::Insert,
BenchEffect,
))));
app.world_mut().flush();
})
});
Expand Down
27 changes: 12 additions & 15 deletions benches/stack_mode.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! Benchmarks for applying stack-mode effects.

use bevy_alchemy::{AlchemyPlugin, EffectBundle, EffectCommandsExt, EffectMode, EffectedBy};
use bevy_alchemy::{AlchemyPlugin, Effect, EffectCommandsExt, EffectMode, EffectedBy};
use bevy_app::App;
use bevy_ecs::name::Name;
use bevy_ecs::prelude::{Component, Entity, SpawnRelated};
use criterion::{Criterion, criterion_group, criterion_main};

#[derive(Component)]
#[derive(Component, Clone)]
struct BenchEffect;

fn init_app() -> (App, Entity) {
Expand All @@ -23,14 +23,11 @@ fn with_effect(c: &mut Criterion) {

c.bench_function("Stack mode `with_effect`", |b| {
b.iter(|| {
app.world_mut()
.commands()
.entity(entity)
.with_effect(EffectBundle {
name: Name::new("Effect"),
mode: EffectMode::Stack,
bundle: BenchEffect,
});
app.world_mut().commands().entity(entity).with_effect((
Name::new("Effect"),
EffectMode::Stack,
BenchEffect,
));
app.world_mut().flush();
})
});
Expand All @@ -44,11 +41,11 @@ fn related_spawner(c: &mut Criterion) {
app.world_mut()
.commands()
.entity(entity)
.insert(EffectedBy::spawn(EffectBundle {
name: Name::new("Effect"),
mode: EffectMode::Stack,
bundle: BenchEffect,
}));
.insert(EffectedBy::spawn(Effect((
Name::new("Effect"),
EffectMode::Stack,
BenchEffect,
))));
app.world_mut().flush();
})
});
Expand Down
10 changes: 4 additions & 6 deletions docs/effected_by_spawn_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# use bevy::prelude::*;
# use bevy_alchemy::*;
#
# #[derive(Component, Default)]
# #[derive(Component, Default, Clone)]
# struct MyEffect;
#
# fn main() {
Expand All @@ -11,11 +11,9 @@
# let mut commands = world.commands();
commands.spawn((
Name::new("Target"),
EffectedBy::spawn(EffectBundle {
name: Name::new("Effect"),
bundle: MyEffect,
..default()
}),
EffectedBy::spawn(
Effect((Name::new("Effect"), MyEffect))
),
));
# }
```
8 changes: 2 additions & 6 deletions docs/with_effect_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
# use bevy::prelude::*;
# use bevy_alchemy::*;
#
# #[derive(Component, Default)]
# #[derive(Component, Default, Clone)]
# struct MyEffect;
#
# fn main() {
# let mut world = World::new();
# let target = world.spawn_empty().id();
# let mut commands = world.commands();
commands.entity(target).with_effect(EffectBundle {
name: Name::new("Effect"),
bundle: MyEffect,
..default()
});
commands.entity(target).with_effect((Name::new("Effect"), MyEffect));
# }
```
15 changes: 3 additions & 12 deletions docs/with_effects_example.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,16 @@
# use bevy::prelude::*;
# use bevy_alchemy::*;
#
# #[derive(Component, Default)]
# #[derive(Component, Default, Clone)]
# struct MyEffect;
#
# fn main() {
# let mut world = World::new();
# let target = world.spawn_empty().id();
# let mut commands = world.commands();
commands.entity(target).with_effects(|effects| {
effects.spawn(EffectBundle {
name: Name::new("EffectA"),
bundle: MyEffect,
..default()
});

effects.spawn(EffectBundle {
name: Name::new("EffectB"),
bundle: MyEffect,
..default()
});
effects.spawn((Name::new("EffectA"), MyEffect));
effects.spawn((Name::new("EffectB"), MyEffect));
});
# }
```
Loading
Loading