Skip to content
127 changes: 117 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,128 @@ import GameWidget
import SpriteKit

let node = Display()
.place {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
}
.node()
.place {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
}
.node()

```

## Layout widgets

### Display

Display multiple widgets in one SKNode.

```swift
let node = Display()
.place {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
}
.place {
Button(.init("Select_B"))
.position(CGPoint(x: 0, y: 64))
Button(.init("Cancel_B"))
.position(CGPoint(x: 0, y: -64))
HorizontalSingleBarChart(name: .init("Bar"))
}
.node()

```

Up to 10 widgets can be placed on a single `Display.place`.

### Node

`Node` widget is modifiable with the values used for SKNode parameters.

```swift
let node = Node {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
}
.posisition(CGPoint(x: 0, y: 32))
.zRotation(0.5)
.node()

```

Up to 10 widgets can be placed on a single `Node`.

### Extension

Use `Extension` to place more than 10 widgets.

```swift
// case Display
let node = Display()
.place {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
Button(.init("Select_B"))
.position(CGPoint(x: 0, y: 64))
Button(.init("Cancel_B"))
.position(CGPoint(x: 0, y: -64))
HorizontalSingleBarChart(name: .init("Bar"))
//...
Extension {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
Button(.init("Select_B"))
.position(CGPoint(x: 0, y: 64))
Button(.init("Cancel_B"))
.position(CGPoint(x: 0, y: -64))
HorizontalSingleBarChart(name: .init("Bar"))
}
}
.node()
```

Extension is a special widget that cannot generate SKNode.

```swift
let node = Extension {
Button(.init("Select"))
.position(CGPoint(x: 0, y: 32))
Button(.init("Cancel"))
.position(CGPoint(x: 0, y: -32))
Button(.init("Select_B"))
.position(CGPoint(x: 0, y: 64))
Button(.init("Cancel_B"))
.position(CGPoint(x: 0, y: -64))
HorizontalSingleBarChart(name: .init("Bar"))
}
.node() // fatalError
```

## Supported widgets

- Button(beta)
- Bar chart(beta)
### Button(beta)

```swift
let node = Button(.init("Button"))
.node()
```

### Bar chart(beta)

```swift
let node = HorizontalSingleBarChart(name: .init("Bar"))
.node()
```

## Planning to make follows

- Controller stick
### Controller (joy stick)
36 changes: 36 additions & 0 deletions Sources/GameWidget/Controller.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// File.swift
//
//
// Created by rrbox on 2022/08/30.
//

import GameplayKit

/// クリックするとコントローラーが表示される領域
class ControllerAreaNode: SKSpriteNode {
override var isUserInteractionEnabled: Bool {
get { true }
set {}
}

override func mouseDown(with event: NSEvent) {

}
override func mouseDragged(with event: NSEvent) {

}
override func mouseUp(with event: NSEvent) {

}

}

struct ControllerArea: Widget {
var size: CGSize
func node() -> SKNode {
let result = ControllerAreaNode(color: .black, size: self.size)
result.alpha = 0.01
return result
}
}