openxr_interaction_profile.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*************************************************************************/
  2. /* openxr_interaction_profile.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "openxr_interaction_profile.h"
  31. void OpenXRIPBinding::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("set_action", "action"), &OpenXRIPBinding::set_action);
  33. ClassDB::bind_method(D_METHOD("get_action"), &OpenXRIPBinding::get_action);
  34. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "action", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRAction"), "set_action", "get_action");
  35. ClassDB::bind_method(D_METHOD("set_paths", "paths"), &OpenXRIPBinding::set_paths);
  36. ClassDB::bind_method(D_METHOD("get_paths"), &OpenXRIPBinding::get_paths);
  37. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "paths", PROPERTY_HINT_ARRAY_TYPE, "STRING"), "set_paths", "get_paths");
  38. }
  39. Ref<OpenXRIPBinding> OpenXRIPBinding::new_binding(const Ref<OpenXRAction> p_action, const char *p_paths) {
  40. // This is a helper function to help build our default action sets
  41. Ref<OpenXRIPBinding> binding;
  42. binding.instantiate();
  43. binding->set_action(p_action);
  44. binding->parse_paths(String(p_paths));
  45. return binding;
  46. }
  47. void OpenXRIPBinding::set_action(const Ref<OpenXRAction> p_action) {
  48. action = p_action;
  49. }
  50. Ref<OpenXRAction> OpenXRIPBinding::get_action() const {
  51. return action;
  52. }
  53. void OpenXRIPBinding::set_paths(const PackedStringArray p_paths) {
  54. paths = p_paths;
  55. }
  56. PackedStringArray OpenXRIPBinding::get_paths() const {
  57. return paths;
  58. }
  59. void OpenXRIPBinding::parse_paths(const String p_paths) {
  60. paths = p_paths.split(",", false);
  61. }
  62. OpenXRIPBinding::~OpenXRIPBinding() {
  63. action.unref();
  64. }
  65. void OpenXRInteractionProfile::_bind_methods() {
  66. ClassDB::bind_method(D_METHOD("set_interaction_profile_path", "interaction_profile_path"), &OpenXRInteractionProfile::set_interaction_profile_path);
  67. ClassDB::bind_method(D_METHOD("get_interaction_profile_path"), &OpenXRInteractionProfile::get_interaction_profile_path);
  68. ADD_PROPERTY(PropertyInfo(Variant::STRING, "interaction_profile_path"), "set_interaction_profile_path", "get_interaction_profile_path");
  69. ClassDB::bind_method(D_METHOD("set_bindings", "bindings"), &OpenXRInteractionProfile::set_bindings);
  70. ClassDB::bind_method(D_METHOD("get_bindings"), &OpenXRInteractionProfile::get_bindings);
  71. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bindings", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRIPBinding", PROPERTY_USAGE_NO_EDITOR), "set_bindings", "get_bindings");
  72. }
  73. Ref<OpenXRInteractionProfile> OpenXRInteractionProfile::new_profile(const char *p_input_profile_path) {
  74. Ref<OpenXRInteractionProfile> profile;
  75. profile.instantiate();
  76. profile->set_interaction_profile_path(String(p_input_profile_path));
  77. return profile;
  78. }
  79. void OpenXRInteractionProfile::set_interaction_profile_path(const String p_input_profile_path) {
  80. interaction_profile_path = p_input_profile_path;
  81. }
  82. String OpenXRInteractionProfile::get_interaction_profile_path() const {
  83. return interaction_profile_path;
  84. }
  85. void OpenXRInteractionProfile::set_bindings(Array p_bindings) {
  86. bindings = p_bindings;
  87. }
  88. Array OpenXRInteractionProfile::get_bindings() const {
  89. return bindings;
  90. }
  91. void OpenXRInteractionProfile::add_binding(Ref<OpenXRIPBinding> p_binding) {
  92. ERR_FAIL_COND(p_binding.is_null());
  93. if (bindings.find(p_binding) == -1) {
  94. bindings.push_back(p_binding);
  95. }
  96. }
  97. void OpenXRInteractionProfile::remove_binding(Ref<OpenXRIPBinding> p_binding) {
  98. int idx = bindings.find(p_binding);
  99. if (idx != -1) {
  100. bindings.remove_at(idx);
  101. }
  102. }
  103. void OpenXRInteractionProfile::add_new_binding(const Ref<OpenXRAction> p_action, const char *p_paths) {
  104. // This is a helper function to help build our default action sets
  105. Ref<OpenXRIPBinding> binding = OpenXRIPBinding::new_binding(p_action, p_paths);
  106. add_binding(binding);
  107. }
  108. OpenXRInteractionProfile::~OpenXRInteractionProfile() {
  109. bindings.clear();
  110. }