-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
861 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
[package] | ||
name = "playdate-scoreboards" | ||
version = "0.1.0" | ||
readme = "README.md" | ||
description = "High-level Scoreboards API built on-top of Playdate API" | ||
keywords = ["playdate", "sdk", "api", "gamedev"] | ||
categories = ["game-development", "api-bindings", "no-std"] | ||
edition.workspace = true | ||
license.workspace = true | ||
authors.workspace = true | ||
homepage.workspace = true | ||
repository.workspace = true | ||
|
||
|
||
[features] | ||
default = ["sys/default"] | ||
|
||
# playdate-sys features, should be shared because it's build configuration: | ||
|
||
bindgen-runtime = ["sys/bindgen-runtime"] | ||
bindgen-static = ["sys/bindgen-static"] | ||
bindings-derive-debug = ["sys/bindings-derive-debug"] | ||
|
||
|
||
[dependencies] | ||
sys = { workspace = true, default-features = false } | ||
erased_set = "0.7.0" | ||
|
||
|
||
[dev-dependencies] | ||
system = { workspace = true, default-features = false, features = [ "try-trait-v2" ] } | ||
|
||
|
||
[[example]] | ||
name = "boards" | ||
crate-type = ["dylib", "staticlib"] | ||
path = "examples/boards.rs" | ||
required-features = ["sys/lang-items", "sys/entry-point"] | ||
|
||
[package.metadata.playdate] | ||
bundle-id = "rs.playdate.scoreboards" | ||
|
||
|
||
[package.metadata.docs.rs] | ||
all-features = false | ||
features = [ | ||
"bindings-derive-default", | ||
"bindings-derive-eq", | ||
"bindings-derive-copy", | ||
"bindings-derive-debug", | ||
"bindings-derive-hash", | ||
"bindings-derive-ord", | ||
"bindings-derive-partialeq", | ||
"bindings-derive-partialord", | ||
] | ||
rustdoc-args = ["--cfg", "docsrs", "--show-type-layout"] | ||
default-target = "thumbv7em-none-eabihf" | ||
cargo-args = [ | ||
"-Zunstable-options", | ||
"-Zrustdoc-scrape-examples", | ||
"-Zbuild-std=core,alloc", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Scoreboards API for PlayDate | ||
|
||
High-level scoreboards API built on-top of [playdate-sys][]. | ||
|
||
|
||
## Usage | ||
|
||
```rust | ||
use playdate_scoreboards::*; | ||
use playdate_sys::println; | ||
|
||
let scoreboards = Scoreboards::Cached(); | ||
|
||
scoreboards.get_scoreboards(|boards| { | ||
println!("{boards:?}"); | ||
}); | ||
``` | ||
|
||
|
||
[playdate-sys]: https://crates.io/crates/playdate-sys | ||
|
||
|
||
|
||
- - - | ||
|
||
This software is not sponsored or supported by Panic. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#![no_std] | ||
extern crate alloc; | ||
use core::ptr::NonNull; | ||
|
||
#[macro_use] | ||
extern crate sys; | ||
extern crate playdate_scoreboards as scoreboards; | ||
|
||
use sys::EventLoopCtrl; | ||
use sys::ffi::*; | ||
use system::prelude::*; | ||
|
||
use scoreboards::ScoresResult; | ||
use scoreboards::Scoreboards; | ||
|
||
|
||
/// Entry point | ||
#[no_mangle] | ||
fn event_handler(_: NonNull<PlaydateAPI>, event: SystemEvent, _: u32) -> EventLoopCtrl { | ||
// Ignore any other events, just for this minimalistic example | ||
if !matches!(event, SystemEvent::Init) { | ||
return EventLoopCtrl::Continue; | ||
} | ||
|
||
const BOARD_ID: &str = "ID101"; | ||
|
||
let scoreboards = Scoreboards::Cached(); | ||
|
||
let res = scoreboards.add_score(BOARD_ID, 42, |res| { | ||
println!("Add score callback"); | ||
match res { | ||
Ok(_) => println!("scores added"), | ||
Err(err) => println!("{err}"), | ||
} | ||
}); | ||
match res { | ||
Ok(_) => println!("add_score res: F"), | ||
Err(err) => println!("add_score res: ERR: {err}"), | ||
} | ||
|
||
|
||
scoreboards.get_scoreboards(|boards| { | ||
println!("1: Get boards callback"); | ||
println!("{boards:?}"); | ||
}); | ||
scoreboards.get_scoreboards(|boards| { | ||
println!("2: Get boards callback"); | ||
println!("{boards:?}"); | ||
}); | ||
|
||
|
||
fn get_scores(scores: ScoresResult<scoreboards::Scores>) { | ||
println!("1: Get scores callback"); | ||
println!("{scores:?}"); | ||
} | ||
|
||
scoreboards.get_scores(BOARD_ID, get_scores).ok(); | ||
scoreboards.get_scores(BOARD_ID, |res| { | ||
println!("2: Get scores callback"); | ||
println!("{res:?}"); | ||
}) | ||
.ok(); | ||
|
||
|
||
scoreboards.get_personal_best(BOARD_ID, |res| { | ||
println!("Get personal best callback"); | ||
match res { | ||
Ok(_) => todo!("scores received"), | ||
Err(err) => println!("{err}"), | ||
} | ||
}) | ||
.ok(); | ||
|
||
|
||
// Set no-op update callback | ||
system::System::Default().set_update_callback_boxed(|_| UpdateCtrl::Continue, ()); | ||
|
||
EventLoopCtrl::Continue | ||
} | ||
|
||
|
||
// Needed for debug build | ||
ll_symbols!(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use core::ffi::c_char; | ||
use alloc::borrow::Cow; | ||
use sys::ffi::CStr; | ||
|
||
|
||
pub type ApiError = sys::error::Error<self::Error>; | ||
|
||
|
||
#[derive(Debug, Clone)] | ||
#[must_use = "Error message doesn’t live long enough"] | ||
pub enum Error { | ||
Response(Cow<'static, str>), | ||
|
||
/// Unknown error. | ||
/// Usually means invalid input or something not found. | ||
Unknown, | ||
} | ||
|
||
impl Error { | ||
pub fn from_ptr(ptr: *const c_char) -> Option<Self> { | ||
if ptr.is_null() { | ||
None | ||
} else { | ||
let s = unsafe { CStr::from_ptr(ptr as _) }.to_string_lossy(); | ||
Self::Response(s).into() | ||
} | ||
} | ||
} | ||
|
||
impl core::fmt::Display for Error { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
Error::Response(s) => write!(f, "{s}"), | ||
Error::Unknown => write!(f, "Unknown"), | ||
} | ||
} | ||
} | ||
|
||
impl core::error::Error for Error {} | ||
|
||
impl Into<ApiError> for Error { | ||
fn into(self) -> ApiError { ApiError::Api(self) } | ||
} |
Oops, something went wrong.