From 7226929abee63d7bbe24b08514e37f4725534e86 Mon Sep 17 00:00:00 2001 From: Jonathan Stevens Date: Wed, 27 Mar 2024 18:11:35 -0700 Subject: [PATCH 1/2] Implement API for obtaining glasses display names --- example.csharp/addons/tiltfive/T5Interface.cs | 13 +++++++++++++ example.csharp/addons/tiltfive/T5Manager.cs | 5 ++++- extension/src/TiltFiveXRInterface.cpp | 12 ++++++++++++ extension/src/TiltFiveXRInterface.h | 2 ++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/example.csharp/addons/tiltfive/T5Interface.cs b/example.csharp/addons/tiltfive/T5Interface.cs index 30e1527..6170e32 100644 --- a/example.csharp/addons/tiltfive/T5Interface.cs +++ b/example.csharp/addons/tiltfive/T5Interface.cs @@ -89,6 +89,19 @@ public override void _Ready() } } + public string GetUIDisplayName(string glassesID) + { + if(string.IsNullOrEmpty(glassesID) + || !xrInterface.Get("is_initialized").AsBool() + || !glassesDictionary.TryGetValue(glassesID, out var xrRigState) + || !xrRigState.available) + { + return string.Empty; + } + + return xrInterface.Call("get_glasses_name", glassesID).AsString(); + } + void StartDisplay(string glassesID, T5XRRig xrRig) { xrInterface.Call("start_display", glassesID, xrRig, xrRig.Origin); diff --git a/example.csharp/addons/tiltfive/T5Manager.cs b/example.csharp/addons/tiltfive/T5Manager.cs index 7c981f2..80fee72 100644 --- a/example.csharp/addons/tiltfive/T5Manager.cs +++ b/example.csharp/addons/tiltfive/T5Manager.cs @@ -77,7 +77,10 @@ public bool ShouldUseGlasses(string glassesID) public string GetUIDisplayName(string glassesID) { - return T5ProjectSettings.DefaultDisplayName; + var uiDisplayName = t5Interface.GetUIDisplayName(glassesID); + return string.IsNullOrEmpty(uiDisplayName) + ? T5ProjectSettings.DefaultDisplayName + : uiDisplayName; } public T5XRRig CreateXRRig(string glassesID) diff --git a/extension/src/TiltFiveXRInterface.cpp b/extension/src/TiltFiveXRInterface.cpp index f40d36b..041bec9 100644 --- a/extension/src/TiltFiveXRInterface.cpp +++ b/extension/src/TiltFiveXRInterface.cpp @@ -19,6 +19,7 @@ void TiltFiveXRInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("release_glasses", "glasses_id"), &TiltFiveXRInterface::release_glasses); ClassDB::bind_method(D_METHOD("get_available_glasses_ids"), &TiltFiveXRInterface::get_available_glasses_ids); ClassDB::bind_method(D_METHOD("get_reserved_glasses_ids"), &TiltFiveXRInterface::get_reserved_glasses_ids); + ClassDB::bind_method(D_METHOD("get_glasses_name", "glasses_id"), &TiltFiveXRInterface::get_glasses_name); ClassDB::bind_method(D_METHOD("get_gameboard_type", "glasses_id"), &TiltFiveXRInterface::get_gameboard_type); ClassDB::bind_method(D_METHOD("get_gameboard_extents", "gameboard_type"), &TiltFiveXRInterface::get_gameboard_extents); @@ -284,6 +285,17 @@ PackedStringArray TiltFiveXRInterface::get_reserved_glasses_ids() { return reserved_list; } +String TiltFiveXRInterface::get_glasses_name(const StringName glasses_id) { + if(!t5_service) + return String(""); + + auto entry = lookup_glasses_entry(glasses_id); + ERR_FAIL_COND_V_MSG(!entry, String(""), "Glasses id was not found"); + + std::string glasses_name = t5_service->get_glasses_name(entry->idx); + return String(glasses_name.c_str()); +} + TiltFiveXRInterface::GameBoardType TiltFiveXRInterface::get_gameboard_type(const StringName glasses_id) { if (!t5_service) return NO_GAMEBOARD_SET; diff --git a/extension/src/TiltFiveXRInterface.h b/extension/src/TiltFiveXRInterface.h index 98b9ef8..19264e4 100644 --- a/extension/src/TiltFiveXRInterface.h +++ b/extension/src/TiltFiveXRInterface.h @@ -108,6 +108,8 @@ class TiltFiveXRInterface : public XRInterfaceExtension { PackedStringArray get_available_glasses_ids(); PackedStringArray get_reserved_glasses_ids(); + String get_glasses_name(const StringName glasses_id); + // Overriden from XRInterfaceExtension virtual StringName _get_name() const override; virtual uint32_t _get_capabilities() const override; From 21261dc86242060cfa1013e11b27bcb65c968b76 Mon Sep 17 00:00:00 2001 From: Jonathan Stevens Date: Wed, 27 Mar 2024 18:13:21 -0700 Subject: [PATCH 2/2] Provide the godot application's name to the Tilt Five service --- example.csharp/addons/tiltfive/T5Interface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example.csharp/addons/tiltfive/T5Interface.cs b/example.csharp/addons/tiltfive/T5Interface.cs index 6170e32..0647c9a 100644 --- a/example.csharp/addons/tiltfive/T5Interface.cs +++ b/example.csharp/addons/tiltfive/T5Interface.cs @@ -116,7 +116,7 @@ void ProcessGlasses() if(entry.Value.CanAttemptToReserve && Manager.ShouldUseGlasses(entry.Key)) { entry.Value.attemptingToReserve = true; - xrInterface.Call("reserve_glasses", entry.Key, Manager.GetUIDisplayName(entry.Key)); + xrInterface.Call("reserve_glasses", entry.Key, ProjectSettings.GetSetting("application/config/name")); } } }