openxr_action_set.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*************************************************************************/
  2. /* openxr_action_set.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_action_set.h"
  31. void OpenXRActionSet::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("set_localized_name", "localized_name"), &OpenXRActionSet::set_localized_name);
  33. ClassDB::bind_method(D_METHOD("get_localized_name"), &OpenXRActionSet::get_localized_name);
  34. ADD_PROPERTY(PropertyInfo(Variant::STRING, "localized_name"), "set_localized_name", "get_localized_name");
  35. ClassDB::bind_method(D_METHOD("set_priority", "priority"), &OpenXRActionSet::set_priority);
  36. ClassDB::bind_method(D_METHOD("get_priority"), &OpenXRActionSet::get_priority);
  37. ADD_PROPERTY(PropertyInfo(Variant::INT, "priority"), "set_priority", "get_priority");
  38. ClassDB::bind_method(D_METHOD("set_actions", "actions"), &OpenXRActionSet::set_actions);
  39. ClassDB::bind_method(D_METHOD("get_actions"), &OpenXRActionSet::get_actions);
  40. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "actions", PROPERTY_HINT_RESOURCE_TYPE, "OpenXRAction", PROPERTY_USAGE_NO_EDITOR), "set_actions", "get_actions");
  41. ClassDB::bind_method(D_METHOD("add_action", "action"), &OpenXRActionSet::add_action);
  42. ClassDB::bind_method(D_METHOD("remove_action", "action"), &OpenXRActionSet::remove_action);
  43. }
  44. Ref<OpenXRActionSet> OpenXRActionSet::new_action_set(const char *p_name, const char *p_localized_name, const int p_priority) {
  45. // This is a helper function to help build our default action sets
  46. Ref<OpenXRActionSet> action_set;
  47. action_set.instantiate();
  48. action_set->set_name(String(p_name));
  49. action_set->set_localized_name(p_localized_name);
  50. action_set->set_priority(p_priority);
  51. return action_set;
  52. }
  53. void OpenXRActionSet::set_localized_name(const String p_localized_name) {
  54. localized_name = p_localized_name;
  55. }
  56. String OpenXRActionSet::get_localized_name() const {
  57. return localized_name;
  58. }
  59. void OpenXRActionSet::set_priority(const int p_priority) {
  60. priority = p_priority;
  61. }
  62. int OpenXRActionSet::get_priority() const {
  63. return priority;
  64. }
  65. void OpenXRActionSet::set_actions(Array p_actions) {
  66. actions = p_actions;
  67. }
  68. Array OpenXRActionSet::get_actions() const {
  69. return actions;
  70. }
  71. void OpenXRActionSet::add_action(Ref<OpenXRAction> p_action) {
  72. ERR_FAIL_COND(p_action.is_null());
  73. if (actions.find(p_action) == -1) {
  74. actions.push_back(p_action);
  75. }
  76. }
  77. void OpenXRActionSet::remove_action(Ref<OpenXRAction> p_action) {
  78. int idx = actions.find(p_action);
  79. if (idx != -1) {
  80. actions.remove_at(idx);
  81. }
  82. }
  83. Ref<OpenXRAction> OpenXRActionSet::add_new_action(const char *p_name, const char *p_localized_name, const OpenXRAction::ActionType p_action_type, const char *p_toplevel_paths) {
  84. // This is a helper function to help build our default action sets
  85. Ref<OpenXRAction> new_action = OpenXRAction::new_action(p_name, p_localized_name, p_action_type, p_toplevel_paths);
  86. add_action(new_action);
  87. return new_action;
  88. }
  89. OpenXRActionSet::~OpenXRActionSet() {
  90. actions.clear();
  91. }