Path: blob/master/modules/openxr/action_map/openxr_action.cpp
10278 views
/**************************************************************************/1/* openxr_action.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "openxr_action.h"3132#include "openxr_action_set.h"3334void OpenXRAction::_bind_methods() {35ClassDB::bind_method(D_METHOD("set_localized_name", "localized_name"), &OpenXRAction::set_localized_name);36ClassDB::bind_method(D_METHOD("get_localized_name"), &OpenXRAction::get_localized_name);37ADD_PROPERTY(PropertyInfo(Variant::STRING, "localized_name"), "set_localized_name", "get_localized_name");3839ClassDB::bind_method(D_METHOD("set_action_type", "action_type"), &OpenXRAction::set_action_type);40ClassDB::bind_method(D_METHOD("get_action_type"), &OpenXRAction::get_action_type);41ADD_PROPERTY(PropertyInfo(Variant::INT, "action_type", PROPERTY_HINT_ENUM, "bool,float,vector2,pose"), "set_action_type", "get_action_type");4243ClassDB::bind_method(D_METHOD("set_toplevel_paths", "toplevel_paths"), &OpenXRAction::set_toplevel_paths);44ClassDB::bind_method(D_METHOD("get_toplevel_paths"), &OpenXRAction::get_toplevel_paths);45ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "toplevel_paths"), "set_toplevel_paths", "get_toplevel_paths");4647BIND_ENUM_CONSTANT(OPENXR_ACTION_BOOL);48BIND_ENUM_CONSTANT(OPENXR_ACTION_FLOAT);49BIND_ENUM_CONSTANT(OPENXR_ACTION_VECTOR2);50BIND_ENUM_CONSTANT(OPENXR_ACTION_POSE);51}5253Ref<OpenXRAction> OpenXRAction::new_action(const char *p_name, const char *p_localized_name, const ActionType p_action_type, const char *p_toplevel_paths) {54// This is a helper function to help build our default action sets5556Ref<OpenXRAction> action;57action.instantiate();58action->set_name(String(p_name));59action->set_localized_name(String(p_localized_name));60action->set_action_type(p_action_type);61action->parse_toplevel_paths(String(p_toplevel_paths));6263return action;64}6566String OpenXRAction::get_name_with_set() const {67String action_name = get_name();6869if (action_set != nullptr) {70action_name = action_set->get_name() + "/" + action_name;71}7273return action_name;74}7576void OpenXRAction::set_localized_name(const String p_localized_name) {77localized_name = p_localized_name;78emit_changed();79}8081String OpenXRAction::get_localized_name() const {82return localized_name;83}8485void OpenXRAction::set_action_type(const OpenXRAction::ActionType p_action_type) {86action_type = p_action_type;87emit_changed();88}8990OpenXRAction::ActionType OpenXRAction::get_action_type() const {91return action_type;92}9394void OpenXRAction::set_toplevel_paths(const PackedStringArray p_toplevel_paths) {95toplevel_paths = p_toplevel_paths;96emit_changed();97}9899PackedStringArray OpenXRAction::get_toplevel_paths() const {100return toplevel_paths;101}102103void OpenXRAction::add_toplevel_path(const String p_toplevel_path) {104if (!toplevel_paths.has(p_toplevel_path)) {105toplevel_paths.push_back(p_toplevel_path);106emit_changed();107}108}109110void OpenXRAction::rem_toplevel_path(const String p_toplevel_path) {111if (toplevel_paths.has(p_toplevel_path)) {112toplevel_paths.erase(p_toplevel_path);113emit_changed();114}115}116117void OpenXRAction::parse_toplevel_paths(const String p_toplevel_paths) {118toplevel_paths = p_toplevel_paths.split(",", false);119emit_changed();120}121122123