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
31#include "openxr_action.h"
32
33#include "openxr_action_set.h"
34
35void OpenXRAction::_bind_methods() {
36 ClassDB::bind_method(D_METHOD("set_localized_name", "localized_name"), &OpenXRAction::set_localized_name);
37 ClassDB::bind_method(D_METHOD("get_localized_name"), &OpenXRAction::get_localized_name);
38 ADD_PROPERTY(PropertyInfo(Variant::STRING, "localized_name"), "set_localized_name", "get_localized_name");
39
40 ClassDB::bind_method(D_METHOD("set_action_type", "action_type"), &OpenXRAction::set_action_type);
41 ClassDB::bind_method(D_METHOD("get_action_type"), &OpenXRAction::get_action_type);
42 ADD_PROPERTY(PropertyInfo(Variant::INT, "action_type", PROPERTY_HINT_ENUM, "bool,float,vector2,pose"), "set_action_type", "get_action_type");
43
44 ClassDB::bind_method(D_METHOD("set_toplevel_paths", "toplevel_paths"), &OpenXRAction::set_toplevel_paths);
45 ClassDB::bind_method(D_METHOD("get_toplevel_paths"), &OpenXRAction::get_toplevel_paths);
46 ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "toplevel_paths"), "set_toplevel_paths", "get_toplevel_paths");
47
48 BIND_ENUM_CONSTANT(OPENXR_ACTION_BOOL);
49 BIND_ENUM_CONSTANT(OPENXR_ACTION_FLOAT);
50 BIND_ENUM_CONSTANT(OPENXR_ACTION_VECTOR2);
51 BIND_ENUM_CONSTANT(OPENXR_ACTION_POSE);
52}
53
54Ref<OpenXRAction> OpenXRAction::new_action(const char *p_name, const char *p_localized_name, const ActionType p_action_type, const char *p_toplevel_paths) {
55 // This is a helper function to help build our default action sets
56
57 Ref<OpenXRAction> action;
58 action.instantiate();
59 action->set_name(String(p_name));
60 action->set_localized_name(String(p_localized_name));
61 action->set_action_type(p_action_type);
62 action->parse_toplevel_paths(String(p_toplevel_paths));
63
64 return action;
65}
66
67String OpenXRAction::get_name_with_set() const {
68 String action_name = get_name();
69
70 if (action_set != nullptr) {
71 action_name = action_set->get_name() + "/" + action_name;
72 }
73
74 return action_name;
75}
76
77void OpenXRAction::set_localized_name(const String p_localized_name) {
78 localized_name = p_localized_name;
79 emit_changed();
80}
81
82String OpenXRAction::get_localized_name() const {
83 return localized_name;
84}
85
86void OpenXRAction::set_action_type(const OpenXRAction::ActionType p_action_type) {
87 action_type = p_action_type;
88 emit_changed();
89}
90
91OpenXRAction::ActionType OpenXRAction::get_action_type() const {
92 return action_type;
93}
94
95void OpenXRAction::set_toplevel_paths(const PackedStringArray p_toplevel_paths) {
96 toplevel_paths = p_toplevel_paths;
97 emit_changed();
98}
99
100PackedStringArray OpenXRAction::get_toplevel_paths() const {
101 return toplevel_paths;
102}
103
104void OpenXRAction::add_toplevel_path(const String p_toplevel_path) {
105 if (!toplevel_paths.has(p_toplevel_path)) {
106 toplevel_paths.push_back(p_toplevel_path);
107 emit_changed();
108 }
109}
110
111void OpenXRAction::rem_toplevel_path(const String p_toplevel_path) {
112 if (toplevel_paths.has(p_toplevel_path)) {
113 toplevel_paths.erase(p_toplevel_path);
114 emit_changed();
115 }
116}
117
118void OpenXRAction::parse_toplevel_paths(const String p_toplevel_paths) {
119 toplevel_paths = p_toplevel_paths.split(",", false);
120 emit_changed();
121}
122