openxr_action.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /**************************************************************************/
  2. /* openxr_action.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_action.h"
  31. #include "openxr_action_set.h"
  32. void OpenXRAction::_bind_methods() {
  33. ClassDB::bind_method(D_METHOD("set_localized_name", "localized_name"), &OpenXRAction::set_localized_name);
  34. ClassDB::bind_method(D_METHOD("get_localized_name"), &OpenXRAction::get_localized_name);
  35. ADD_PROPERTY(PropertyInfo(Variant::STRING, "localized_name"), "set_localized_name", "get_localized_name");
  36. ClassDB::bind_method(D_METHOD("set_action_type", "action_type"), &OpenXRAction::set_action_type);
  37. ClassDB::bind_method(D_METHOD("get_action_type"), &OpenXRAction::get_action_type);
  38. ADD_PROPERTY(PropertyInfo(Variant::INT, "action_type", PROPERTY_HINT_ENUM, "bool,float,vector2,pose"), "set_action_type", "get_action_type");
  39. ClassDB::bind_method(D_METHOD("set_toplevel_paths", "toplevel_paths"), &OpenXRAction::set_toplevel_paths);
  40. ClassDB::bind_method(D_METHOD("get_toplevel_paths"), &OpenXRAction::get_toplevel_paths);
  41. ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "toplevel_paths"), "set_toplevel_paths", "get_toplevel_paths");
  42. BIND_ENUM_CONSTANT(OPENXR_ACTION_BOOL);
  43. BIND_ENUM_CONSTANT(OPENXR_ACTION_FLOAT);
  44. BIND_ENUM_CONSTANT(OPENXR_ACTION_VECTOR2);
  45. BIND_ENUM_CONSTANT(OPENXR_ACTION_POSE);
  46. }
  47. Ref<OpenXRAction> OpenXRAction::new_action(const char *p_name, const char *p_localized_name, const ActionType p_action_type, const char *p_toplevel_paths) {
  48. // This is a helper function to help build our default action sets
  49. Ref<OpenXRAction> action;
  50. action.instantiate();
  51. action->set_name(String(p_name));
  52. action->set_localized_name(String(p_localized_name));
  53. action->set_action_type(p_action_type);
  54. action->parse_toplevel_paths(String(p_toplevel_paths));
  55. return action;
  56. }
  57. String OpenXRAction::get_name_with_set() const {
  58. String action_name = get_name();
  59. if (action_set != nullptr) {
  60. action_name = action_set->get_name() + "/" + action_name;
  61. }
  62. return action_name;
  63. }
  64. void OpenXRAction::set_localized_name(const String p_localized_name) {
  65. localized_name = p_localized_name;
  66. emit_changed();
  67. }
  68. String OpenXRAction::get_localized_name() const {
  69. return localized_name;
  70. }
  71. void OpenXRAction::set_action_type(const OpenXRAction::ActionType p_action_type) {
  72. action_type = p_action_type;
  73. emit_changed();
  74. }
  75. OpenXRAction::ActionType OpenXRAction::get_action_type() const {
  76. return action_type;
  77. }
  78. void OpenXRAction::set_toplevel_paths(const PackedStringArray p_toplevel_paths) {
  79. toplevel_paths = p_toplevel_paths;
  80. emit_changed();
  81. }
  82. PackedStringArray OpenXRAction::get_toplevel_paths() const {
  83. return toplevel_paths;
  84. }
  85. void OpenXRAction::add_toplevel_path(const String p_toplevel_path) {
  86. if (!toplevel_paths.has(p_toplevel_path)) {
  87. toplevel_paths.push_back(p_toplevel_path);
  88. emit_changed();
  89. }
  90. }
  91. void OpenXRAction::rem_toplevel_path(const String p_toplevel_path) {
  92. if (toplevel_paths.has(p_toplevel_path)) {
  93. toplevel_paths.erase(p_toplevel_path);
  94. emit_changed();
  95. }
  96. }
  97. void OpenXRAction::parse_toplevel_paths(const String p_toplevel_paths) {
  98. toplevel_paths = p_toplevel_paths.split(",", false);
  99. emit_changed();
  100. }