Skip to content
Merged
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions firefly/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ func addProgress(peerID, badgeID uint32, val int32) uint32
//go:wasmimport stats add_score
func addScore(peerID, boardID uint32, val int32) int32

// -- MENU -- //

//go:wasmimport menu add_menu_item
func addMenuItem(index uint32, ptr unsafe.Pointer, size uint32)

//go:wasmimport menu remove_menu_item
func removeMenuItem(index uint32)

//go:wasmimport menu open_menu
func openMenu()

// -- MISC -- //

//go:wasmimport misc log_debug
Expand Down
13 changes: 13 additions & 0 deletions firefly/callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ var (
//
// Accepts the command index and value and returns a response to show in CLI.
Cheat func(int, int) int

// Callback to be called when a custom menu item is selected.
HandleMenu func(MenuItem)
)

//go:export boot
Expand Down Expand Up @@ -62,10 +65,20 @@ func cheat(c, v int32) int32 {
return 0
}

//go:export handle_menu
func handleMenu(i int32) {
if HandleMenu != nil {
HandleMenu(MenuItem(i))
}
}

// Suppress warning about unused private function
// (the linter doesn't account for "go:export").
var (
_ = boot
_ = update
_ = render
_ = beforeExit
_ = cheat
_ = handleMenu
)
19 changes: 19 additions & 0 deletions firefly/menu.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package firefly

import "unsafe"

type MenuItem uint8

func OpenMenu() {
openMenu()
}

func AddMenuItem(i MenuItem, name string) {
ptr := unsafe.Pointer(unsafe.StringData(name))
size := uint32(len(name))
addMenuItem(uint32(i), ptr, size)
}

func RemoveMenuItem(i MenuItem) {
removeMenuItem(uint32(i))
}
Loading