Code Monkey home page Code Monkey logo

playdatekit's Introduction

PlaydateKit Logo

PlaydateKit

PlaydateKit provides easy to use Swift bindings for the Playdate C API. PlaydateKit aims to be as Swift-y as possible, replacing error pointers with throwable functions, avoiding the use of pointers as much as possible, and adding documentation comments to all functions (taken directly from the Playdate SDK docs).

PlaydateKit is still very much WIP.

Status

PlaydateKit aims to provide full coverage of the Playdate C API. To start out with, the Swift API closely follows the C API, meaning it is completely functional. I would like to make it more object-oriented soon, meaning wrapper types for things like frames, bitmaps, sprites, etc.

Currently, the following sections of the API are implemented:

  • Display
  • File
  • Graphics
  • JSON
  • Lua
  • Scoreboards
  • Sound
  • Sprite
  • System

Usage

For example usage, see the BasicExample here. I strongly recommend reading through the Swift Playdate Examples documentation here for information on downloading required tools, setting up build scripts, and compiling for Playdate.

Besides the complicated build setup, this is all it takes to create a simple "game" that adds a menu item:

public import CPlaydate
import PlaydateKit

@_cdecl("update") func update(_: UnsafeMutableRawPointer!) -> Int32 { 1 }

@_cdecl("eventHandler") public func eventHandler(
    pointer: UnsafeMutableRawPointer!,
    event: PDSystemEvent,
    _: UInt32
) -> Int32 {
    let playdate = pointer.bindMemory(to: PlaydateAPI.self, capacity: 1)
    if event == .initialize {
        Playdate.initialize(with: playdate)
        Playdate.System.setUpdateCallback(update: update, userdata: nil)

        _ = Playdate.System.addMenuItem(title: "PlaydateKit") { _ in
            Playdate.System.logToConsole(format: "PlaydateKit selected!")
        }
    }
    return 0
}

I would like to investigate ways to avoid this boilerplate, perhaps providing a macro similar to SwiftGodot.

The Makefile in the example project requires compiling the PlaydateKit source files, meaning you will need to have PlaydateKit checked out locally and update your Makefile to point to it (you can't just add PlaydateKit as a package dependency). I am investigating ways to improve this, for now you could probably add a git submodule or something ๐Ÿคทโ€โ™‚๏ธ

Acknowledgements

PlaydateKit was inspired by and would not be possible without the excellent work done by @rauhul on swift-playdate-examples. Specifically, PlaydateKit was created due to the note in the swift-playdate-examples repo:

It is not intended to be a full-featured Playdate SDK so please do not raise PRs to extend the Playdate Swift overlay to new areas.

The example project build scripts as well as most of CPlaydate were copied from swift-playdate-examples, and as such fall under the Apache License 2.0 found here.

playdatekit's People

Contributors

finnvoor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.