Add DocC documentation and a runnable example game
- DocC catalog (Sources/PlayDate/PlayDate.docc) with a curated landing page and a Getting Started article; swift-docc-plugin wired up for `swift package generate-documentation`, and a GitHub Pages deployment workflow renders docs on every push to main. - Examples/HelloPlaydate: a minimal game (bouncing box, crank needle, button handling, system menu item) whose build.sh compiles the game as a dylib and produces a runnable simulator .pdx via the SDK's pdc. Verified: the pdx builds and exports the eventHandler entry point. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// swift-tools-version: 6.4
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "HelloPlaydate",
|
||||
products: [
|
||||
// The Playdate Simulator loads the game as pdex.dylib.
|
||||
.library(name: "pdex", type: .dynamic, targets: ["HelloPlaydate"]),
|
||||
],
|
||||
dependencies: [
|
||||
.package(path: "../.."),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "HelloPlaydate",
|
||||
dependencies: [.product(name: "PlayDate", package: "play-date")]
|
||||
),
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,23 @@
|
||||
# Hello Playdate
|
||||
|
||||
A minimal game built on the `play-date` bindings: a bouncing box, a
|
||||
crank-aimed needle, button handling, a system menu item, and an FPS counter.
|
||||
|
||||
## Build and run (Playdate Simulator)
|
||||
|
||||
With the Playdate SDK installed (and the one-time
|
||||
`Scripts/install-pkgconfig.sh` setup from the repository root done):
|
||||
|
||||
```sh
|
||||
./build.sh
|
||||
open -a "$HOME/Developer/PlaydateSDK/bin/Playdate Simulator.app" HelloPlaydate.pdx
|
||||
```
|
||||
|
||||
The script compiles the game as a dylib, places it in `Source/` next to
|
||||
`pdxinfo`, and runs the SDK's `pdc` to produce `HelloPlaydate.pdx`.
|
||||
|
||||
## Device builds
|
||||
|
||||
Running on hardware requires the Embedded Swift + ARM toolchain pipeline
|
||||
(see the repository README and Apple's swift-playdate-examples for the
|
||||
Makefile setup). This example covers the simulator workflow only.
|
||||
@@ -0,0 +1,6 @@
|
||||
name=Hello Playdate
|
||||
author=Röck+Cöde
|
||||
description=Minimal example for the play-date Swift bindings
|
||||
bundleID=com.rock-n-code.hello-playdate
|
||||
version=0.1
|
||||
buildNumber=1
|
||||
@@ -0,0 +1,97 @@
|
||||
//
|
||||
// Game.swift
|
||||
// A minimal Playdate game built on the play-date Swift bindings: a
|
||||
// bouncing box, a crank-aimed needle, button logging, and a system menu
|
||||
// item.
|
||||
//
|
||||
|
||||
import CPlaydate
|
||||
import PlayDate
|
||||
|
||||
@_cdecl("eventHandler")
|
||||
public func eventHandler(
|
||||
pointer: UnsafeMutableRawPointer,
|
||||
event: PDSystemEvent,
|
||||
argument: UInt32
|
||||
) -> Int32 {
|
||||
if case .initialize = SystemEvent(event: event, argument: argument) {
|
||||
Playdate.initialize(with: pointer) // must happen before anything else
|
||||
Game.shared.start()
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
final class Game {
|
||||
nonisolated(unsafe) static let shared = Game()
|
||||
|
||||
private var x: Float = 200
|
||||
private var y: Float = 120
|
||||
private var dx: Float = 3
|
||||
private var dy: Float = 2
|
||||
private let boxSize = 24
|
||||
|
||||
func start() {
|
||||
Display.setRefreshRate(50)
|
||||
|
||||
System.addMenuItem(title: "reset") { _ in
|
||||
Game.shared.reset()
|
||||
}
|
||||
|
||||
System.setUpdateCallback {
|
||||
Game.shared.update()
|
||||
return true // redraw the display this frame
|
||||
}
|
||||
}
|
||||
|
||||
private func reset() {
|
||||
x = 200
|
||||
y = 120
|
||||
}
|
||||
|
||||
private func update() {
|
||||
moveBox()
|
||||
handleInput()
|
||||
draw()
|
||||
}
|
||||
|
||||
private func moveBox() {
|
||||
let width = Float(Display.width)
|
||||
let height = Float(Display.height)
|
||||
|
||||
x += dx
|
||||
y += dy
|
||||
if x < 0 || x > width - Float(boxSize) { dx = -dx }
|
||||
if y < 24 || y > height - Float(boxSize) { dy = -dy }
|
||||
}
|
||||
|
||||
private func handleInput() {
|
||||
let (_, pushed, _) = System.buttonState
|
||||
if pushed.contains(.a) {
|
||||
System.log("A pressed at \(System.currentTimeMilliseconds)ms")
|
||||
}
|
||||
if pushed.contains(.b) {
|
||||
(dx, dy) = (-dx, -dy)
|
||||
}
|
||||
}
|
||||
|
||||
private func draw() {
|
||||
Graphics.clear(color: .white)
|
||||
Graphics.drawText("Hëllo from Swift — Ⓑ reverses", x: 8, y: 4)
|
||||
Graphics.fillRect(x: Int(x), y: Int(y), width: boxSize, height: boxSize, color: .black)
|
||||
|
||||
if !System.isCrankDocked {
|
||||
// A needle from the screen center pointing where the crank points.
|
||||
let radians = System.crankAngle * .pi / 180
|
||||
let centerX = Display.width / 2
|
||||
let centerY = Display.height / 2
|
||||
Graphics.drawLine(
|
||||
x1: centerX, y1: centerY,
|
||||
x2: centerX + Int(40 * sinf(radians)),
|
||||
y2: centerY - Int(40 * cosf(radians)),
|
||||
width: 2, color: .xor)
|
||||
}
|
||||
|
||||
System.drawFPS(x: 380, y: 4)
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Builds HelloPlaydate.pdx for the Playdate Simulator: compiles the game as
|
||||
# a dylib, places it in the pdc source folder, and runs the SDK's pdc.
|
||||
#
|
||||
# Device builds need the Embedded Swift + ARM toolchain setup described in
|
||||
# the repository README; this script covers the simulator only.
|
||||
|
||||
set -eu
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
sdk_path="${PLAYDATE_SDK_PATH:-$HOME/Developer/PlaydateSDK}"
|
||||
|
||||
swift build -c release
|
||||
bin_path="$(swift build -c release --show-bin-path)"
|
||||
cp "$bin_path/libpdex.dylib" Source/pdex.dylib
|
||||
|
||||
"$sdk_path/bin/pdc" Source HelloPlaydate.pdx
|
||||
|
||||
echo "Built HelloPlaydate.pdx — run it with:"
|
||||
echo " open -a \"$sdk_path/bin/Playdate Simulator.app\" HelloPlaydate.pdx"
|
||||
Reference in New Issue
Block a user