Replies: 4 comments 6 replies
-
Edit systemsEdit systems are currently defined something like this: fn edit_foo(mut edit: YoleckEdit<Foo>, mut commands: Commands) {
edit.edit(|ctx, data, ui| {
// Edit with egui:
ui.add(egui::Slider::new(&mut data.some_field, 0.0..=1.0).prefix("..."));
// Edit with knobs:
let mut knob = ctx.knob(&mut commands, "knob-name");
knob.cmd.insert(...)
if let Some(knob_drag) = knob.get_passed_data::<Vec3>() {
// update data base on knob_drag
}
});
} I want them to look more like this: fn edit_foo(mut ui: YoleckUi, mut query: Query<&mut Foo, With<YoleckEdit>>) {
let Ok(foo) = query.get_single_mut() else { return };
// Edit with egui:
ui.add(egui::Slider::new(&mut foo.some_field, 0.0..=1.0).prefix("..."));
// I'll talk about knob semantics later
} The This style will allow editing multiple entities: fn edit_foos(mut ui: YoleckUi, mut query: Query<&mut Foo, With<YoleckEdit>>) {
if query.is_empty() {
return;
}
// Gonna hide the details inside this type:
let mut aggregator = Aggregator::new();
for foo in query.iter() {
aggregator.add(foo.some_field)
}
// Edit with egui:
aggregator.edit_with(ui);
for mut foo in query.iter() {
aggregator.update(&mut foo.some_field);
}
} KnobsI see two options for knobs:
The first option sounds very natural, and I'm writing it because someone may convince me to use it, but for now I prefer the second option for the following reasons:
Overall, a simple edit system that includes a knob will look something like that: fn edit_foo(
mut ui: YoleckUi,
mut query: Query<&mut Foo, With<YoleckEdit>>,
mut knobs: YoleckKnobs,
) {
let Ok(foo) = query.get_single_mut() else { return };
// Edit with egui:
ui.add(egui::Slider::new(&mut foo.some_field, 0.0..=1.0).prefix("..."));
// Edit with knobs:
let mut knob = knobs.knob("knob-name");
knob.cmd.insert(...)
if let Some(knob_drag) = knob.get_passed_data::<Vec3>() {
// update data base on knob_drag
}
} |
Beta Was this translation helpful? Give feedback.
-
Populate SystemsThe most straightforward way to do it in the new style is: fn populate_foo(
query: Query<(Entity, &Foo), With<YoleckPopulate>>,
mut commands: Commands,
) {
for (entity, foo) in query.iter() {
let mut cmd = commands.entity(entity);
// insert components to cmd based on foo
}
} I really wish I could do something like this though: fn populate_foo(query: Query<(YoleckPopulate, &Foo)>) {
for (populate, foo) in query.iter() {
let mut cmd = populate.cmd();
// ...
}
} But I may have to settle for: fn populate_foo(
query: Query<(YoleckPopulate, &Foo)>,
mut commands: Commands,
) {
for (populate, foo) in query.iter() {
let mut cmd = populate.cmd(&mut commands);
// ...
}
} |
Beta Was this translation helpful? Give feedback.
-
Populate SystemsThe most straightforward way to do it in the new style is: fn populate_foo(
query: Query<(Entity, &Foo), With<YoleckPopulate>>,
mut commands: Commands,
) {
for (entity, foo) in query.iter() {
let mut cmd = commands.entity(entity);
// insert components to cmd based on foo
}
} I really wish I could do something like this though: fn populate_foo(query: Query<(YoleckPopulate, &Foo)>) {
for (populate, foo) in query.iter() {
let mut cmd = populate.cmd();
// ...
}
} But I may have to settle for: fn populate_foo(
query: Query<(YoleckPopulate, &Foo)>,
mut commands: Commands,
) {
for (populate, foo) in query.iter() {
let mut cmd = populate.cmd(&mut commands);
// ...
}
} Another option is to still use the lambda syntax: fn populate_foo(mut populate: YoleckPopulate<&Foo>) {
populate.populate(|_ctx, mut cmd, foo| {
// ...
});
} This creates a difference between the edit systems and the populate systems though, so I'm not 100% sure I want it. |
Beta Was this translation helpful? Give feedback.
-
Closing because I've implemented it all. |
Beta Was this translation helpful? Give feedback.
-
Yoleck's fundamental design concept is that rather than editing the components, we should edit new data types designed for easy editing and for serialization. The current implementation is that each such
YoleckTypeHandler
contains:There are several problems with this design:
vpeol_position_edit_adapter
, which has both weird implementation and weird API.Box<dyn Send + Sync + Any>
, which is neither efficient nor easy to work with.I want to migrate to a new design, a more ECSy one. The core principle of editing "proxy" data instead of the actual components will remain, but:
Beta Was this translation helpful? Give feedback.
All reactions