A port of the SDK for Firefly Zero, a modern handheld game console using WebAssembly
moon add applejag/firefly{
"is-main": true,
"import": [
"applejag/firefly"
],
"link": {
"wasm": {
"exports": ["boot", "update", "render", "before_exit"],
"export-memory-name": "memory"
}
}
}///|
/// `main` is called immediately on startup.
///
/// MoonBit requires the presence of a `main` function, but Firely Zero
/// recommends that you use `boot` for any initialization logic.
fn main {
// keep this function empty
}
///|
/// `boot` is only called once, after all the memory is initialized and all
/// runtime functions are available but before any other callback is called.
///
/// This is the best place to load fonts, sprites, and other assets,
/// initialize the default state, read configurations, etc.
pub fn boot() -> Unit {
@firefly.log_debug("entering boot") // placeholder for demonstration purposes
}
///|
/// `before_exit` is called before the app is closed.
pub fn before_exit() -> Unit {
@firefly.log_debug("entering before_exit") // placeholder for demonstration purposes
}
///|
/// `update` is called ~60 times per second.
///
/// It is guaranteed to be never called more often, and it won’t be called less
/// often if the game doesn’t consume too much resources.
/// This is the best place to update the state of objects, position of NPCs,
/// read and handle user input, etc.
pub fn update() -> Unit {
@firefly.log_debug("entering update") // placeholder for demonstration purposes
}
///|
/// `render` is called before updating the image on the screen.
///
/// It might be called less often than `update` if the device sees that the game
/// is slow and needs more resources.
/// This is the best place to call all drawing functions.
pub fn render() -> Unit {
@firefly.log_debug("entering render") // placeholder for demonstration purposes
}author_id = "yourname"
app_id = "your-app-id"
author_name = "Your Name"
app_name = "Your App Name"
[files]
_bin = { path = "./target/wasm/release/build/<moonbit app name>.wasm", copy = true }moon build --target wasm
firefly_cli build
firefly-emulator --id yourname.your-app-idtypealias @firefly.Angle
typealias @firefly.Color
typealias @firefly.LineStyle
typealias @firefly.Point
typealias @firefly.Size
typealias @firefly.Style
fn render() -> Unit {
// Instead of this:
@firefly.draw_rect(
@firefly.Point::new(102, 78),
@firefly.Size::new(29, 9),
@firefly.Style::new_solid(Red),
)
// You can write this:
@firefly.draw_rect(
Point::new(102, 78),
Size::new(29, 9),
Style::new_solid(Red),
)
}task example/input:run
task example/shapes:runpub type Angle Floatpub(all) struct Buttons {
south : Bool
east : Bool
west : Bool
north : Bool
menu : Bool
}pub type Canvas FixedArray[Byte]pub(all) enum Color {
None
Black
Purple
Red
Orange
Yellow
LightGreen
Green
DarkGreen
DarkBlue
Blue
LightBlue
Cyan
White
LightGray
Gray
DarkGray
}pub(all) struct DPad {
left : Bool
right : Bool
up : Bool
down : Bool
}pub type File FixedArray[Byte]pub type Font FixedArray[Byte]pub type Image FixedArray[Byte]pub(all) struct Pad {
x : Int
y : Int
}pub type Peer Bytepub(all) struct Point {
x : Int
y : Int
}pub(all) struct RGB {
r : Byte
g : Byte
b : Byte
}pub(all) struct Size {
w : UInt
h : UInt
}let DPAD_THRESHOLD : Intlet PEER_COMBINED : Bytefn dump_bytes_to_file(path : String, bytes : Bytes) -> UIntfn get_file_size(path : String) -> UIntfn is_file(path : String) -> Boolfn load_file_to(path : String, output : FixedArray[Byte]) -> UIntfn load_file_to_bytes(path : String) -> Bytes?fn remove_file(path : String) -> Unitfn unset_canvas() -> UnitInstall
Download zipA port of the SDK for Firefly Zero, a modern handheld game console using WebAssembly