Promote subsystem namespaces to the top level of the module

System, Display, Graphics, Sprite, Sound, File, JSON, Lua, Scoreboards,
Network, Rect, SystemEvent, and AccessReply now live at module scope
instead of being nested in the Playdate enum; consumers write
System.log(...) instead of Playdate.System.log(...), and can qualify with
the module name (PlayDate.System) on collision. The Playdate enum remains
only as the raw C API bootstrap (initialize(with:), api, apiPointer), and
Playdate.Error is renamed PlaydateError so no top-level type shadows
Swift.Error.

Breaking change for any existing consumers.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 11:10:25 +02:00
co-authored by Claude Fable 5
parent 3ee071e098
commit 6485997edc
22 changed files with 801 additions and 822 deletions
+23 -23
View File
@@ -6,20 +6,20 @@ import Testing
// inline C helpers that work without it.
@Test func buttonsOptionSetMatchesCMasks() {
#expect(Playdate.System.Buttons.left.rawValue == 1 << 0)
#expect(Playdate.System.Buttons.right.rawValue == 1 << 1)
#expect(Playdate.System.Buttons.up.rawValue == 1 << 2)
#expect(Playdate.System.Buttons.down.rawValue == 1 << 3)
#expect(Playdate.System.Buttons.b.rawValue == 1 << 4)
#expect(Playdate.System.Buttons.a.rawValue == 1 << 5)
#expect(System.Buttons.left.rawValue == 1 << 0)
#expect(System.Buttons.right.rawValue == 1 << 1)
#expect(System.Buttons.up.rawValue == 1 << 2)
#expect(System.Buttons.down.rawValue == 1 << 3)
#expect(System.Buttons.b.rawValue == 1 << 4)
#expect(System.Buttons.a.rawValue == 1 << 5)
let combined: Playdate.System.Buttons = [.a, .up]
let combined: System.Buttons = [.a, .up]
#expect(combined.contains(.a))
#expect(!combined.contains(.b))
}
@Test func graphicsRectConvertsBetweenOriginSizeAndEdges() {
let rect = Playdate.Graphics.Rect(x: 10, y: 20, width: 30, height: 40)
let rect = Graphics.Rect(x: 10, y: 20, width: 30, height: 40)
#expect(rect.left == 10)
#expect(rect.right == 40)
#expect(rect.top == 20)
@@ -29,13 +29,13 @@ import Testing
#expect(translated.left == 15)
#expect(translated.top == 15)
let roundTripped = Playdate.Graphics.Rect(rect.cValue)
let roundTripped = Graphics.Rect(rect.cValue)
#expect(roundTripped.left == rect.left && roundTripped.bottom == rect.bottom)
}
@Test func spriteRectRoundTripsThroughC() {
let rect = Playdate.Rect(x: 1.5, y: 2.5, width: 3, height: 4)
let roundTripped = Playdate.Rect(rect.cValue)
let rect = Rect(x: 1.5, y: 2.5, width: 3, height: 4)
let roundTripped = Rect(rect.cValue)
#expect(roundTripped.x == 1.5)
#expect(roundTripped.y == 2.5)
#expect(roundTripped.width == 3)
@@ -43,23 +43,23 @@ import Testing
}
@Test func soundFormatPropertiesMatchCMacros() {
#expect(!Playdate.Sound.Format.mono8bit.isStereo)
#expect(Playdate.Sound.Format.stereo16bit.isStereo)
#expect(Playdate.Sound.Format.mono16bit.is16bit)
#expect(!Playdate.Sound.Format.monoADPCM.is16bit)
#expect(!Sound.Format.mono8bit.isStereo)
#expect(Sound.Format.stereo16bit.isStereo)
#expect(Sound.Format.mono16bit.is16bit)
#expect(!Sound.Format.monoADPCM.is16bit)
#expect(Playdate.Sound.Format.mono8bit.bytesPerFrame == 1)
#expect(Playdate.Sound.Format.stereo8bit.bytesPerFrame == 2)
#expect(Playdate.Sound.Format.mono16bit.bytesPerFrame == 2)
#expect(Playdate.Sound.Format.stereo16bit.bytesPerFrame == 4)
#expect(Sound.Format.mono8bit.bytesPerFrame == 1)
#expect(Sound.Format.stereo8bit.bytesPerFrame == 2)
#expect(Sound.Format.mono16bit.bytesPerFrame == 2)
#expect(Sound.Format.stereo16bit.bytesPerFrame == 4)
}
@Test func midiNoteFrequencyConversionRoundTrips() {
// A4 (MIDI 69) is 440 Hz.
let a4 = Playdate.Sound.frequency(forNote: 69)
let a4 = Sound.frequency(forNote: 69)
#expect(abs(a4 - 440) < 0.01)
let note = Playdate.Sound.note(forFrequency: 440)
let note = Sound.note(forFrequency: 440)
#expect(abs(note - 69) < 0.001)
}
@@ -74,9 +74,9 @@ import Testing
}
@Test func dateTimeMirrorsCStruct() {
let dateTime = Playdate.System.DateTime(year: 2026, month: 7, day: 24, weekday: 5,
let dateTime = System.DateTime(year: 2026, month: 7, day: 24, weekday: 5,
hour: 12, minute: 34, second: 56)
let roundTripped = Playdate.System.DateTime(dateTime.cValue)
let roundTripped = System.DateTime(dateTime.cValue)
#expect(roundTripped.year == 2026)
#expect(roundTripped.month == 7)
#expect(roundTripped.day == 24)