Skip to content

Commit

Permalink
Merge pull request #51 from rrbox/release
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
rrbox authored Feb 11, 2022
2 parents ab72cb8 + f1a7536 commit a00c24d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

`Builder` オブジェクトをインスタンス化すると, イニシャライザに応じて内部に SKNode インスタンスが作成されます.
``` Swift
let rect = SKSpriteNode(color: .white, size: CGSize(width: 32, height: 32)
Builder<SKNode>()
.position(CGPoint(x: 32, y: 100)) // 座標を設定
.add(
// 子ノードを追加
child: SKSpriteNode(color: .white, size: CGSize(width: 32, height: 32),
.add(// 子ノードを追加(既に変数に保持されている場合)
child: rect,
build: { builder in
builder
.position(CGPoint(x: 0, y: 32)) // 子ノードの座標を設定
}
)
.add(child: SKLabelNode(text: "Rect"), build: { builder in
builder
.add(// 子ノードを追加
child: Builder<SKLabelNode>(text: "Rect")
.vertivalAlignment(.center)
.horizontalAlignment(.center)
.fontColor(.black)
.position(x: -32, y: -32)
})
)
```

### NodeBuilder
Expand Down
10 changes: 5 additions & 5 deletions Sources/SKNodeBuilder/Builder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final public class Builder<Body: SKNode>: NSObject, BuilderProtocol {

}

final public class ChildNodeBuilder<Body: SKNode>: NSObject, BuilderProtocol {
final public class UnownedNodeBuilder<Body: SKNode>: NSObject, BuilderProtocol {

public var node: Body {
self.body
Expand All @@ -58,15 +58,15 @@ public extension BuilderProtocol {
return self
}

@discardableResult func add<Node: SKNode>(child node: Node, build: (ChildNodeBuilder<Node>) -> () = {_ in}) -> Self {
@discardableResult func add<Node: SKNode>(child node: Node, build: (UnownedNodeBuilder<Node>) -> () = {_ in}) -> Self {
self.node.addChild(node)
build(ChildNodeBuilder<Node>(node))
build(UnownedNodeBuilder<Node>(node))
return self
}

@discardableResult func insert<Node: SKNode>(child node: Node, at index: Int, build: (ChildNodeBuilder<Node>) -> () = {_ in}) -> Self {
@discardableResult func insert<Node: SKNode>(child node: Node, at index: Int, build: (UnownedNodeBuilder<Node>) -> () = {_ in}) -> Self {
self.node.insertChild(node, at: index)
build(ChildNodeBuilder<Node>(node))
build(UnownedNodeBuilder<Node>(node))
return self
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/SKNodeBuilder/PropertyWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct NodeBuilder<Body: SKNode> {
public init(wrappedValue: Body) {
self.wrappedValue = wrappedValue
}
public var projectedValue: ChildNodeBuilder<Body> {
ChildNodeBuilder(self.wrappedValue)
public var projectedValue: UnownedNodeBuilder<Body> {
UnownedNodeBuilder(self.wrappedValue)
}
}

0 comments on commit a00c24d

Please sign in to comment.