Skip to main content

Module effects

Module effects 

Source
Expand description

Author-defined effect registries and active effect state.

effects is a horizontal gameplay-definition layer. It does not ship poison, speed, regeneration, potion, survival, or player-specific behavior. The game author defines effect ids, metadata, tags, stacks, durations, and the systems that interpret active effects.

The framework provides three generic pieces:

§Example

use bevy::ecs::message::MessageWriter;
use bevy::prelude::*;
use voxel_framework::effects::{
    ActiveEffectSet, EffectApplied, EffectDefinition, EffectRegistry, VoxelEffectsPlugin,
    apply_effect,
};

fn register_effects(mut effects: ResMut<EffectRegistry>) {
    effects
        .register(
            EffectDefinition::new("low_oxygen")
                .named("Low Oxygen")
                .duration_secs(10.0)
                .max_stacks(3)
                .tag("space_suit"),
        )
        .expect("effect id should be unique");
}

fn apply_low_oxygen(
    registry: Res<EffectRegistry>,
    mut active: ResMut<ActiveEffectSet>,
    mut applied: MessageWriter<EffectApplied>,
) {
    apply_effect("low_oxygen", &registry, &mut active, &mut applied)
        .expect("effect should exist");
}

App::new()
    .add_plugins(MinimalPlugins)
    .add_plugins(VoxelEffectsPlugin)
    .add_systems(Startup, register_effects)
    .add_systems(Update, apply_low_oxygen);

Structs§

ActiveEffectSet
Active author-defined effect instances.
EffectApplied
Message emitted by apply_effect and apply_effect_instance.
EffectDefinition
Author-defined effect metadata.
EffectDefinitionSnapshot
Serializable snapshot of one author-defined effect definition.
EffectExpired
Message emitted by tick_effects when finite effects expire.
EffectId
Stable identifier for an author-defined effect.
EffectInstance
Runtime instance of an author-defined effect.
EffectInstanceSnapshot
Serializable snapshot of one active effect instance.
EffectRegistry
Registry of author-defined effect definitions.
VoxelEffectsPlugin
Horizontal plugin that initializes author-defined effect resources.

Enums§

EffectError
Errors returned by effect registries and active effect sets.

Functions§

apply_effect
Applies an effect and emits EffectApplied.
apply_effect_instance
Applies an explicit effect instance and emits EffectApplied.
tick_effects
Advances finite effect durations and emits EffectExpired for each expired effect.