Skip to content

Commit

Permalink
[update] SKLabelNode, SKShapeNode のサブクラスに対してサポート.
Browse files Browse the repository at this point in the history
SKSpriteNode 同様に, サブクラスに対しても extension が適用されるようにした.
  • Loading branch information
rrbox committed Nov 2, 2022
1 parent 2095d3e commit 0118784
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/SKNodeBuilder/LabelBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public extension LabelBuilder {

}

public extension BuilderProtocol where Body == SKLabelNode {
public extension BuilderProtocol where Body: SKLabelNode {

@discardableResult func text(_ value: String?) -> Self {
self.node.text = value
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKNodeBuilder/ShapeBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public extension ShapeBuilder {

}

public extension BuilderProtocol where Body == SKShapeNode {
public extension BuilderProtocol where Body: SKShapeNode {

func path(_ value: CGPath) -> Self {
self.node.path = value
Expand Down
10 changes: 8 additions & 2 deletions Tests/SKNodeBuilderTests/SubclassTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,14 @@ class ShapeNode: SKShapeNode {

final class SubclassTests: XCTestCase {
func testSubclass() {
let builder = Builder<SpriteNode>()
_ = Builder<SpriteNode>()
.size(CGSize(width: 32, height: 32))

_ = Builder<ShapeNode>()
.fillColor(.red)

_ = Builder<LabelNode>()
.text("test")
}

}

0 comments on commit 0118784

Please sign in to comment.