Files
playdate-kit/Sources/PlaydateKit/Playdate/Enumerations/SystemEvent.swift
T
javier c5037dd716 Swift 6.4 migration and exhancements (#1)
This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it.

Reviewed-on: #1
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
2026-09-18 13:15:08 +00:00

47 lines
1.6 KiB
Swift

public import CPlaydate
/// An event sent to the game's `eventHandler`. Wraps `PDSystemEvent`; key events carry
/// the event argument.
public enum SystemEvent {
/// Once after the game loads, before the first update.
case initialize
/// After `initialize` if no update callback is set, once Lua exists and before
/// `main.lua` runs; register Lua functions and classes here.
case initializeLua
case lock
case unlock
/// E.g. the system menu opened.
case pause
case resume
case terminate
/// Simulator only.
case keyPressed(keyCode: UInt32)
/// Simulator only.
case keyReleased(keyCode: UInt32)
/// About to enter low-power sleep because the battery is low.
case lowPower
/// Mirror connected.
case mirrorStarted
/// Mirror disconnected.
case mirrorEnded
/// From the `eventHandler` arguments; `nil` for events this binding doesn't know.
public init?(event: PDSystemEvent, argument: UInt32) {
switch event {
case kEventInit: self = .initialize
case kEventInitLua: self = .initializeLua
case kEventLock: self = .lock
case kEventUnlock: self = .unlock
case kEventPause: self = .pause
case kEventResume: self = .resume
case kEventTerminate: self = .terminate
case kEventKeyPressed: self = .keyPressed(keyCode: argument)
case kEventKeyReleased: self = .keyReleased(keyCode: argument)
case kEventLowPower: self = .lowPower
case kEventMirrorStarted: self = .mirrorStarted
case kEventMirrorEnded: self = .mirrorEnded
default: return nil
}
}
}