Created
May 8, 2026 09:12
-
-
Save martinpi/74ecadd662312761ee363d158e2d0f2d to your computer and use it in GitHub Desktop.
Tokebi analytics C# header for Godot
This file contains hidden or 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
| namespace SparrowWarfare; | |
| using Godot; | |
| using Godot.Collections; | |
| /* | |
| Change necessary to tokebi.gd: add the following 2 lines to _ready(): | |
| if not Engine.has_singleton("Tokebi"): | |
| Engine.register_singleton("Tokebi", self) | |
| This registers the singleton so that it can be found from C#. | |
| */ | |
| public static class Tokebi { | |
| private static Node? instance; | |
| public static Node Instance { | |
| get { | |
| if (instance == null) { | |
| instance = (Node)Engine.GetSingleton("Tokebi"); | |
| } | |
| return instance; | |
| } | |
| } | |
| public static void Track(string event_type, Dictionary? payload = null, bool force_track = false) { | |
| if (payload == null) { | |
| Instance.Call("track", event_type); | |
| } | |
| else { | |
| Instance.Call("track", event_type, payload, force_track); | |
| } | |
| } | |
| public static void TrackLevelStart(string level) { | |
| Instance.Call("track_level_start", level); | |
| } | |
| public static void TrackLevelComplete(string level, float time_taken) { | |
| Instance.Call("track_level_complete", level, time_taken); | |
| } | |
| public static void TrackClientEvent(string event_type, Dictionary? payload = null) { | |
| if (payload == null) { | |
| Instance.Call("track_client_event", event_type); | |
| } | |
| else { | |
| Instance.Call("track_client_event", event_type, payload); | |
| } | |
| } | |
| public static void TrackDraftOptions(string[] cards, string picked_card, WorldState worldState) { | |
| var eventData = new Godot.Collections.Dictionary { | |
| { "mode", worldState.Session.PlayMode.ToString() }, | |
| { "progress", worldState.Session.Progress }, | |
| { "way", worldState.Session.Way }, | |
| { "level", worldState.Session.Level }, | |
| { "tile_picked", picked_card }, | |
| }; | |
| var count = 0; | |
| for (int i = 0; i < cards.Length; i++) { | |
| if (cards[i] != picked_card) { | |
| eventData[$"tile_rejected_{count}"] = cards[i]; | |
| count++; | |
| } | |
| } | |
| Tokebi.Track("pick_tile", eventData); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment