Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Source/model/scene/Group.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ open class Group: Node {
}

// Searching

override public func nodeBy(tag: String) -> Node? {
if let node = super.nodeBy(tag: tag) {
override public func nodeBy(predicate: (Node) -> Bool) -> Node? {
if let node = super.nodeBy(predicate: predicate) {
return node
}

for child in contents {
if let node = child.nodeBy(tag: tag) {
if let node = child.nodeBy(predicate: predicate) {
return node
}
}

return .none
}

override public func nodesBy(tag: String) -> [Node] {
override public func nodesBy(predicate: (Node) -> Bool) -> [Node] {
var result = [Node]()
contents.forEach { child in
result.append(contentsOf: child.nodesBy(tag: tag))
result.append(contentsOf: child.nodesBy(predicate: predicate))
}

if let node = super.nodeBy(tag: tag) {
if let node = super.nodeBy(predicate: predicate) {
result.append(node)
}

Expand Down
18 changes: 13 additions & 5 deletions Source/model/scene/Node.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,25 @@ open class Node: Drawable {

// MARK: - Searching
public func nodeBy(tag: String) -> Node? {
if self.tag.contains(tag) {
return nodeBy(predicate: { $0.tag.contains(tag) })
}

public func nodesBy(tag: String) -> [Node] {
return nodesBy(predicate: { $0.tag.contains(tag) })
}

public func nodeBy(predicate: (Node) -> Bool) -> Node? {
if predicate(self) {
return self
}

return .none
}

public func nodesBy(tag: String) -> [Node] {
return [nodeBy(tag: tag)].compactMap { $0 }
public func nodesBy(predicate: (Node) -> Bool) -> [Node] {
return [nodeBy(predicate: predicate)].compactMap { $0 }
}


// MARK: - Events
internal var animationObservers = [AnimationObserver]()

Expand Down