Skip to content

Commit

Permalink
more ergonomic subchildren_of_type generics
Browse files Browse the repository at this point in the history
  • Loading branch information
Lamby777 committed May 12, 2024
1 parent 16d1130 commit 13ffb1e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pets-lib/src/dialogue/dbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ impl DialogBox {
}

fn free_choice_labels(&mut self) {
let cont = self.choice_container().upcast();
let children = subchildren_of_type::<DChoice>(cont);
let cont = self.choice_container();
let children = subchildren_of_type::<DChoice, _>(cont);

for mut node in children {
node.queue_free();
Expand Down
8 changes: 5 additions & 3 deletions pets-lib/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
Filter: Inherits<Node>,
N: Inherits<Node>,
{
subchildren_of_type::<Filter>(node.upcast())
subchildren_of_type::<Filter, _>(node.upcast())
.iter()
.position(|n| n.upcast_ref().get_name() == name.clone().into())
}
Expand Down Expand Up @@ -65,15 +65,17 @@ where
/// Returns a vector. Use `subchildren_of_type_array` for a godot array.
///
/// bugfix later: it won't find children of nodes that are the correct type
pub fn subchildren_of_type<T>(parent: Gd<Node>) -> Vec<Gd<T>>
pub fn subchildren_of_type<T, Par>(parent: Gd<Par>) -> Vec<Gd<T>>
where
Par: Inherits<Node>,
T: Inherits<Node>,
{
let mut res = vec![];
let parent = parent.upcast_ref();

for node in parent.get_children().iter_shared() {
let Ok(node) = node.clone().try_cast::<T>() else {
let children = subchildren_of_type::<T>(node);
let children = subchildren_of_type::<T, _>(node);
res.extend(children);
continue;
};
Expand Down
2 changes: 1 addition & 1 deletion pets-lib/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl World {
impl INode2D for World {
fn ready(&mut self) {
let room = self.room.clone();
let mzones = subchildren_of_type::<MusicZone>(room.upcast());
let mzones = subchildren_of_type::<MusicZone, _>(room);

for mut zone in mzones {
let on_exit = self.base().callable("on_exit");
Expand Down

0 comments on commit 13ffb1e

Please sign in to comment.