-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redesign template macro #14
base: main
Are you sure you want to change the base?
Conversation
.flatten() | ||
.collect(); | ||
|
||
commands.entity(*scene_tree).build_children(template); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice how this is building a template on a child of another template. Now that receipts are stored on-entity, you can apply any template to any entity and it will just work (remove any components/children included in the previous template but not the new one).
Co-authored-by: Oliver Maskery <omaskery@googlemail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to update RELEASES.md :) I like these changes, but we should get ready to cut a new major version.
Yep yep. Just random question, how do we feel about a 1.0 release? |
No strong feelings. I suppose this is about as 1.0 as we'll ever get? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome evolution of this very handy macro! Loving the neater syntax and the b!
-macro.
Co-authored-by: Viktor Gustavsson <villor94@gmail.com>
I would hold off on a 1.0 for now. I'm planning to test this out in some editor stuff sometime soon hopefully, and might find additional stuff to change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting!
if let Some(parent_id) = world.get::<Parent>(entity_id).map(|parent| parent.get()) { | ||
observer.watch_entity(parent_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is just obvious to other people (I'm not super familiar with how observers work), but perhaps this could do with a comment briefly explaining why we observe the parent if it's there, and why we fallback to listening to all entities otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, I'll be sure to document that. My thinking was, this could let you swap out different global observers by collecting them into a template.
($fragments:ident; @ $block:block ; $( $($sib:tt)+ )? ) => { | ||
$fragments.extend({ $block }); // Extend the fragments with the value of the block. | ||
$(push_item!($fragments; $($sib)*))* // Continue pushing siblings onto the current list. | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
($fragments:ident; @ $block:block ; $( $($sib:tt)+ )? ) => { | |
$fragments.extend({ $block }); // Extend the fragments with the value of the block. | |
$(push_item!($fragments; $($sib)*))* // Continue pushing siblings onto the current list. | |
}; | |
($fragments:ident; @ $splice:expr ; $( $($sib:tt)+ )? ) => { | |
$fragments.extend({ $splice }); // Extend the fragments with the result of the expression. | |
$(push_item!($fragments; $($sib)*))* // Continue pushing siblings onto the current list. | |
}; |
Maybe the brace-requirement could be removed for splices as well for consistency:
@counter(num_sheep, "sheep", Button::Increment, Button::Decrement);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to switch from the work account. Again...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that, I was still on the fence.
I actually like that there is a separation between entity delimiters and component delimiters. Maybe BSN should do the same 🤷♂️ |
Same. Will keep then. |
I've redesigned several aspects of the template macro to incorporate community feedback.
Changes
Prototype
trait has been removed.Fragment
no longer is generic over bundle type.Commands
based api has been replaced with a more flexibleEntityCommands
version.pub
.BoxedBundle
trait andb!()
macro. I've opted forb!(Foo)
overbundle!(Foo)
because it gets tedious to write.Callback
component andon(into_observer_system)
helper for adding observers to templates. Observers are added as children which always observe their parents.This is a breaking change, as the syntax of the macro is not fully backwards compatible. Here is the full list of syntax changes:
=>
symbol is now required between a fragment's bundle and it's list of children.{(Foo, Bar)}
is now just(Foo, Bar)
.Example
The proposed syntax changes:
Conditional bundles:
Observers:
Other Notes
For increased compatibility with bsn, i'm considering swapping the
;
for a,
.