Files
playdate-kit/Sources/PlaydateKit/Playdate/Enumerations/SystemEvent.swift
T

47 lines
1.6 KiB
Swift
Raw Normal View History

public import CPlaydate
2026-09-18 13:15:08 +00:00
/// An event sent to the game's `eventHandler`. Wraps `PDSystemEvent`; key events carry
/// the event argument.
public enum SystemEvent {
2026-09-18 13:15:08 +00:00
/// Once after the game loads, before the first update.
case initialize
2026-09-18 13:15:08 +00:00
/// 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
2026-09-18 13:15:08 +00:00
/// E.g. the system menu opened.
case pause
case resume
case terminate
2026-09-18 13:15:08 +00:00
/// Simulator only.
case keyPressed(keyCode: UInt32)
2026-09-18 13:15:08 +00:00
/// Simulator only.
case keyReleased(keyCode: UInt32)
2026-09-18 13:15:08 +00:00
/// About to enter low-power sleep because the battery is low.
case lowPower
2026-09-18 13:15:08 +00:00
/// Mirror connected.
case mirrorStarted
2026-09-18 13:15:08 +00:00
/// Mirror disconnected.
case mirrorEnded
2026-09-18 13:15:08 +00:00
/// 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
}
}
}