Skip to content

Commit

Permalink
Merge pull request #78 from rrbox/hoffix/node-subclass-support
Browse files Browse the repository at this point in the history
Hotfix/node subclass support
  • Loading branch information
rrbox authored Nov 2, 2022
2 parents 6d6bba7 + 0118784 commit 6e9cee8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 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
2 changes: 1 addition & 1 deletion Sources/SKNodeBuilder/SpriteBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension SpriteBuilder {

}

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

@discardableResult func texture(_ texture: SKTexture?) -> Self {
self.node.texture = texture
Expand Down
36 changes: 36 additions & 0 deletions Tests/SKNodeBuilderTests/SubclassTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SubclassTests.swift
//
//
// Created by rrbox on 2022/11/02.
//

import SpriteKit
import SKNodeBuilder
import XCTest

class SpriteNode: SKSpriteNode {

}

class LabelNode: SKLabelNode {

}

class ShapeNode: SKShapeNode {

}

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

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

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

}

0 comments on commit 6e9cee8

Please sign in to comment.