use bevy::prelude::*;
use bevy_gauge::prelude::*;
use bevy_gauge::sources::StatsAppSourcesExt;
fn main() {
app_config();
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(bevy_gauge::plugin)
.register_stat_relationship_as::<ChildOf>("Parent")
.add_systems(Startup, (spawn_entities, ApplyDeferred).chain())
.add_systems(
Update,
(
read_stats_system,
)
.chain(),
)
.run();
}
fn app_config() {
Konfig::register_stat_type("Strength", "Modifiable");
Konfig::register_stat_type("ChildBonus", "Modifiable");
}
fn spawn_entities(mut commands: Commands) {
let parent = commands
.spawn((
Stats::new(), stats! { "Strength" => 50.0 }, Name::new("Parent"),
))
.id();
commands.spawn((
Stats::new(), stats! { "ChildBonus" => "Strength@Parent * 0.1" },
Name::new("Child"),
)).insert(ChildOf(parent));
println!("Entities spawned. Parent has 50 Strength.");
}
fn read_stats_system(
q_child_of: Query<&Stats, With<ChildOf>>,
) {
for child in q_child_of.iter() {
let child_bonus = child.get("ChildBonus");
println!("ChildBonus: {}", child_bonus);
}
}