Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 198 additions & 14 deletions playdate/playdate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ require("playdate.json")

-- ████████╗██╗███╗ ███╗███████╗
-- ╚══██╔══╝██║████╗ ████║██╔════╝
-- ██║ ██║██╔████╔██║█████╗
-- ██║ ██║██║╚██╔╝██║██╔══╝
-- ██║ ██║██╔████╔██║█████╗
-- ██║ ██║██║╚██╔╝██║██╔══╝
-- ██║ ██║██║ ╚═╝ ██║███████╗
-- ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝


local startTime = love.timer.getTime()

function module.getTime()
local seconds = os.time()
local date = os.date("*t", seconds)
Expand All @@ -32,10 +34,78 @@ function module.getTime()
}
end

function module.wait(milliseconds)
love.timer.sleep(milliseconds / 1000)
end

function module.stop()
error("[ERR] playdate.stop() is not yet implemented.")
end

function module.start()
error("[ERR] playdate.start() is not yet implemented.")
end

function module.restart(arg)
error("[ERR] playdate.restart() is not yet implemented.")
end

function module.restart()
error("[ERR] playdate.restart() is not yet implemented.")
end

function module.getSystemMenu()
error("[ERR] playdate.getSystemMenu() is not yet implemented.")
end

function module.setMenuImage(image, xOffset)
error("[ERR] playdate.setMenuImage() is not yet implemented.")
end

function module.getSystemLanguage()
error("[ERR] playdate.getSystemLanguage() is not yet implemented.")
end

function module.getReduceFlashing()
error("[ERR] playdate.getReduceFlashing() is not yet implemented.")
end

function module.getFlipped()
error("[ERR] playdate.getFlipped() is not yet implemented.")
end

function module.startAccelerometer()
error("[ERR] playdate.startAccelerometer() is not yet implemented.")
end

function module.stopAccelerometer()
error("[ERR] playdate.stopAccelerometer() is not yet implemented.")
end

function module.readAccelerometer()
error("[ERR] playdate.readAccelerometer() is not yet implemented.")
end

function module.accelerometerIsRunning()
error("[ERR] playdate.accelerometerIsRunning() is not yet implemented.")
end

function module.setAutoLockDisabled(disable)
error("[ERR] playdate.setAutoLockDisabled() is not yet implemented.")
end

function module.getCurrentTimeMilliseconds()
return love.timer.getTime() * 1000
end

function module.resetElapsedTime()
startTime = love.timer.getTime()
end

function module.getElapsedTime()
return love.timer.getTime() - startTime
end

function module.getSecondsSinceEpoch()
-- os.time() without params always returns in system local time, so we must convert to UTC
local nowLocal = os.time()
Expand All @@ -55,13 +125,45 @@ function module.getSecondsSinceEpoch()
return os.difftime(nowUtc, playdateEpochUtc), milliseconds
end

function module.getTime()
error("[ERR] playdate.getTime() is not yet implemented.")
end

function module.getGMTTime()
error("[ERR] playdate.getGMTTime() is not yet implemented.")
end

function module.epochFromTime(time)
error("[ERR] playdate.epochFromTime() is not yet implemented.")
end

function module.epochFromGMTTime(time)
error("[ERR] playdate.epochFromTime() is not yet implemented.")
end

function module.timeFromEpoch(seconds, milliseconds)
error("[ERR] playdate.timeFromEpoch() is not yet implemented.")
end

function module.GMTTimeFromEpoch(seconds, milliseconds)
error("[ERR] playdate.GMTTimeFromEpoch() is not yet implemented.")
end

function module.getServerTime(callback)
error("[ERR] playdate.getServerTime() is not yet implemented.")
end

function module.shouldDisplay24HourTime()
error("[ERR] playdate.shouldDisplay24HourTime() is not yet implemented.")
end

-- ██╗███╗ ██╗██████╗ ██╗ ██╗████████╗
-- ██║████╗ ██║██╔══██╗██║ ██║╚══██╔══╝
-- ██║██╔██╗ ██║██████╔╝██║ ██║ ██║
-- ██║██║╚██╗██║██╔═══╝ ██║ ██║ ██║
-- ██║██║ ╚████║██║ ╚██████╔╝ ██║
-- ╚═╝╚═╝ ╚═══╝╚═╝ ╚═════╝ ╚═╝
-- ██║██╔██╗ ██║██████╔╝██║ ██║ ██║
-- ██║██║╚██╗██║██╔═══╝ ██║ ██║ ██║
-- ██║██║ ╚████║██║ ╚██████╔╝ ██║
-- ╚═╝╚═╝ ╚═══╝╚═╝ ╚═════╝ ╚═╝

local lastActiveJoystick = nil
local isCrankDocked = false
local crankPos = 0
Expand Down Expand Up @@ -126,6 +228,10 @@ function module.getButtonState(button)
return value == PRESSED, value == PRESSED, value == JUST_RELEASED
end

function module.setButtonQueueSize(size)
error("[ERR] playdate.setButtonQueueSize() is not yet implemented.")
end

function module.isCrankDocked()
if not lastActiveJoystick then
return isCrankDocked
Expand All @@ -147,7 +253,7 @@ end
function module.getCrankChange()
local change = playbit.geometry.angleDiff(lastCrankPos, crankPos)
-- TODO: how does the playdate accelerate this?
local acceleratedChange = change
local acceleratedChange = change
return change, acceleratedChange
end

Expand All @@ -173,6 +279,14 @@ function module.getCrankPosition()
return degrees
end

function module.getCrankTicks(ticksPerRevolution)
error("[ERR] playdate.getCrankTicks() is not yet implemented.")
end

function module.setCrankSoundsDisabled(disable)
error("[ERR] playdate.getCrankTicks() is not yet implemented.")
end

function love.joystickadded(joystick)
-- always take most recently added joystick as active joystick
lastActiveJoystick = joystick
Expand Down Expand Up @@ -218,7 +332,7 @@ function love.wheelmoved(x, y)
-- TODO: emulate PD crank acceleration?
-- TODO: configure scroll sensitivity?
crankPos = crankPos + -y * 6

if crankPos < 0 then
crankPos = 359
elseif crankPos > 359 then
Expand Down Expand Up @@ -289,7 +403,7 @@ function love.keypressed(key)
end
end

function love.keyreleased(key)
function love.keyreleased(key)
inputStates["kb_"..key] = JUST_RELEASED

if playbit.keyReleased then
Expand All @@ -315,13 +429,25 @@ function module.updateInput()
lastCrankPos = crankPos
end

-- ██╗ ██╗ ██╗ █████╗
function module.setNewlinePrinted(flag)
error("[ERR] playdate.setNewlinePrinted() is not yet implemented.")
end

function module.getFPS()
return love.timer.getFPS()
end

function module.drawFPS(x, y)
-- not implemented yet, but do not produce errors
end

-- ██╗ ██╗ ██╗ █████╗
-- ██║ ██║ ██║██╔══██╗
-- ██║ ██║ ██║███████║
-- ██║ ██║ ██║██╔══██║
-- ███████╗╚██████╔╝██║ ██║
-- ╚══════╝ ╚═════╝ ╚═╝ ╚═╝

function table.indexOfElement(table, element)
for i = 1, #table do
if table[i] == element then
Expand All @@ -331,6 +457,24 @@ function table.indexOfElement(table, element)
return nil
end

function table.getsize(table)
error("[ERR] table.getsize() is not yet implemented.")
end

function table.create(arrayCount, hashCount)
return { }
end

function table.shallowcopy(source, destination)
destination = destination or {}
playbit.util.shallowCopy(destination, source)
return destination
end

function table.deepcopy(source)
error("[ERR] table.deepcopy() is not yet implemented.")
end

function printTable(...)
error("[ERR] printTable() is not yet implemented.")
end
Expand All @@ -340,11 +484,51 @@ function sample()
error("[ERR] sample() is not yet implemented.")
end

function module.getStats()
error("[ERR] playdate.getStats() is not yet implemented.")
end

function module.setStatsInterval(seconds)
error("[ERR] playdate.setStatsInterval() is not yet implemented.")
end

function where()
error("[ERR] where() is not yet implemented.")
end

function module.apiVersion()
-- TODO: return Playbit version instead?
error("[ERR] playdate.apiVersion() is not yet implemented.")
end
end

function module.getPowerStatus()
error("[ERR] playdate.getPowerStatus() is not yet implemented.")
end

function module.getBatteryPercentage()
error("[ERR] playdate.getBatteryPercentage() is not yet implemented.")
end

function module.getBatteryVoltage()
error("[ERR] playdate.getBatteryVoltage() is not yet implemented.")
end

function module.clearConsole()
error("[ERR] playdate.clearConsole() is not yet implemented.")
end

function module.setDebugDrawColor(r, g, b, a)
error("[ERR] playdate.setDebugDrawColor() is not yet implemented.")
end

function module.setCollectsGarbage(flag)
error("[ERR] playdate.setCollectsGarbage() is not yet implemented.")
end

function module.setMinimumGCTime(ms)
error("[ERR] playdate.setMinimumGCTime() is not yet implemented.")
end

function module.setGCScaling(min, max)
error("[ERR] playdate.setGCScaling() is not yet implemented.")
end