2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* visual_script_nodes.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 15:47:28 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
#include "visual_script_nodes.h"
|
2017-03-05 15:47:28 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/config/engine.h"
|
|
|
|
#include "core/config/project_settings.h"
|
|
|
|
#include "core/core_constants.h"
|
2020-04-28 15:19:37 +02:00
|
|
|
#include "core/input/input.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/os.h"
|
2016-08-03 00:11:05 +02:00
|
|
|
#include "scene/main/node.h"
|
2017-06-27 03:58:03 +02:00
|
|
|
#include "scene/main/scene_tree.h"
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////FUNCTION//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptFunction::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
if (p_name == "argument_count") {
|
|
|
|
int new_argc = p_value;
|
2016-08-03 00:11:05 +02:00
|
|
|
int argc = arguments.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (argc == new_argc) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
arguments.resize(new_argc);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = argc; i < new_argc; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
arguments.write[i].name = "arg" + itos(i + 1);
|
|
|
|
arguments.write[i].type = Variant::NIL;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-03 00:11:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
2017-07-01 02:30:17 +02:00
|
|
|
if (String(p_name).begins_with("argument_")) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(idx, arguments.size(), false);
|
2017-07-01 02:30:17 +02:00
|
|
|
String what = String(p_name).get_slice("/", 1);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (what == "type") {
|
2016-08-03 00:11:05 +02:00
|
|
|
Variant::Type new_type = Variant::Type(int(p_value));
|
2018-07-25 03:11:03 +02:00
|
|
|
arguments.write[idx].type = new_type;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (what == "name") {
|
2018-07-25 03:11:03 +02:00
|
|
|
arguments.write[idx].name = p_value;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "stack/stackless") {
|
2016-08-06 03:46:45 +02:00
|
|
|
set_stack_less(p_value);
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "stack/size") {
|
|
|
|
stack_size = p_value;
|
2016-08-06 03:46:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "rpc/mode") {
|
2022-07-12 23:12:42 +02:00
|
|
|
rpc_mode = MultiplayerAPI::RPCMode(int(p_value));
|
2016-08-25 22:45:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-08 18:14:36 +02:00
|
|
|
if (p_name == "sequenced/sequenced") {
|
|
|
|
sequenced = p_value;
|
|
|
|
ports_changed_notify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptFunction::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
if (p_name == "argument_count") {
|
2016-08-03 00:11:05 +02:00
|
|
|
r_ret = arguments.size();
|
|
|
|
return true;
|
|
|
|
}
|
2017-07-01 02:30:17 +02:00
|
|
|
if (String(p_name).begins_with("argument_")) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(idx, arguments.size(), false);
|
2017-07-01 02:30:17 +02:00
|
|
|
String what = String(p_name).get_slice("/", 1);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (what == "type") {
|
2016-08-03 00:11:05 +02:00
|
|
|
r_ret = arguments[idx].type;
|
|
|
|
return true;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
if (what == "name") {
|
2016-08-03 00:11:05 +02:00
|
|
|
r_ret = arguments[idx].name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "stack/stackless") {
|
|
|
|
r_ret = stack_less;
|
2016-08-06 03:46:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "stack/size") {
|
|
|
|
r_ret = stack_size;
|
2016-08-06 03:46:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_name == "rpc/mode") {
|
|
|
|
r_ret = rpc_mode;
|
2016-08-25 22:45:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-08 18:14:36 +02:00
|
|
|
if (p_name == "sequenced/sequenced") {
|
|
|
|
r_ret = sequenced;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptFunction::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "argument_count", PROPERTY_HINT_RANGE, "0,256"));
|
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < arguments.size(); i++) {
|
2017-07-01 02:30:17 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "argument_" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "argument_" + itos(i + 1) + "/name"));
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2017-08-08 18:14:36 +02:00
|
|
|
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced/sequenced"));
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
if (!stack_less) {
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "stack/size", PROPERTY_HINT_RANGE, "1,100000"));
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "stack/stackless"));
|
2021-08-10 20:44:06 +02:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "rpc/mode", PROPERTY_HINT_ENUM, "Disabled,Any,Authority"));
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptFunction::get_output_sequence_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptFunction::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptFunction::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptFunction::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return arguments.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptFunction::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptFunction::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
ERR_FAIL_V(PropertyInfo());
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptFunction::get_output_value_port_info(int p_idx) const {
|
2021-07-13 09:39:43 +02:00
|
|
|
// Need to check it without ERR_FAIL_COND, to prevent warnings from appearing on node creation via dragging.
|
|
|
|
if (p_idx < 0 || p_idx >= arguments.size()) {
|
|
|
|
return PropertyInfo();
|
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
PropertyInfo out;
|
2017-03-05 16:44:50 +01:00
|
|
|
out.type = arguments[p_idx].type;
|
|
|
|
out.name = arguments[p_idx].name;
|
2018-07-25 23:23:26 +02:00
|
|
|
out.hint = arguments[p_idx].hint;
|
|
|
|
out.hint_string = arguments[p_idx].hint_string;
|
2016-08-03 00:11:05 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptFunction::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Function");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptFunction::get_text() const {
|
|
|
|
return get_name(); //use name as function name I guess
|
|
|
|
}
|
|
|
|
|
2018-07-25 23:23:26 +02:00
|
|
|
void VisualScriptFunction::add_argument(Variant::Type p_type, const String &p_name, int p_index, const PropertyHint p_hint, const String &p_hint_string) {
|
2016-08-03 00:11:05 +02:00
|
|
|
Argument arg;
|
2017-03-05 16:44:50 +01:00
|
|
|
arg.name = p_name;
|
|
|
|
arg.type = p_type;
|
2018-07-25 23:23:26 +02:00
|
|
|
arg.hint = p_hint;
|
|
|
|
arg.hint_string = p_hint_string;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_index >= 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
arguments.insert(p_index, arg);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-08-03 00:11:05 +02:00
|
|
|
arguments.push_back(arg);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptFunction::set_argument_type(int p_argidx, Variant::Type p_type) {
|
|
|
|
ERR_FAIL_INDEX(p_argidx, arguments.size());
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
arguments.write[p_argidx].type = p_type;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
Variant::Type VisualScriptFunction::get_argument_type(int p_argidx) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_argidx, arguments.size(), Variant::NIL);
|
2016-08-03 00:11:05 +02:00
|
|
|
return arguments[p_argidx].type;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptFunction::set_argument_name(int p_argidx, const String &p_name) {
|
|
|
|
ERR_FAIL_INDEX(p_argidx, arguments.size());
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
arguments.write[p_argidx].name = p_name;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
String VisualScriptFunction::get_argument_name(int p_argidx) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_argidx, arguments.size(), String());
|
2016-08-03 00:11:05 +02:00
|
|
|
return arguments[p_argidx].name;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void VisualScriptFunction::remove_argument(int p_argidx) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX(p_argidx, arguments.size());
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2021-07-04 00:17:03 +02:00
|
|
|
arguments.remove_at(p_argidx);
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptFunction::get_argument_count() const {
|
|
|
|
return arguments.size();
|
|
|
|
}
|
|
|
|
|
2022-07-12 23:12:42 +02:00
|
|
|
void VisualScriptFunction::set_rpc_mode(MultiplayerAPI::RPCMode p_mode) {
|
2017-03-05 16:44:50 +01:00
|
|
|
rpc_mode = p_mode;
|
2016-08-25 22:45:20 +02:00
|
|
|
}
|
|
|
|
|
2022-07-12 23:12:42 +02:00
|
|
|
MultiplayerAPI::RPCMode VisualScriptFunction::get_rpc_mode() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return rpc_mode;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceFunction : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptFunction *node = nullptr;
|
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-06 03:46:45 +02:00
|
|
|
int ac = node->get_argument_count();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < ac; i++) {
|
2016-08-06 03:46:45 +02:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
Variant::Type expected = node->get_argument_type(i);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (expected != Variant::NIL) {
|
|
|
|
if (!Variant::can_convert_strict(p_inputs[i]->get_type(), expected)) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error.expected = expected;
|
|
|
|
r_error.argument = i;
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[i] = *p_inputs[i];
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptFunction::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceFunction *instance = memnew(VisualScriptNodeInstanceFunction);
|
|
|
|
instance->node = this;
|
|
|
|
instance->instance = p_instance;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 18:18:45 +01:00
|
|
|
void VisualScriptFunction::reset_state() {
|
|
|
|
arguments.clear();
|
|
|
|
stack_size = 256;
|
|
|
|
stack_less = false;
|
|
|
|
sequenced = true;
|
2022-07-12 23:12:42 +02:00
|
|
|
rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
|
2021-02-11 18:18:45 +01:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
VisualScriptFunction::VisualScriptFunction() {
|
2017-03-05 16:44:50 +01:00
|
|
|
stack_size = 256;
|
|
|
|
stack_less = false;
|
2017-08-08 18:14:36 +02:00
|
|
|
sequenced = true;
|
2022-07-12 23:12:42 +02:00
|
|
|
rpc_mode = MultiplayerAPI::RPC_MODE_DISABLED;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptFunction::set_stack_less(bool p_enable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
stack_less = p_enable;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualScriptFunction::is_stack_less() const {
|
|
|
|
return stack_less;
|
|
|
|
}
|
|
|
|
|
2017-08-08 18:14:36 +02:00
|
|
|
void VisualScriptFunction::set_sequenced(bool p_enable) {
|
|
|
|
sequenced = p_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualScriptFunction::is_sequenced() const {
|
|
|
|
return sequenced;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
void VisualScriptFunction::set_stack_size(int p_size) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(p_size < 1 || p_size > 100000);
|
|
|
|
stack_size = p_size;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptFunction::get_stack_size() const {
|
|
|
|
return stack_size;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
/////////////////LISTS////////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptLists::get_output_sequence_port_count() const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (sequenced) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return 1;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::has_input_sequence_port() const {
|
|
|
|
return sequenced;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLists::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptLists::get_input_value_port_count() const {
|
|
|
|
return inputports.size();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
int VisualScriptLists::get_output_value_port_count() const {
|
|
|
|
return outputports.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo VisualScriptLists::get_input_value_port_info(int p_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, inputports.size(), PropertyInfo());
|
|
|
|
|
|
|
|
PropertyInfo pi;
|
|
|
|
pi.name = inputports[p_idx].name;
|
|
|
|
pi.type = inputports[p_idx].type;
|
|
|
|
return pi;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
PropertyInfo VisualScriptLists::get_output_value_port_info(int p_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, outputports.size(), PropertyInfo());
|
|
|
|
|
|
|
|
PropertyInfo pi;
|
|
|
|
pi.name = outputports[p_idx].name;
|
|
|
|
pi.type = outputports[p_idx].type;
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualScriptLists::is_input_port_editable() const {
|
|
|
|
return ((flags & INPUT_EDITABLE) == INPUT_EDITABLE);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::is_input_port_name_editable() const {
|
|
|
|
return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::is_input_port_type_editable() const {
|
|
|
|
return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualScriptLists::is_output_port_editable() const {
|
|
|
|
return ((flags & OUTPUT_EDITABLE) == OUTPUT_EDITABLE);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::is_output_port_name_editable() const {
|
|
|
|
return ((flags & INPUT_NAME_EDITABLE) == INPUT_NAME_EDITABLE);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::is_output_port_type_editable() const {
|
|
|
|
return ((flags & INPUT_TYPE_EDITABLE) == INPUT_TYPE_EDITABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// for the inspector
|
|
|
|
bool VisualScriptLists::_set(const StringName &p_name, const Variant &p_value) {
|
|
|
|
if (p_name == "input_count" && is_input_port_editable()) {
|
|
|
|
int new_argc = p_value;
|
|
|
|
int argc = inputports.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (argc == new_argc) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
inputports.resize(new_argc);
|
|
|
|
|
|
|
|
for (int i = argc; i < new_argc; i++) {
|
|
|
|
inputports.write[i].name = "arg" + itos(i + 1);
|
|
|
|
inputports.write[i].type = Variant::NIL;
|
|
|
|
}
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (String(p_name).begins_with("input_") && is_input_port_editable()) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(idx, inputports.size(), false);
|
|
|
|
String what = String(p_name).get_slice("/", 1);
|
|
|
|
if (what == "type") {
|
|
|
|
Variant::Type new_type = Variant::Type(int(p_value));
|
|
|
|
inputports.write[idx].type = new_type;
|
|
|
|
ports_changed_notify();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what == "name") {
|
|
|
|
inputports.write[idx].name = p_value;
|
|
|
|
ports_changed_notify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_name == "output_count" && is_output_port_editable()) {
|
|
|
|
int new_argc = p_value;
|
|
|
|
int argc = outputports.size();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (argc == new_argc) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
outputports.resize(new_argc);
|
|
|
|
|
|
|
|
for (int i = argc; i < new_argc; i++) {
|
|
|
|
outputports.write[i].name = "arg" + itos(i + 1);
|
|
|
|
outputports.write[i].type = Variant::NIL;
|
|
|
|
}
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (String(p_name).begins_with("output_") && is_output_port_editable()) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(idx, outputports.size(), false);
|
|
|
|
String what = String(p_name).get_slice("/", 1);
|
|
|
|
if (what == "type") {
|
|
|
|
Variant::Type new_type = Variant::Type(int(p_value));
|
|
|
|
outputports.write[idx].type = new_type;
|
|
|
|
ports_changed_notify();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (what == "name") {
|
|
|
|
outputports.write[idx].name = p_value;
|
|
|
|
ports_changed_notify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_name == "sequenced/sequenced") {
|
|
|
|
sequenced = p_value;
|
|
|
|
ports_changed_notify();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::_get(const StringName &p_name, Variant &r_ret) const {
|
|
|
|
if (p_name == "input_count" && is_input_port_editable()) {
|
|
|
|
r_ret = inputports.size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (String(p_name).begins_with("input_") && is_input_port_editable()) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(idx, inputports.size(), false);
|
|
|
|
String what = String(p_name).get_slice("/", 1);
|
|
|
|
if (what == "type") {
|
|
|
|
r_ret = inputports[idx].type;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (what == "name") {
|
|
|
|
r_ret = inputports[idx].name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_name == "output_count" && is_output_port_editable()) {
|
|
|
|
r_ret = outputports.size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (String(p_name).begins_with("output_") && is_output_port_editable()) {
|
|
|
|
int idx = String(p_name).get_slicec('_', 1).get_slicec('/', 0).to_int() - 1;
|
|
|
|
ERR_FAIL_INDEX_V(idx, outputports.size(), false);
|
|
|
|
String what = String(p_name).get_slice("/", 1);
|
|
|
|
if (what == "type") {
|
|
|
|
r_ret = outputports[idx].type;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (what == "name") {
|
|
|
|
r_ret = outputports[idx].name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_name == "sequenced/sequenced") {
|
|
|
|
r_ret = sequenced;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::_get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
if (is_input_port_editable()) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "input_count", PROPERTY_HINT_RANGE, "0,256"));
|
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < inputports.size(); i++) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "input_" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "input_" + itos(i + 1) + "/name"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_output_port_editable()) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "output_count", PROPERTY_HINT_RANGE, "0,256"));
|
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < outputports.size(); i++) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "output_" + itos(i + 1) + "/type", PROPERTY_HINT_ENUM, argt));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, "output_" + itos(i + 1) + "/name"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "sequenced/sequenced"));
|
|
|
|
}
|
|
|
|
|
|
|
|
// input data port interaction
|
|
|
|
void VisualScriptLists::add_input_data_port(Variant::Type p_type, const String &p_name, int p_index) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_input_port_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
Port inp;
|
|
|
|
inp.name = p_name;
|
|
|
|
inp.type = p_type;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_index >= 0) {
|
2019-09-13 21:14:12 +02:00
|
|
|
inputports.insert(p_index, inp);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2019-09-13 21:14:12 +02:00
|
|
|
inputports.push_back(inp);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::set_input_data_port_type(int p_idx, Variant::Type p_type) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_input_port_type_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_idx, inputports.size());
|
|
|
|
|
|
|
|
inputports.write[p_idx].type = p_type;
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::set_input_data_port_name(int p_idx, const String &p_name) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_input_port_name_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_idx, inputports.size());
|
|
|
|
|
|
|
|
inputports.write[p_idx].name = p_name;
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::remove_input_data_port(int p_argidx) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_input_port_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_argidx, inputports.size());
|
|
|
|
|
2021-07-04 00:17:03 +02:00
|
|
|
inputports.remove_at(p_argidx);
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// output data port interaction
|
|
|
|
void VisualScriptLists::add_output_data_port(Variant::Type p_type, const String &p_name, int p_index) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_output_port_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
Port out;
|
|
|
|
out.name = p_name;
|
|
|
|
out.type = p_type;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_index >= 0) {
|
2019-09-13 21:14:12 +02:00
|
|
|
outputports.insert(p_index, out);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2019-09-13 21:14:12 +02:00
|
|
|
outputports.push_back(out);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::set_output_data_port_type(int p_idx, Variant::Type p_type) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_output_port_type_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_idx, outputports.size());
|
|
|
|
|
|
|
|
outputports.write[p_idx].type = p_type;
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::set_output_data_port_name(int p_idx, const String &p_name) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_output_port_name_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_idx, outputports.size());
|
|
|
|
|
|
|
|
outputports.write[p_idx].name = p_name;
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
void VisualScriptLists::remove_output_data_port(int p_argidx) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_output_port_editable()) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ERR_FAIL_INDEX(p_argidx, outputports.size());
|
|
|
|
|
2021-07-04 00:17:03 +02:00
|
|
|
outputports.remove_at(p_argidx);
|
2019-09-13 21:14:12 +02:00
|
|
|
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// sequences
|
|
|
|
void VisualScriptLists::set_sequenced(bool p_enable) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (sequenced == p_enable) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
sequenced = p_enable;
|
|
|
|
ports_changed_notify();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptLists::is_sequenced() const {
|
|
|
|
return sequenced;
|
|
|
|
}
|
|
|
|
|
2021-02-11 18:18:45 +01:00
|
|
|
void VisualScriptLists::reset_state() {
|
|
|
|
inputports.clear();
|
|
|
|
outputports.clear();
|
|
|
|
sequenced = false;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
VisualScriptLists::VisualScriptLists() {
|
|
|
|
// initialize
|
|
|
|
sequenced = false;
|
|
|
|
flags = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptLists::_bind_methods() {
|
2019-09-27 22:16:32 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("add_input_data_port", "type", "name", "index"), &VisualScriptLists::add_input_data_port);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_input_data_port_name", "index", "name"), &VisualScriptLists::set_input_data_port_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_input_data_port_type", "index", "type"), &VisualScriptLists::set_input_data_port_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_input_data_port", "index"), &VisualScriptLists::remove_input_data_port);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("add_output_data_port", "type", "name", "index"), &VisualScriptLists::add_output_data_port);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_output_data_port_name", "index", "name"), &VisualScriptLists::set_output_data_port_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_output_data_port_type", "index", "type"), &VisualScriptLists::set_output_data_port_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("remove_output_data_port", "index"), &VisualScriptLists::remove_output_data_port);
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
//////////////COMPOSEARRAY////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptComposeArray::get_output_sequence_port_count() const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (sequenced) {
|
2019-09-13 21:14:12 +02:00
|
|
|
return 1;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
bool VisualScriptComposeArray::has_input_sequence_port() const {
|
|
|
|
return sequenced;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComposeArray::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptComposeArray::get_input_value_port_count() const {
|
|
|
|
return inputports.size();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
int VisualScriptComposeArray::get_output_value_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo VisualScriptComposeArray::get_input_value_port_info(int p_idx) const {
|
|
|
|
ERR_FAIL_INDEX_V(p_idx, inputports.size(), PropertyInfo());
|
|
|
|
|
|
|
|
PropertyInfo pi;
|
|
|
|
pi.name = inputports[p_idx].name;
|
|
|
|
pi.type = inputports[p_idx].type;
|
|
|
|
return pi;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
PropertyInfo VisualScriptComposeArray::get_output_value_port_info(int p_idx) const {
|
|
|
|
PropertyInfo pi;
|
|
|
|
pi.name = "out";
|
|
|
|
pi.type = Variant::ARRAY;
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComposeArray::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Compose Array");
|
2019-09-13 21:14:12 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2019-09-13 21:14:12 +02:00
|
|
|
String VisualScriptComposeArray::get_text() const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptComposeArrayNode : public VisualScriptNodeInstance {
|
|
|
|
public:
|
|
|
|
int input_count = 0;
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int get_working_memory_size() const override { return 0; }
|
2019-09-13 21:14:12 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2019-09-13 21:14:12 +02:00
|
|
|
if (input_count > 0) {
|
|
|
|
Array arr;
|
2020-05-14 16:41:43 +02:00
|
|
|
for (int i = 0; i < input_count; i++) {
|
2019-09-13 21:14:12 +02:00
|
|
|
arr.push_back((*p_inputs[i]));
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-09-13 21:14:12 +02:00
|
|
|
Variant va = Variant(arr);
|
|
|
|
|
|
|
|
*p_outputs[0] = va;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptComposeArray::instantiate(VisualScriptInstance *p_instance) {
|
2019-09-13 21:14:12 +02:00
|
|
|
VisualScriptComposeArrayNode *instance = memnew(VisualScriptComposeArrayNode);
|
|
|
|
instance->input_count = inputports.size();
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptComposeArray::VisualScriptComposeArray() {
|
|
|
|
// initialize stuff here
|
|
|
|
sequenced = false;
|
|
|
|
flags = INPUT_EDITABLE;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////OPERATOR//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptOperator::get_output_sequence_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptOperator::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return false;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptOperator::get_input_value_port_count() const {
|
|
|
|
return (op == Variant::OP_BIT_NEGATE || op == Variant::OP_NOT || op == Variant::OP_NEGATE || op == Variant::OP_POSITIVE) ? 1 : 2;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptOperator::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptOperator::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptOperator::get_input_value_port_info(int p_idx) const {
|
|
|
|
static const Variant::Type port_types[Variant::OP_MAX][2] = {
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_EQUAL,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_NOT_EQUAL,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_LESS,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_LESS_EQUAL,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_GREATER,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_GREATER_EQUAL,
|
2016-08-03 00:11:05 +02:00
|
|
|
//mathematic
|
2017-03-05 16:44:50 +01:00
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_ADD,
|
2017-12-05 05:34:46 +01:00
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_SUBTRACT,
|
2017-03-05 16:44:50 +01:00
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_MULTIPLY,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_DIVIDE,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_NEGATE,
|
|
|
|
{ Variant::NIL, Variant::NIL }, //OP_POSITIVE,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_MODULE,
|
2016-08-03 00:11:05 +02:00
|
|
|
//bitwise
|
2017-03-05 16:44:50 +01:00
|
|
|
{ Variant::INT, Variant::INT }, //OP_SHIFT_LEFT,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_SHIFT_RIGHT,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_BIT_AND,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_BIT_OR,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_BIT_XOR,
|
|
|
|
{ Variant::INT, Variant::INT }, //OP_BIT_NEGATE,
|
2016-08-03 00:11:05 +02:00
|
|
|
//logic
|
2017-03-05 16:44:50 +01:00
|
|
|
{ Variant::BOOL, Variant::BOOL }, //OP_AND,
|
|
|
|
{ Variant::BOOL, Variant::BOOL }, //OP_OR,
|
|
|
|
{ Variant::BOOL, Variant::BOOL }, //OP_XOR,
|
|
|
|
{ Variant::BOOL, Variant::BOOL }, //OP_NOT,
|
2016-08-03 00:11:05 +02:00
|
|
|
//containment
|
2017-03-05 16:44:50 +01:00
|
|
|
{ Variant::NIL, Variant::NIL } //OP_IN,
|
2016-08-03 00:11:05 +02:00
|
|
|
};
|
|
|
|
|
2019-07-20 08:09:57 +02:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, 2, PropertyInfo());
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
PropertyInfo pinfo;
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.name = p_idx == 0 ? "A" : "B";
|
|
|
|
pinfo.type = port_types[op][p_idx];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pinfo.type == Variant::NIL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.type = typed;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
return pinfo;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptOperator::get_output_value_port_info(int p_idx) const {
|
|
|
|
static const Variant::Type port_types[Variant::OP_MAX] = {
|
2018-02-21 17:30:55 +01:00
|
|
|
//comparison
|
2016-08-03 00:11:05 +02:00
|
|
|
Variant::BOOL, //OP_EQUAL,
|
|
|
|
Variant::BOOL, //OP_NOT_EQUAL,
|
|
|
|
Variant::BOOL, //OP_LESS,
|
|
|
|
Variant::BOOL, //OP_LESS_EQUAL,
|
|
|
|
Variant::BOOL, //OP_GREATER,
|
|
|
|
Variant::BOOL, //OP_GREATER_EQUAL,
|
|
|
|
//mathematic
|
|
|
|
Variant::NIL, //OP_ADD,
|
2017-12-05 05:34:46 +01:00
|
|
|
Variant::NIL, //OP_SUBTRACT,
|
2016-08-03 00:11:05 +02:00
|
|
|
Variant::NIL, //OP_MULTIPLY,
|
|
|
|
Variant::NIL, //OP_DIVIDE,
|
|
|
|
Variant::NIL, //OP_NEGATE,
|
2016-11-12 02:45:26 +01:00
|
|
|
Variant::NIL, //OP_POSITIVE,
|
2016-08-03 00:11:05 +02:00
|
|
|
Variant::INT, //OP_MODULE,
|
|
|
|
//bitwise
|
|
|
|
Variant::INT, //OP_SHIFT_LEFT,
|
|
|
|
Variant::INT, //OP_SHIFT_RIGHT,
|
|
|
|
Variant::INT, //OP_BIT_AND,
|
|
|
|
Variant::INT, //OP_BIT_OR,
|
|
|
|
Variant::INT, //OP_BIT_XOR,
|
|
|
|
Variant::INT, //OP_BIT_NEGATE,
|
|
|
|
//logic
|
|
|
|
Variant::BOOL, //OP_AND,
|
|
|
|
Variant::BOOL, //OP_OR,
|
|
|
|
Variant::BOOL, //OP_XOR,
|
|
|
|
Variant::BOOL, //OP_NOT,
|
|
|
|
//containment
|
|
|
|
Variant::BOOL //OP_IN,
|
|
|
|
};
|
|
|
|
|
|
|
|
PropertyInfo pinfo;
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.name = "";
|
|
|
|
pinfo.type = port_types[op];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (pinfo.type == Variant::NIL) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.type = typed;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptOperator::get_caption() const {
|
2021-06-22 15:20:39 +02:00
|
|
|
switch (op) {
|
|
|
|
// comparison
|
|
|
|
case Variant::OP_EQUAL:
|
|
|
|
return U"A = B";
|
|
|
|
case Variant::OP_NOT_EQUAL:
|
|
|
|
return U"A \u2260 B";
|
|
|
|
case Variant::OP_LESS:
|
|
|
|
return U"A < B";
|
|
|
|
case Variant::OP_LESS_EQUAL:
|
|
|
|
return U"A \u2264 B";
|
|
|
|
case Variant::OP_GREATER:
|
|
|
|
return U"A > B";
|
|
|
|
case Variant::OP_GREATER_EQUAL:
|
|
|
|
return U"A \u2265 B";
|
|
|
|
|
|
|
|
// mathematic
|
|
|
|
case Variant::OP_ADD:
|
|
|
|
return U"A + B";
|
|
|
|
case Variant::OP_SUBTRACT:
|
|
|
|
return U"A - B";
|
|
|
|
case Variant::OP_MULTIPLY:
|
|
|
|
return U"A \u00D7 B";
|
|
|
|
case Variant::OP_DIVIDE:
|
|
|
|
return U"A \u00F7 B";
|
|
|
|
case Variant::OP_NEGATE:
|
|
|
|
return U"\u00AC A";
|
|
|
|
case Variant::OP_POSITIVE:
|
|
|
|
return U"+ A";
|
|
|
|
case Variant::OP_MODULE:
|
|
|
|
return U"A mod B";
|
|
|
|
|
|
|
|
// bitwise
|
|
|
|
case Variant::OP_SHIFT_LEFT:
|
|
|
|
return U"A << B";
|
|
|
|
case Variant::OP_SHIFT_RIGHT:
|
|
|
|
return U"A >> B";
|
|
|
|
case Variant::OP_BIT_AND:
|
|
|
|
return U"A & B";
|
|
|
|
case Variant::OP_BIT_OR:
|
|
|
|
return U"A | B";
|
|
|
|
case Variant::OP_BIT_XOR:
|
|
|
|
return U"A ^ B";
|
|
|
|
case Variant::OP_BIT_NEGATE:
|
|
|
|
return U"~A";
|
|
|
|
|
|
|
|
// logic
|
|
|
|
case Variant::OP_AND:
|
|
|
|
return U"A and B";
|
|
|
|
case Variant::OP_OR:
|
|
|
|
return U"A or B";
|
|
|
|
case Variant::OP_XOR:
|
|
|
|
return U"A xor B";
|
|
|
|
case Variant::OP_NOT:
|
|
|
|
return U"not A";
|
|
|
|
case Variant::OP_IN:
|
|
|
|
return U"A in B";
|
|
|
|
|
|
|
|
default: {
|
|
|
|
ERR_FAIL_V_MSG(
|
|
|
|
U"Unknown node",
|
|
|
|
U"Unknown node type encountered, caption not available.");
|
|
|
|
}
|
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2021-06-27 14:28:12 +02:00
|
|
|
String VisualScriptOperator::get_operator_name(Variant::Operator p_op) {
|
|
|
|
switch (p_op) {
|
|
|
|
// comparison
|
|
|
|
case Variant::OP_EQUAL:
|
|
|
|
return "Are Equal";
|
|
|
|
case Variant::OP_NOT_EQUAL:
|
|
|
|
return "Are Not Equal";
|
|
|
|
case Variant::OP_LESS:
|
|
|
|
return "Less Than";
|
|
|
|
case Variant::OP_LESS_EQUAL:
|
|
|
|
return "Less Than or Equal";
|
|
|
|
case Variant::OP_GREATER:
|
|
|
|
return "Greater Than";
|
|
|
|
case Variant::OP_GREATER_EQUAL:
|
|
|
|
return "Greater Than or Equal";
|
|
|
|
|
|
|
|
// mathematic
|
|
|
|
case Variant::OP_ADD:
|
|
|
|
return "Add";
|
|
|
|
case Variant::OP_SUBTRACT:
|
|
|
|
return "Subtract";
|
|
|
|
case Variant::OP_MULTIPLY:
|
|
|
|
return "Multiply";
|
|
|
|
case Variant::OP_DIVIDE:
|
|
|
|
return "Divide";
|
|
|
|
case Variant::OP_NEGATE:
|
|
|
|
return "Negate";
|
|
|
|
case Variant::OP_POSITIVE:
|
|
|
|
return "Positive";
|
|
|
|
case Variant::OP_MODULE:
|
|
|
|
return "Remainder";
|
|
|
|
|
|
|
|
// bitwise
|
|
|
|
case Variant::OP_SHIFT_LEFT:
|
|
|
|
return "Bit Shift Left";
|
|
|
|
case Variant::OP_SHIFT_RIGHT:
|
|
|
|
return "Bit Shift Right";
|
|
|
|
case Variant::OP_BIT_AND:
|
|
|
|
return "Bit And";
|
|
|
|
case Variant::OP_BIT_OR:
|
|
|
|
return "Bit Or";
|
|
|
|
case Variant::OP_BIT_XOR:
|
|
|
|
return "Bit Xor";
|
|
|
|
case Variant::OP_BIT_NEGATE:
|
|
|
|
return "Bit Negate";
|
|
|
|
|
|
|
|
// logic
|
|
|
|
case Variant::OP_AND:
|
|
|
|
return "And";
|
|
|
|
case Variant::OP_OR:
|
|
|
|
return "Or";
|
|
|
|
case Variant::OP_XOR:
|
|
|
|
return "Xor";
|
|
|
|
case Variant::OP_NOT:
|
|
|
|
return "Not";
|
|
|
|
case Variant::OP_IN:
|
|
|
|
return "In";
|
|
|
|
|
|
|
|
default: {
|
|
|
|
ERR_FAIL_INDEX_V(p_op, Variant::OP_MAX, "");
|
|
|
|
return "Unknown Operator";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void VisualScriptOperator::set_operator(Variant::Operator p_op) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (op == p_op) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
op = p_op;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::Operator VisualScriptOperator::get_operator() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return op;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
void VisualScriptOperator::set_typed(Variant::Type p_op) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (typed == p_op) {
|
2016-08-29 01:57:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
typed = p_op;
|
2016-08-29 01:57:27 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptOperator::get_typed() const {
|
|
|
|
return typed;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void VisualScriptOperator::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualScriptOperator::set_operator);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_operator"), &VisualScriptOperator::get_operator);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptOperator::set_typed);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptOperator::get_typed);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
String types;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < Variant::OP_MAX; i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
types += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-27 14:28:12 +02:00
|
|
|
types += get_operator_name(static_cast<Variant::Operator>(i));
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, types), "set_operator", "get_operator");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_typed", "get_typed");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceOperator : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
bool unary = false;
|
2016-08-06 03:46:45 +02:00
|
|
|
Variant::Operator op;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-06 03:46:45 +02:00
|
|
|
bool valid;
|
|
|
|
if (unary) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::evaluate(op, *p_inputs[0], Variant(), *p_outputs[0], valid);
|
2016-08-06 03:46:45 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::evaluate(op, *p_inputs[0], *p_inputs[1], *p_outputs[0], valid);
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_outputs[0]->get_type() == Variant::STRING) {
|
|
|
|
r_error_str = *p_outputs[0];
|
2016-08-07 00:00:54 +02:00
|
|
|
} else {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (unary) {
|
2022-06-08 11:42:51 +02:00
|
|
|
r_error_str = String(Variant::get_operator_name(op)) + ": " + RTR("Invalid argument of type:") + " " + Variant::get_type_name(p_inputs[0]->get_type());
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2022-06-08 11:42:51 +02:00
|
|
|
r_error_str = String(Variant::get_operator_name(op)) + ": " + RTR("Invalid arguments:") + " A: " + Variant::get_type_name(p_inputs[0]->get_type()) + ", B: " + Variant::get_type_name(p_inputs[1]->get_type());
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptOperator::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceOperator *instance = memnew(VisualScriptNodeInstanceOperator);
|
|
|
|
instance->unary = get_input_value_port_count() == 1;
|
|
|
|
instance->op = op;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptOperator::VisualScriptOperator() {
|
2017-03-05 16:44:50 +01:00
|
|
|
op = Variant::OP_ADD;
|
|
|
|
typed = Variant::NIL;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
template <Variant::Operator OP>
|
|
|
|
static Ref<VisualScriptNode> create_op_node(const String &p_name) {
|
2016-08-03 00:11:05 +02:00
|
|
|
Ref<VisualScriptOperator> node;
|
2021-06-18 00:03:09 +02:00
|
|
|
node.instantiate();
|
2016-08-03 00:11:05 +02:00
|
|
|
node->set_operator(OP);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////OPERATOR//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptSelect::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualScriptSelect::has_input_sequence_port() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptSelect::get_input_value_port_count() const {
|
|
|
|
return 3;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
int VisualScriptSelect::get_output_value_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSelect::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
|
|
|
PropertyInfo VisualScriptSelect::get_input_value_port_info(int p_idx) const {
|
|
|
|
if (p_idx == 0) {
|
|
|
|
return PropertyInfo(Variant::BOOL, "cond");
|
|
|
|
} else if (p_idx == 1) {
|
|
|
|
return PropertyInfo(typed, "a");
|
|
|
|
} else {
|
|
|
|
return PropertyInfo(typed, "b");
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
PropertyInfo VisualScriptSelect::get_output_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(typed, "out");
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSelect::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Select");
|
2017-07-01 02:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSelect::get_text() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("a if cond, else b");
|
2017-07-01 02:30:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptSelect::set_typed(Variant::Type p_op) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (typed == p_op) {
|
2017-07-01 02:30:17 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-01 02:30:17 +02:00
|
|
|
|
|
|
|
typed = p_op;
|
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptSelect::get_typed() const {
|
|
|
|
return typed;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptSelect::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_typed", "type"), &VisualScriptSelect::set_typed);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_typed"), &VisualScriptSelect::get_typed);
|
|
|
|
|
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_typed", "get_typed");
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceSelect : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2017-07-01 02:30:17 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-07-01 02:30:17 +02:00
|
|
|
bool cond = *p_inputs[0];
|
2020-05-14 16:41:43 +02:00
|
|
|
if (cond) {
|
2017-07-01 02:30:17 +02:00
|
|
|
*p_outputs[0] = *p_inputs[1];
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2017-07-01 02:30:17 +02:00
|
|
|
*p_outputs[0] = *p_inputs[2];
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-01 02:30:17 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptSelect::instantiate(VisualScriptInstance *p_instance) {
|
2017-07-01 02:30:17 +02:00
|
|
|
VisualScriptNodeInstanceSelect *instance = memnew(VisualScriptNodeInstanceSelect);
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptSelect::VisualScriptSelect() {
|
|
|
|
typed = Variant::NIL;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
2016-08-06 03:46:45 +02:00
|
|
|
////////////////VARIABLE GET//////////////////
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
int VisualScriptVariableGet::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptVariableGet::has_input_sequence_port() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return false;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptVariableGet::get_input_value_port_count() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptVariableGet::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
String VisualScriptVariableGet::get_output_sequence_port_text(int p_port) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptVariableGet::get_input_value_port_info(int p_idx) const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptVariableGet::get_output_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
PropertyInfo pinfo;
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.name = "value";
|
2016-08-03 00:11:05 +02:00
|
|
|
if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) {
|
|
|
|
PropertyInfo vinfo = get_visual_script()->get_variable_info(variable);
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.type = vinfo.type;
|
|
|
|
pinfo.hint = vinfo.hint;
|
|
|
|
pinfo.hint_string = vinfo.hint_string;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
String VisualScriptVariableGet::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return vformat(RTR("Get %s"), variable);
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
void VisualScriptVariableGet::set_variable(StringName p_variable) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (variable == p_variable) {
|
2016-08-06 03:46:45 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
variable = p_variable;
|
2016-08-06 03:46:45 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
StringName VisualScriptVariableGet::get_variable() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptVariableGet::_validate_property(PropertyInfo &property) const {
|
2017-07-01 02:30:17 +02:00
|
|
|
if (property.name == "var_name" && get_visual_script().is_valid()) {
|
2016-08-06 03:46:45 +02:00
|
|
|
Ref<VisualScript> vs = get_visual_script();
|
|
|
|
List<StringName> vars;
|
|
|
|
vs->get_variable_list(&vars);
|
|
|
|
|
|
|
|
String vhint;
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const StringName &E : vars) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!vhint.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
vhint += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2021-07-16 05:45:57 +02:00
|
|
|
vhint += E.operator String();
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint = PROPERTY_HINT_ENUM;
|
|
|
|
property.hint_string = vhint;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptVariableGet::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableGet::set_variable);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableGet::get_variable);
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable");
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceVariableGet : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptVariableGet *node = nullptr;
|
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-06 03:46:45 +02:00
|
|
|
StringName variable;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2018-10-06 22:20:41 +02:00
|
|
|
if (!instance->get_variable(variable, p_outputs[0])) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2022-06-08 11:42:51 +02:00
|
|
|
r_error_str = RTR("VariableGet not found in script:") + " '" + String(variable) + "'";
|
2019-12-10 05:13:02 +01:00
|
|
|
return 0;
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptVariableGet::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceVariableGet *instance = memnew(VisualScriptNodeInstanceVariableGet);
|
|
|
|
instance->node = this;
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->variable = variable;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
VisualScriptVariableGet::VisualScriptVariableGet() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
2016-08-30 16:42:39 +02:00
|
|
|
////////////////VARIABLE SET//////////////////
|
2016-08-06 03:46:45 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptVariableSet::get_output_sequence_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptVariableSet::has_input_sequence_port() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptVariableSet::get_input_value_port_count() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptVariableSet::get_output_value_port_count() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptVariableSet::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptVariableSet::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
PropertyInfo pinfo;
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.name = "set";
|
2016-08-03 00:11:05 +02:00
|
|
|
if (get_visual_script().is_valid() && get_visual_script()->has_variable(variable)) {
|
|
|
|
PropertyInfo vinfo = get_visual_script()->get_variable_info(variable);
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.type = vinfo.type;
|
|
|
|
pinfo.hint = vinfo.hint;
|
|
|
|
pinfo.hint_string = vinfo.hint_string;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptVariableSet::get_output_value_port_info(int p_idx) const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
String VisualScriptVariableSet::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return vformat(RTR("Set %s"), variable);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
void VisualScriptVariableSet::set_variable(StringName p_variable) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (variable == p_variable) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
variable = p_variable;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
StringName VisualScriptVariableSet::get_variable() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return variable;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptVariableSet::_validate_property(PropertyInfo &property) const {
|
2017-07-01 02:30:17 +02:00
|
|
|
if (property.name == "var_name" && get_visual_script().is_valid()) {
|
2016-08-03 00:11:05 +02:00
|
|
|
Ref<VisualScript> vs = get_visual_script();
|
|
|
|
List<StringName> vars;
|
|
|
|
vs->get_variable_list(&vars);
|
|
|
|
|
|
|
|
String vhint;
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const StringName &E : vars) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!vhint.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
vhint += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2021-07-16 05:45:57 +02:00
|
|
|
vhint += E.operator String();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint = PROPERTY_HINT_ENUM;
|
|
|
|
property.hint_string = vhint;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
void VisualScriptVariableSet::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_variable", "name"), &VisualScriptVariableSet::set_variable);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_variable"), &VisualScriptVariableSet::get_variable);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_variable", "get_variable");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceVariableSet : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptVariableSet *node = nullptr;
|
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-06 03:46:45 +02:00
|
|
|
StringName variable;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2018-10-06 22:20:41 +02:00
|
|
|
if (!instance->set_variable(variable, *p_inputs[0])) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2022-06-08 11:42:51 +02:00
|
|
|
r_error_str = RTR("VariableSet not found in script:") + " '" + String(variable) + "'";
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptVariableSet::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceVariableSet *instance = memnew(VisualScriptNodeInstanceVariableSet);
|
|
|
|
instance->node = this;
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->variable = variable;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
VisualScriptVariableSet::VisualScriptVariableSet() {
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////CONSTANT//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptConstant::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptConstant::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptConstant::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptConstant::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptConstant::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptConstant::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptConstant::get_output_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
PropertyInfo pinfo;
|
2018-05-01 00:39:28 +02:00
|
|
|
pinfo.name = String(value);
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.type = type;
|
2016-08-03 00:11:05 +02:00
|
|
|
return pinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptConstant::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Constant");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptConstant::set_constant_type(Variant::Type p_type) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (type == p_type) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_type;
|
2020-02-19 20:27:19 +01:00
|
|
|
Callable::CallError ce;
|
2020-11-09 04:19:09 +01:00
|
|
|
Variant::construct(type, value, nullptr, 0, ce);
|
2017-11-25 22:28:59 +01:00
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::Type VisualScriptConstant::get_constant_type() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptConstant::set_constant_value(Variant p_value) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (value == p_value) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
value = p_value;
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant VisualScriptConstant::get_constant_value() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptConstant::_validate_property(PropertyInfo &property) const {
|
2017-07-01 02:30:17 +02:00
|
|
|
if (property.name == "value") {
|
2017-03-05 16:44:50 +01:00
|
|
|
property.type = type;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (type == Variant::NIL) {
|
2021-07-01 03:24:34 +02:00
|
|
|
property.usage = PROPERTY_USAGE_NONE; //do not save if nil
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptConstant::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_constant_type", "type"), &VisualScriptConstant::set_constant_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_constant_type"), &VisualScriptConstant::get_constant_type);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_constant_value", "value"), &VisualScriptConstant::set_constant_value);
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_constant_value"), &VisualScriptConstant::get_constant_value);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Null";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_constant_type", "get_constant_type");
|
2017-11-25 22:28:59 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NIL, "value", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT | PROPERTY_USAGE_DEFAULT), "set_constant_value", "get_constant_value");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceConstant : public VisualScriptNodeInstance {
|
|
|
|
public:
|
|
|
|
Variant constant;
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = constant;
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptConstant::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceConstant *instance = memnew(VisualScriptNodeInstanceConstant);
|
|
|
|
instance->constant = value;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptConstant::VisualScriptConstant() {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = Variant::NIL;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////PRELOAD//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptPreload::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptPreload::has_input_sequence_port() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptPreload::get_input_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptPreload::get_output_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptPreload::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptPreload::get_input_value_port_info(int p_idx) const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptPreload::get_output_value_port_info(int p_idx) const {
|
2018-05-01 00:39:28 +02:00
|
|
|
PropertyInfo pinfo;
|
|
|
|
pinfo.type = Variant::OBJECT;
|
2016-09-03 19:58:23 +02:00
|
|
|
if (preload.is_valid()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
pinfo.hint = PROPERTY_HINT_RESOURCE_TYPE;
|
|
|
|
pinfo.hint_string = preload->get_class();
|
2018-05-01 00:39:28 +02:00
|
|
|
if (preload->get_path().is_resource_file()) {
|
|
|
|
pinfo.name = preload->get_path();
|
2021-12-09 10:42:46 +01:00
|
|
|
} else if (!preload->get_name().is_empty()) {
|
2018-05-01 00:39:28 +02:00
|
|
|
pinfo.name = preload->get_name();
|
|
|
|
} else {
|
|
|
|
pinfo.name = preload->get_class();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pinfo.name = "<empty>";
|
2016-09-03 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return pinfo;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptPreload::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Preload");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptPreload::set_preload(const Ref<Resource> &p_preload) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (preload == p_preload) {
|
2016-08-29 01:57:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
preload = p_preload;
|
2016-08-29 01:57:27 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
2017-08-12 18:52:50 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<Resource> VisualScriptPreload::get_preload() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return preload;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptPreload::_bind_methods() {
|
2017-08-09 13:19:41 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_preload", "resource"), &VisualScriptPreload::set_preload);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_preload"), &VisualScriptPreload::get_preload);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), "set_preload", "get_preload");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstancePreload : public VisualScriptNodeInstance {
|
|
|
|
public:
|
|
|
|
Ref<Resource> preload;
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = preload;
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptPreload::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstancePreload *instance = memnew(VisualScriptNodeInstancePreload);
|
|
|
|
instance->preload = preload;
|
2016-08-29 01:57:27 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptPreload::VisualScriptPreload() {
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////INDEX////////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptIndexGet::get_output_sequence_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptIndexGet::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return false;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptIndexGet::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 2;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptIndexGet::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptIndexGet::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptIndexGet::get_input_value_port_info(int p_idx) const {
|
|
|
|
if (p_idx == 0) {
|
|
|
|
return PropertyInfo(Variant::NIL, "base");
|
2016-08-03 00:11:05 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return PropertyInfo(Variant::NIL, "index");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptIndexGet::get_output_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptIndexGet::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Index");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceIndexGet : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-06 03:46:45 +02:00
|
|
|
bool valid;
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = p_inputs[0]->get(*p_inputs[1], &valid);
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
if (!valid) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Invalid get: " + p_inputs[0]->get_construct_string();
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptIndexGet::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceIndexGet *instance = memnew(VisualScriptNodeInstanceIndexGet);
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
VisualScriptIndexGet::VisualScriptIndexGet() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////INDEXSET//////////////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptIndexSet::get_output_sequence_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptIndexSet::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptIndexSet::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 3;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptIndexSet::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptIndexSet::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptIndexSet::get_input_value_port_info(int p_idx) const {
|
|
|
|
if (p_idx == 0) {
|
|
|
|
return PropertyInfo(Variant::NIL, "base");
|
|
|
|
} else if (p_idx == 1) {
|
|
|
|
return PropertyInfo(Variant::NIL, "index");
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
return PropertyInfo(Variant::NIL, "value");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptIndexSet::get_output_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptIndexSet::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Set Index");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceIndexSet : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-06 03:46:45 +02:00
|
|
|
bool valid;
|
2022-02-16 08:27:41 +01:00
|
|
|
((Variant *)p_inputs[0])->set(*p_inputs[1], *p_inputs[2], &valid);
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
if (!valid) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Invalid set: " + p_inputs[1]->get_construct_string();
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptIndexSet::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceIndexSet *instance = memnew(VisualScriptNodeInstanceIndexSet);
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
VisualScriptIndexSet::VisualScriptIndexSet() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////GLOBALCONSTANT///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptGlobalConstant::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptGlobalConstant::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptGlobalConstant::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptGlobalConstant::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptGlobalConstant::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptGlobalConstant::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptGlobalConstant::get_output_value_port_info(int p_idx) const {
|
2020-11-07 23:33:38 +01:00
|
|
|
String name = CoreConstants::get_global_constant_name(index);
|
2020-01-30 18:20:33 +01:00
|
|
|
return PropertyInfo(Variant::INT, name);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptGlobalConstant::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Global Constant");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptGlobalConstant::set_global_constant(int p_which) {
|
2017-03-05 16:44:50 +01:00
|
|
|
index = p_which;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int VisualScriptGlobalConstant::get_global_constant() {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceGlobalConstant : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
int index = 0;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2020-11-07 23:33:38 +01:00
|
|
|
*p_outputs[0] = CoreConstants::get_global_constant_value(index);
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptGlobalConstant::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceGlobalConstant *instance = memnew(VisualScriptNodeInstanceGlobalConstant);
|
|
|
|
instance->index = index;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptGlobalConstant::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_constant", "index"), &VisualScriptGlobalConstant::set_global_constant);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_constant"), &VisualScriptGlobalConstant::get_global_constant);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
String cc;
|
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
for (int i = 0; i < CoreConstants::get_global_constant_count(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
cc += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-11-07 23:33:38 +01:00
|
|
|
cc += CoreConstants::get_global_constant_name(i);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2017-09-12 12:58:18 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_global_constant", "get_global_constant");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptGlobalConstant::VisualScriptGlobalConstant() {
|
2017-03-05 16:44:50 +01:00
|
|
|
index = 0;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 17:49:45 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////CLASSCONSTANT///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptClassConstant::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptClassConstant::has_input_sequence_port() const {
|
2016-08-31 17:49:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptClassConstant::get_input_value_port_count() const {
|
2016-08-31 17:49:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptClassConstant::get_output_value_port_count() const {
|
2016-08-31 17:49:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptClassConstant::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptClassConstant::get_input_value_port_info(int p_idx) const {
|
2016-08-31 17:49:45 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptClassConstant::get_output_value_port_info(int p_idx) const {
|
2020-02-10 08:49:11 +01:00
|
|
|
if (name == "") {
|
|
|
|
return PropertyInfo(Variant::INT, String(base_type));
|
|
|
|
} else {
|
|
|
|
return PropertyInfo(Variant::INT, String(base_type) + "." + String(name));
|
|
|
|
}
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptClassConstant::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Class Constant");
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptClassConstant::set_class_constant(const StringName &p_which) {
|
|
|
|
name = p_which;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-31 17:49:45 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptClassConstant::get_class_constant() {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptClassConstant::set_base_type(const StringName &p_which) {
|
|
|
|
base_type = p_which;
|
2020-02-10 08:49:11 +01:00
|
|
|
List<String> constants;
|
|
|
|
ClassDB::get_integer_constant_list(base_type, &constants, true);
|
|
|
|
if (constants.size() > 0) {
|
|
|
|
bool found_name = false;
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const String &E : constants) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E == name) {
|
2020-02-10 08:49:11 +01:00
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found_name) {
|
|
|
|
name = constants[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = "";
|
|
|
|
}
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-31 17:49:45 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptClassConstant::get_base_type() {
|
|
|
|
return base_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceClassConstant : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
int value = 0;
|
|
|
|
bool valid = false;
|
2016-08-31 17:49:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-31 17:49:45 +02:00
|
|
|
if (!valid) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Invalid constant name, pick a valid class constant.";
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*p_outputs[0] = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptClassConstant::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceClassConstant *instance = memnew(VisualScriptNodeInstanceClassConstant);
|
|
|
|
instance->value = ClassDB::get_integer_constant(base_type, name, &instance->valid);
|
2016-08-31 17:49:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptClassConstant::_validate_property(PropertyInfo &property) const {
|
2017-09-28 12:07:20 +02:00
|
|
|
if (property.name == "constant") {
|
2016-08-31 17:49:45 +02:00
|
|
|
List<String> constants;
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::get_integer_constant_list(base_type, &constants, true);
|
2016-08-31 17:49:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string = "";
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const String &E : constants) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!property.hint_string.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string += ",";
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
property.hint_string += E;
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptClassConstant::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_class_constant", "name"), &VisualScriptClassConstant::set_class_constant);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_class_constant"), &VisualScriptClassConstant::get_class_constant);
|
2016-08-31 17:49:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_base_type", "name"), &VisualScriptClassConstant::set_base_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_base_type"), &VisualScriptClassConstant::get_base_type);
|
2016-08-31 17:49:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "base_type", PROPERTY_HINT_TYPE_STRING, "Object"), "set_base_type", "get_base_type");
|
2017-09-12 12:58:18 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_class_constant", "get_class_constant");
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptClassConstant::VisualScriptClassConstant() {
|
2017-03-05 16:44:50 +01:00
|
|
|
base_type = "Object";
|
2016-08-31 17:49:45 +02:00
|
|
|
}
|
|
|
|
|
2016-09-02 07:13:12 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////BASICTYPECONSTANT///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptBasicTypeConstant::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptBasicTypeConstant::has_input_sequence_port() const {
|
2016-09-02 07:13:12 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptBasicTypeConstant::get_input_value_port_count() const {
|
2016-09-02 07:13:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptBasicTypeConstant::get_output_value_port_count() const {
|
2016-09-02 07:13:12 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptBasicTypeConstant::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptBasicTypeConstant::get_input_value_port_info(int p_idx) const {
|
2016-09-02 07:13:12 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptBasicTypeConstant::get_output_value_port_info(int p_idx) const {
|
2020-01-30 18:20:33 +01:00
|
|
|
return PropertyInfo(type, "value");
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptBasicTypeConstant::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Basic Constant");
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptBasicTypeConstant::get_text() const {
|
2020-01-30 18:20:33 +01:00
|
|
|
if (name == "") {
|
|
|
|
return Variant::get_type_name(type);
|
|
|
|
} else {
|
|
|
|
return Variant::get_type_name(type) + "." + String(name);
|
|
|
|
}
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptBasicTypeConstant::set_basic_type_constant(const StringName &p_which) {
|
|
|
|
name = p_which;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-09-02 07:13:12 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptBasicTypeConstant::get_basic_type_constant() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptBasicTypeConstant::set_basic_type(Variant::Type p_which) {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_which;
|
2020-01-30 18:20:33 +01:00
|
|
|
|
|
|
|
List<StringName> constants;
|
|
|
|
Variant::get_constants_for_type(type, &constants);
|
|
|
|
if (constants.size() > 0) {
|
|
|
|
bool found_name = false;
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const StringName &E : constants) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E == name) {
|
2020-01-30 18:20:33 +01:00
|
|
|
found_name = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found_name) {
|
|
|
|
name = constants[0];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
name = "";
|
|
|
|
}
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-09-02 07:13:12 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptBasicTypeConstant::get_basic_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceBasicTypeConstant : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2017-12-15 16:43:27 +01:00
|
|
|
Variant value;
|
2022-05-02 16:28:25 +02:00
|
|
|
bool valid = false;
|
2016-09-02 07:13:12 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-09-02 07:13:12 +02:00
|
|
|
if (!valid) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Invalid constant name, pick a valid basic type constant.";
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*p_outputs[0] = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptBasicTypeConstant::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceBasicTypeConstant *instance = memnew(VisualScriptNodeInstanceBasicTypeConstant);
|
2017-12-15 16:43:27 +01:00
|
|
|
instance->value = Variant::get_constant_value(type, name, &instance->valid);
|
2016-09-02 07:13:12 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptBasicTypeConstant::_validate_property(PropertyInfo &property) const {
|
2017-09-28 12:07:20 +02:00
|
|
|
if (property.name == "constant") {
|
2016-09-02 07:13:12 +02:00
|
|
|
List<StringName> constants;
|
2017-12-15 16:43:27 +01:00
|
|
|
Variant::get_constants_for_type(type, &constants);
|
2016-09-02 07:13:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (constants.size() == 0) {
|
2021-07-01 03:24:34 +02:00
|
|
|
property.usage = PROPERTY_USAGE_NONE;
|
2016-09-02 07:13:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string = "";
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const StringName &E : constants) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!property.hint_string.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string += ",";
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
property.hint_string += String(E);
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptBasicTypeConstant::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_basic_type", "name"), &VisualScriptBasicTypeConstant::set_basic_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_basic_type"), &VisualScriptBasicTypeConstant::get_basic_type);
|
2016-09-02 07:13:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_basic_type_constant", "name"), &VisualScriptBasicTypeConstant::set_basic_type_constant);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_basic_type_constant"), &VisualScriptBasicTypeConstant::get_basic_type_constant);
|
2016-09-02 07:13:12 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Null";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "basic_type", PROPERTY_HINT_ENUM, argt), "set_basic_type", "get_basic_type");
|
2017-09-12 12:58:18 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant", PROPERTY_HINT_ENUM, ""), "set_basic_type_constant", "get_basic_type_constant");
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptBasicTypeConstant::VisualScriptBasicTypeConstant() {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = Variant::NIL;
|
2016-09-02 07:13:12 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////MATHCONSTANT///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *VisualScriptMathConstant::const_name[MATH_CONSTANT_MAX] = {
|
2016-08-03 00:11:05 +02:00
|
|
|
"One",
|
|
|
|
"PI",
|
|
|
|
"PI/2",
|
2017-11-04 10:34:27 +01:00
|
|
|
"TAU",
|
2016-08-03 00:11:05 +02:00
|
|
|
"E",
|
|
|
|
"Sqrt2",
|
2017-02-06 23:44:22 +01:00
|
|
|
"INF",
|
|
|
|
"NAN"
|
2016-08-03 00:11:05 +02:00
|
|
|
};
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
double VisualScriptMathConstant::const_value[MATH_CONSTANT_MAX] = {
|
2016-08-06 03:46:45 +02:00
|
|
|
1.0,
|
|
|
|
Math_PI,
|
2017-03-05 16:44:50 +01:00
|
|
|
Math_PI * 0.5,
|
2017-11-04 10:34:27 +01:00
|
|
|
Math_TAU,
|
2016-08-06 03:46:45 +02:00
|
|
|
2.71828182845904523536,
|
2017-02-06 23:44:22 +01:00
|
|
|
Math::sqrt(2.0),
|
2021-07-21 10:40:31 +02:00
|
|
|
INFINITY,
|
|
|
|
NAN
|
2016-08-06 03:46:45 +02:00
|
|
|
};
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
int VisualScriptMathConstant::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptMathConstant::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptMathConstant::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptMathConstant::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptMathConstant::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptMathConstant::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptMathConstant::get_output_value_port_info(int p_idx) const {
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 19:20:53 +01:00
|
|
|
return PropertyInfo(Variant::FLOAT, const_name[constant]);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptMathConstant::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Math Constant");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptMathConstant::set_math_constant(MathConstant p_which) {
|
2017-03-05 16:44:50 +01:00
|
|
|
constant = p_which;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptMathConstant::MathConstant VisualScriptMathConstant::get_math_constant() {
|
|
|
|
return constant;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceMathConstant : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
float value = 0.0f;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = value;
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptMathConstant::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceMathConstant *instance = memnew(VisualScriptNodeInstanceMathConstant);
|
|
|
|
instance->value = const_value[constant];
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptMathConstant::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_math_constant", "which"), &VisualScriptMathConstant::set_math_constant);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_math_constant"), &VisualScriptMathConstant::get_math_constant);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
String cc;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < MATH_CONSTANT_MAX; i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
cc += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
cc += const_name[i];
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2017-09-12 12:58:18 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "constant", PROPERTY_HINT_ENUM, cc), "set_math_constant", "get_math_constant");
|
2017-09-12 21:09:06 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_ONE);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_PI);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_HALF_PI);
|
2017-11-04 10:34:27 +01:00
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_TAU);
|
2017-09-12 21:09:06 +02:00
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_E);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_SQRT2);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_INF);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_NAN);
|
|
|
|
BIND_ENUM_CONSTANT(MATH_CONSTANT_MAX);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptMathConstant::VisualScriptMathConstant() {
|
2017-03-05 16:44:50 +01:00
|
|
|
constant = MATH_CONSTANT_ONE;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
2018-05-01 00:39:28 +02:00
|
|
|
////////////////ENGINESINGLETON///////////
|
2016-08-03 00:11:05 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
int VisualScriptEngineSingleton::get_output_sequence_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptEngineSingleton::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptEngineSingleton::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptEngineSingleton::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
String VisualScriptEngineSingleton::get_output_sequence_port_text(int p_port) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptEngineSingleton::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptEngineSingleton::get_output_value_port_info(int p_idx) const {
|
2018-05-01 00:39:28 +02:00
|
|
|
return PropertyInfo(Variant::OBJECT, singleton);
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
String VisualScriptEngineSingleton::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Engine Singleton");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptEngineSingleton::set_singleton(const String &p_string) {
|
|
|
|
singleton = p_string;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
String VisualScriptEngineSingleton::get_singleton() {
|
2016-08-03 00:11:05 +02:00
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceEngineSingleton : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
Object *singleton = nullptr;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = singleton;
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptEngineSingleton::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceEngineSingleton *instance = memnew(VisualScriptNodeInstanceEngineSingleton);
|
2017-11-13 21:46:57 +01:00
|
|
|
instance->singleton = Engine::get_singleton()->get_singleton_object(singleton);
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptEngineSingleton::TypeGuess VisualScriptEngineSingleton::guess_output_type(TypeGuess *p_inputs, int p_output) const {
|
2017-11-13 21:46:57 +01:00
|
|
|
Object *obj = Engine::get_singleton()->get_singleton_object(singleton);
|
2016-09-03 19:58:23 +02:00
|
|
|
TypeGuess tg;
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.type = Variant::OBJECT;
|
2016-09-03 19:58:23 +02:00
|
|
|
if (obj) {
|
2017-07-01 02:30:17 +02:00
|
|
|
tg.gdclass = obj->get_class();
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.script = obj->get_script();
|
2016-09-03 19:58:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return tg;
|
|
|
|
}
|
|
|
|
|
2020-01-19 20:02:40 +01:00
|
|
|
void VisualScriptEngineSingleton::_validate_property(PropertyInfo &property) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
String cc;
|
|
|
|
|
2017-11-13 21:46:57 +01:00
|
|
|
List<Engine::Singleton> singletons;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-11-13 21:46:57 +01:00
|
|
|
Engine::get_singleton()->get_singletons(&singletons);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const Engine::Singleton &E : singletons) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E.name == "VS" || E.name == "PS" || E.name == "PS2D" || E.name == "AS" || E.name == "TS" || E.name == "SS" || E.name == "SS2D") {
|
2016-08-03 00:11:05 +02:00
|
|
|
continue; //skip these, too simple named
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!cc.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
cc += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
cc += E.name;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2020-01-19 20:02:40 +01:00
|
|
|
property.hint = PROPERTY_HINT_ENUM;
|
|
|
|
property.hint_string = cc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptEngineSingleton::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_singleton", "name"), &VisualScriptEngineSingleton::set_singleton);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_singleton"), &VisualScriptEngineSingleton::get_singleton);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "constant"), "set_singleton", "get_singleton");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
VisualScriptEngineSingleton::VisualScriptEngineSingleton() {
|
2017-03-05 16:44:50 +01:00
|
|
|
singleton = String();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////GETNODE///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptSceneNode::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptSceneNode::has_input_sequence_port() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSceneNode::get_input_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSceneNode::get_output_value_port_count() const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSceneNode::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSceneNode::get_input_value_port_info(int p_idx) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSceneNode::get_output_value_port_info(int p_idx) const {
|
2018-05-01 00:39:28 +02:00
|
|
|
return PropertyInfo(Variant::OBJECT, path.simplified());
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSceneNode::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Scene Node");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptSceneNode::set_node_path(const NodePath &p_path) {
|
|
|
|
path = p_path;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
NodePath VisualScriptSceneNode::get_node_path() {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceSceneNode : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptSceneNode *node = nullptr;
|
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-06 03:46:45 +02:00
|
|
|
NodePath path;
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-08-24 22:58:51 +02:00
|
|
|
Node *node = Object::cast_to<Node>(instance->get_owner_ptr());
|
2016-08-06 03:46:45 +02:00
|
|
|
if (!node) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Base object is not a Node!";
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *another = node->get_node(path);
|
2017-08-25 17:14:33 +02:00
|
|
|
if (!another) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Path does not lead Node!";
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = another;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptSceneNode::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceSceneNode *instance = memnew(VisualScriptNodeInstanceSceneNode);
|
|
|
|
instance->node = this;
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->path = path;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
Ref<Script> scr = p_current_node->get_script();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (scr.is_valid() && scr == script) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return p_current_node;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_current_node->get_child_count(); i++) {
|
|
|
|
Node *n = _find_script_node(p_edited_scene, p_current_node->get_child(i), script);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (n) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return n;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
return nullptr;
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptSceneNode::TypeGuess VisualScriptSceneNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
|
2016-09-03 19:58:23 +02:00
|
|
|
VisualScriptSceneNode::TypeGuess tg;
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.type = Variant::OBJECT;
|
2022-02-06 14:12:19 +01:00
|
|
|
tg.gdclass = SNAME("Node");
|
2016-09-03 19:58:23 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Ref<Script> script = get_visual_script();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script.is_valid()) {
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
|
2017-08-24 22:58:51 +02:00
|
|
|
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!scene_tree) {
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-03 19:58:23 +02:00
|
|
|
|
|
|
|
Node *edited_scene = scene_tree->get_edited_scene_root();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!edited_scene) {
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script_node) {
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *another = script_node->get_node(path);
|
2016-09-03 19:58:23 +02:00
|
|
|
|
|
|
|
if (another) {
|
2017-07-01 02:30:17 +02:00
|
|
|
tg.gdclass = another->get_class();
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.script = another->get_script();
|
2016-09-03 19:58:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return tg;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptSceneNode::_validate_property(PropertyInfo &property) const {
|
2016-08-03 00:11:05 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
if (property.name == "node_path") {
|
2016-08-03 00:11:05 +02:00
|
|
|
Ref<Script> script = get_visual_script();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script.is_valid()) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
MainLoop *main_loop = OS::get_singleton()->get_main_loop();
|
2017-08-24 22:58:51 +02:00
|
|
|
SceneTree *scene_tree = Object::cast_to<SceneTree>(main_loop);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!scene_tree) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
|
|
|
Node *edited_scene = scene_tree->get_edited_scene_root();
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!edited_scene) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Node *script_node = _find_script_node(edited_scene, edited_scene, script);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script_node) {
|
2016-08-03 00:11:05 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string = script_node->get_path();
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptSceneNode::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_node_path", "path"), &VisualScriptSceneNode::set_node_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_node_path"), &VisualScriptSceneNode::get_node_path);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_path", PROPERTY_HINT_NODE_PATH_TO_EDITED_NODE), "set_node_path", "get_node_path");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptSceneNode::VisualScriptSceneNode() {
|
2017-03-05 16:44:50 +01:00
|
|
|
path = String(".");
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
|
|
|
|
2016-08-03 16:28:20 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////SceneTree///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptSceneTree::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptSceneTree::has_input_sequence_port() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSceneTree::get_input_value_port_count() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSceneTree::get_output_value_port_count() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSceneTree::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSceneTree::get_input_value_port_info(int p_idx) const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSceneTree::get_output_value_port_info(int p_idx) const {
|
2018-05-13 05:34:35 +02:00
|
|
|
return PropertyInfo(Variant::OBJECT, "Scene Tree", PROPERTY_HINT_TYPE_STRING, "SceneTree");
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSceneTree::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Scene Tree");
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceSceneTree : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptSceneTree *node = nullptr;
|
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-03 16:28:20 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-08-24 22:58:51 +02:00
|
|
|
Node *node = Object::cast_to<Node>(instance->get_owner_ptr());
|
2016-08-06 03:46:45 +02:00
|
|
|
if (!node) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Base object is not a Node!";
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SceneTree *tree = node->get_tree();
|
2016-08-06 03:46:45 +02:00
|
|
|
if (!tree) {
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Attempt to get SceneTree while node is not in the active tree.";
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = tree;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptSceneTree::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceSceneTree *instance = memnew(VisualScriptNodeInstanceSceneTree);
|
|
|
|
instance->node = this;
|
|
|
|
instance->instance = p_instance;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptSceneTree::TypeGuess VisualScriptSceneTree::guess_output_type(TypeGuess *p_inputs, int p_output) const {
|
2016-09-03 19:58:23 +02:00
|
|
|
TypeGuess tg;
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.type = Variant::OBJECT;
|
2022-02-06 14:12:19 +01:00
|
|
|
tg.gdclass = SNAME("SceneTree");
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptSceneTree::_validate_property(PropertyInfo &property) const {
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptSceneTree::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptSceneTree::VisualScriptSceneTree() {
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////RESPATH///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptResourcePath::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptResourcePath::has_input_sequence_port() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptResourcePath::get_input_value_port_count() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptResourcePath::get_output_value_port_count() const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptResourcePath::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptResourcePath::get_input_value_port_info(int p_idx) const {
|
2016-08-03 16:28:20 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptResourcePath::get_output_value_port_info(int p_idx) const {
|
2018-05-01 00:39:28 +02:00
|
|
|
return PropertyInfo(Variant::STRING, path);
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptResourcePath::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Resource Path");
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptResourcePath::set_resource_path(const String &p_path) {
|
|
|
|
path = p_path;
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed();
|
2016-08-04 03:06:39 +02:00
|
|
|
ports_changed_notify();
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptResourcePath::get_resource_path() {
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
class VisualScriptNodeInstanceResourcePath : public VisualScriptNodeInstance {
|
|
|
|
public:
|
|
|
|
String path;
|
2016-08-03 16:28:20 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-31 04:44:14 +02:00
|
|
|
*p_outputs[0] = path;
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptResourcePath::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceResourcePath *instance = memnew(VisualScriptNodeInstanceResourcePath);
|
|
|
|
instance->path = path;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptResourcePath::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_resource_path", "path"), &VisualScriptResourcePath::set_resource_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_resource_path"), &VisualScriptResourcePath::get_resource_path);
|
2016-08-03 16:28:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), "set_resource_path", "get_resource_path");
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptResourcePath::VisualScriptResourcePath() {
|
2017-03-05 16:44:50 +01:00
|
|
|
path = "";
|
2016-08-03 16:28:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-06 03:46:45 +02:00
|
|
|
//////////////////////////////////////////
|
2016-08-08 00:22:33 +02:00
|
|
|
////////////////SELF///////////
|
2016-08-06 03:46:45 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptSelf::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptSelf::has_input_sequence_port() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSelf::get_input_value_port_count() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSelf::get_output_value_port_count() const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSelf::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSelf::get_input_value_port_info(int p_idx) const {
|
2016-08-06 03:46:45 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSelf::get_output_value_port_info(int p_idx) const {
|
2022-02-06 14:12:19 +01:00
|
|
|
StringName type_name;
|
2020-05-14 16:41:43 +02:00
|
|
|
if (get_visual_script().is_valid()) {
|
2018-05-01 00:39:28 +02:00
|
|
|
type_name = get_visual_script()->get_instance_base_type();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2022-02-06 14:12:19 +01:00
|
|
|
type_name = SNAME("instance");
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2018-05-01 00:39:28 +02:00
|
|
|
return PropertyInfo(Variant::OBJECT, type_name);
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
2018-05-01 00:39:28 +02:00
|
|
|
String VisualScriptSelf::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Self");
|
2016-08-06 03:46:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceSelf : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-06 03:46:45 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-31 04:44:14 +02:00
|
|
|
*p_outputs[0] = instance->get_owner_ptr();
|
2016-08-06 03:46:45 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptSelf::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceSelf *instance = memnew(VisualScriptNodeInstanceSelf);
|
|
|
|
instance->instance = p_instance;
|
2016-08-06 03:46:45 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptSelf::TypeGuess VisualScriptSelf::guess_output_type(TypeGuess *p_inputs, int p_output) const {
|
2016-09-03 19:58:23 +02:00
|
|
|
VisualScriptSceneNode::TypeGuess tg;
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.type = Variant::OBJECT;
|
2022-02-06 14:12:19 +01:00
|
|
|
tg.gdclass = SNAME("Object");
|
2016-09-03 19:58:23 +02:00
|
|
|
|
|
|
|
Ref<Script> script = get_visual_script();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!script.is_valid()) {
|
2016-09-03 19:58:23 +02:00
|
|
|
return tg;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-03 19:58:23 +02:00
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
tg.gdclass = script->get_instance_base_type();
|
2017-03-05 16:44:50 +01:00
|
|
|
tg.script = script;
|
2016-09-03 19:58:23 +02:00
|
|
|
|
|
|
|
return tg;
|
|
|
|
}
|
2016-08-06 03:46:45 +02:00
|
|
|
|
|
|
|
void VisualScriptSelf::_bind_methods() {
|
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptSelf::VisualScriptSelf() {
|
|
|
|
}
|
|
|
|
|
2016-08-08 02:22:14 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////CUSTOM (SCRIPTED)///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptCustomNode::get_output_sequence_port_count() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
int ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_sequence_port_count, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptCustomNode::has_input_sequence_port() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
bool ret;
|
|
|
|
if (GDVIRTUAL_CALL(_has_input_sequence_port, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptCustomNode::get_input_value_port_count() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
int ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_input_value_port_count, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptCustomNode::get_output_value_port_count() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
int ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_value_port_count, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptCustomNode::get_output_sequence_port_text(int p_port) const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_sequence_port_text, p_port, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptCustomNode::get_input_value_port_info(int p_idx) const {
|
2016-08-08 02:22:14 +02:00
|
|
|
PropertyInfo info;
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
if (GDVIRTUAL_CALL(_get_input_value_port_type, p_idx, type)) {
|
|
|
|
info.type = Variant::Type(type);
|
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
String name;
|
|
|
|
if (GDVIRTUAL_CALL(_get_input_value_port_name, p_idx, name)) {
|
|
|
|
info.name = name;
|
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
int hint;
|
|
|
|
if (GDVIRTUAL_CALL(_get_input_value_port_hint, p_idx, hint)) {
|
|
|
|
info.hint = PropertyHint(hint);
|
|
|
|
}
|
2021-05-22 15:19:57 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
String hint_string;
|
|
|
|
if (GDVIRTUAL_CALL(_get_input_value_port_hint_string, p_idx, hint_string)) {
|
|
|
|
info.hint_string = hint_string;
|
|
|
|
}
|
2021-05-22 15:19:57 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
|
2016-08-08 02:22:14 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptCustomNode::get_output_value_port_info(int p_idx) const {
|
2016-08-08 02:22:14 +02:00
|
|
|
PropertyInfo info;
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
int type;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_value_port_type, p_idx, type)) {
|
|
|
|
info.type = Variant::Type(type);
|
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
String name;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_value_port_name, p_idx, name)) {
|
|
|
|
info.name = name;
|
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
{
|
|
|
|
int hint;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_value_port_hint, p_idx, hint)) {
|
|
|
|
info.hint = PropertyHint(hint);
|
|
|
|
}
|
2021-05-22 15:19:57 +02:00
|
|
|
}
|
2021-08-22 03:52:44 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
String hint_string;
|
|
|
|
if (GDVIRTUAL_CALL(_get_output_value_port_hint_string, p_idx, hint_string)) {
|
|
|
|
info.hint_string = hint_string;
|
|
|
|
}
|
2021-05-22 15:19:57 +02:00
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2021-05-22 15:19:57 +02:00
|
|
|
VisualScriptCustomNode::TypeGuess VisualScriptCustomNode::guess_output_type(TypeGuess *p_inputs, int p_output) const {
|
|
|
|
TypeGuess tg;
|
|
|
|
PropertyInfo pi = VisualScriptCustomNode::get_output_value_port_info(p_output);
|
|
|
|
tg.type = pi.type;
|
|
|
|
if (pi.type == Variant::OBJECT) {
|
|
|
|
if (pi.hint == PROPERTY_HINT_RESOURCE_TYPE) {
|
|
|
|
if (pi.hint_string.is_resource_file()) {
|
|
|
|
tg.script = ResourceLoader::load(pi.hint_string);
|
|
|
|
} else if (ClassDB::class_exists(pi.hint_string)) {
|
|
|
|
tg.gdclass = pi.hint_string;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tg;
|
|
|
|
}
|
|
|
|
|
2016-08-08 02:22:14 +02:00
|
|
|
String VisualScriptCustomNode::get_caption() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_caption, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("CustomNode");
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptCustomNode::get_text() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_text, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptCustomNode::get_category() const {
|
2021-08-22 03:52:44 +02:00
|
|
|
String ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_category, ret)) {
|
|
|
|
return ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
2019-08-09 21:51:48 +02:00
|
|
|
return "Custom";
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceCustomNode : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
|
|
|
VisualScriptCustomNode *node = nullptr;
|
|
|
|
int in_count = 0;
|
|
|
|
int out_count = 0;
|
|
|
|
int work_mem_size = 0;
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int get_working_memory_size() const override { return work_mem_size; }
|
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2021-08-25 19:44:01 +02:00
|
|
|
if (GDVIRTUAL_IS_OVERRIDDEN_PTR(node, _step)) {
|
2017-01-11 12:53:31 +01:00
|
|
|
Array in_values;
|
|
|
|
Array out_values;
|
|
|
|
Array work_mem;
|
2016-08-08 02:22:14 +02:00
|
|
|
|
|
|
|
in_values.resize(in_count);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < in_count; i++) {
|
2017-07-21 05:05:56 +02:00
|
|
|
in_values[i] = *p_inputs[i];
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-21 05:05:56 +02:00
|
|
|
out_values.resize(out_count);
|
2016-08-08 02:22:14 +02:00
|
|
|
|
|
|
|
work_mem.resize(work_mem_size);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < work_mem_size; i++) {
|
|
|
|
work_mem[i] = p_working_mem[i];
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int ret_out;
|
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
Variant ret;
|
|
|
|
GDVIRTUAL_CALL_PTR(node, _step, in_values, out_values, p_start_mode, work_mem, ret);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (ret.get_type() == Variant::STRING) {
|
|
|
|
r_error_str = ret;
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-08 02:22:14 +02:00
|
|
|
return 0;
|
|
|
|
} else if (ret.is_num()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ret_out = ret;
|
2016-08-08 02:22:14 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = RTR("Invalid return value from _step(), must be integer (seq out), or string (error).");
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-08 02:22:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < out_count; i++) {
|
|
|
|
if (i < out_values.size()) {
|
|
|
|
*p_outputs[i] = out_values[i];
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < work_mem_size; i++) {
|
|
|
|
if (i < work_mem.size()) {
|
|
|
|
p_working_mem[i] = work_mem[i];
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_out;
|
2021-08-22 03:52:44 +02:00
|
|
|
} else {
|
|
|
|
r_error_str = RTR("Custom node has no _step() method, can't process graph.");
|
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptCustomNode::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceCustomNode *instance = memnew(VisualScriptNodeInstanceCustomNode);
|
|
|
|
instance->instance = p_instance;
|
2017-07-21 05:05:56 +02:00
|
|
|
instance->node = this;
|
2017-03-05 16:44:50 +01:00
|
|
|
instance->in_count = get_input_value_port_count();
|
|
|
|
instance->out_count = get_output_value_port_count();
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
instance->work_mem_size = 0;
|
|
|
|
GDVIRTUAL_CALL(_get_working_memory_size, instance->work_mem_size);
|
2016-08-08 02:22:14 +02:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-07-22 04:45:57 +02:00
|
|
|
void VisualScriptCustomNode::_script_changed() {
|
2021-07-17 23:22:52 +02:00
|
|
|
call_deferred(SNAME("ports_changed_notify"));
|
2017-07-22 04:45:57 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 02:22:14 +02:00
|
|
|
void VisualScriptCustomNode::_bind_methods() {
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_output_sequence_port_count);
|
|
|
|
GDVIRTUAL_BIND(_has_input_sequence_port);
|
|
|
|
GDVIRTUAL_BIND(_get_output_sequence_port_text, "seq_idx");
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_input_value_port_count);
|
|
|
|
GDVIRTUAL_BIND(_get_input_value_port_type, "input_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_input_value_port_name, "input_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_input_value_port_hint, "input_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_input_value_port_hint_string, "input_idx");
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_output_value_port_count);
|
|
|
|
GDVIRTUAL_BIND(_get_output_value_port_type, "output_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_output_value_port_name, "output_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_output_value_port_hint, "output_idx");
|
|
|
|
GDVIRTUAL_BIND(_get_output_value_port_hint_string, "output_idx");
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_caption);
|
|
|
|
GDVIRTUAL_BIND(_get_text);
|
|
|
|
GDVIRTUAL_BIND(_get_category);
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_get_working_memory_size);
|
2017-08-29 07:15:46 +02:00
|
|
|
|
2021-08-22 03:52:44 +02:00
|
|
|
GDVIRTUAL_BIND(_step, "inputs", "outputs", "start_mode", "working_mem");
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2017-08-20 17:45:01 +02:00
|
|
|
BIND_ENUM_CONSTANT(START_MODE_BEGIN_SEQUENCE);
|
|
|
|
BIND_ENUM_CONSTANT(START_MODE_CONTINUE_SEQUENCE);
|
|
|
|
BIND_ENUM_CONSTANT(START_MODE_RESUME_YIELD);
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_CONSTANT(STEP_PUSH_STACK_BIT);
|
|
|
|
BIND_CONSTANT(STEP_GO_BACK_BIT);
|
|
|
|
BIND_CONSTANT(STEP_NO_ADVANCE_BIT);
|
|
|
|
BIND_CONSTANT(STEP_EXIT_FUNCTION_BIT);
|
|
|
|
BIND_CONSTANT(STEP_YIELD_BIT);
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptCustomNode::VisualScriptCustomNode() {
|
2020-02-21 18:28:45 +01:00
|
|
|
connect("script_changed", callable_mp(this, &VisualScriptCustomNode::_script_changed));
|
2016-08-08 02:22:14 +02:00
|
|
|
}
|
|
|
|
|
2016-08-08 06:21:22 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////SUBCALL///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptSubCall::get_output_sequence_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptSubCall::has_input_sequence_port() const {
|
2016-08-08 06:21:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSubCall::get_input_value_port_count() const {
|
2016-08-08 06:21:22 +02:00
|
|
|
Ref<Script> script = get_script();
|
|
|
|
|
|
|
|
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
|
|
|
|
MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall);
|
|
|
|
return mi.arguments.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptSubCall::get_output_value_port_count() const {
|
2016-08-08 06:21:22 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSubCall::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSubCall::get_input_value_port_info(int p_idx) const {
|
2016-08-08 06:21:22 +02:00
|
|
|
Ref<Script> script = get_script();
|
|
|
|
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
|
|
|
|
MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall);
|
|
|
|
return mi.arguments[p_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptSubCall::get_output_value_port_info(int p_idx) const {
|
2016-08-08 06:21:22 +02:00
|
|
|
Ref<Script> script = get_script();
|
|
|
|
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
|
|
|
|
MethodInfo mi = script->get_method_info(VisualScriptLanguage::singleton->_subcall);
|
|
|
|
return mi.return_val;
|
|
|
|
}
|
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSubCall::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("SubCall");
|
2016-08-08 06:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSubCall::get_text() const {
|
2016-08-08 06:41:57 +02:00
|
|
|
Ref<Script> script = get_script();
|
|
|
|
if (script.is_valid()) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!script->get_name().is_empty()) {
|
2016-08-08 06:41:57 +02:00
|
|
|
return script->get_name();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (script->get_path().is_resource_file()) {
|
2016-08-08 06:41:57 +02:00
|
|
|
return script->get_path().get_file();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-01-03 03:03:46 +01:00
|
|
|
return script->get_class();
|
2016-08-08 06:41:57 +02:00
|
|
|
}
|
2016-08-08 06:21:22 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptSubCall::get_category() const {
|
|
|
|
return "custom";
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceSubCall : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
|
|
|
VisualScriptSubCall *subcall = nullptr;
|
|
|
|
int input_args = 0;
|
|
|
|
bool valid = false;
|
2016-08-08 06:21:22 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-08 06:21:22 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-08 06:21:22 +02:00
|
|
|
if (!valid) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Node requires a script with a _subcall(<args>) method to work.";
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-08 06:21:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2022-03-09 14:58:40 +01:00
|
|
|
*p_outputs[0] = subcall->callp(VisualScriptLanguage::singleton->_subcall, p_inputs, input_args, r_error);
|
2016-08-08 06:21:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptSubCall::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceSubCall *instance = memnew(VisualScriptNodeInstanceSubCall);
|
|
|
|
instance->instance = p_instance;
|
2016-08-08 06:21:22 +02:00
|
|
|
Ref<Script> script = get_script();
|
|
|
|
if (script.is_valid() && script->has_method(VisualScriptLanguage::singleton->_subcall)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
instance->valid = true;
|
|
|
|
instance->input_args = get_input_value_port_count();
|
2016-08-08 06:21:22 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
instance->valid = false;
|
2016-08-08 06:21:22 +02:00
|
|
|
}
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptSubCall::_bind_methods() {
|
2021-08-22 03:52:44 +02:00
|
|
|
// Since this is script only, registering virtual function is no longer valid. Will have to go in docs.
|
2016-08-08 06:21:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptSubCall::VisualScriptSubCall() {
|
|
|
|
}
|
2016-08-08 02:22:14 +02:00
|
|
|
|
2016-08-25 22:45:20 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////Comment///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptComment::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptComment::has_input_sequence_port() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptComment::get_input_value_port_count() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptComment::get_output_value_port_count() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComment::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptComment::get_input_value_port_info(int p_idx) const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptComment::get_output_value_port_info(int p_idx) const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComment::get_caption() const {
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComment::get_text() const {
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptComment::set_title(const String &p_title) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (title == p_title) {
|
2016-08-25 22:45:20 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
title = p_title;
|
2016-08-25 22:45:20 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String VisualScriptComment::get_title() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return title;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptComment::set_description(const String &p_description) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (description == p_description) {
|
2016-08-25 22:45:20 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
description = p_description;
|
2016-08-25 22:45:20 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String VisualScriptComment::get_description() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptComment::set_size(const Size2 &p_size) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (size == p_size) {
|
2016-08-25 22:45:20 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
size = p_size;
|
2016-08-25 22:45:20 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Size2 VisualScriptComment::get_size() const {
|
2016-08-25 22:45:20 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptComment::get_category() const {
|
|
|
|
return "data";
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceComment : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2016-08-25 22:45:20 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptComment::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceComment *instance = memnew(VisualScriptNodeInstanceComment);
|
|
|
|
instance->instance = p_instance;
|
2016-08-25 22:45:20 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptComment::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_title", "title"), &VisualScriptComment::set_title);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_title"), &VisualScriptComment::get_title);
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_description", "description"), &VisualScriptComment::set_description);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_description"), &VisualScriptComment::get_description);
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_size", "size"), &VisualScriptComment::set_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_size"), &VisualScriptComment::get_size);
|
2016-08-25 22:45:20 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "description", PROPERTY_HINT_MULTILINE_TEXT), "set_description", "get_description");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
|
2016-08-25 22:45:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptComment::VisualScriptComment() {
|
2017-03-05 16:44:50 +01:00
|
|
|
title = "Comment";
|
|
|
|
size = Size2(150, 150);
|
2016-08-25 22:45:20 +02:00
|
|
|
}
|
|
|
|
|
2016-08-26 22:34:25 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////Constructor///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptConstructor::get_output_sequence_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptConstructor::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return false;
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptConstructor::get_input_value_port_count() const {
|
2016-08-26 22:34:25 +02:00
|
|
|
return constructor.arguments.size();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptConstructor::get_output_value_port_count() const {
|
2016-08-26 22:34:25 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptConstructor::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptConstructor::get_input_value_port_info(int p_idx) const {
|
2016-08-26 22:34:25 +02:00
|
|
|
return constructor.arguments[p_idx];
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptConstructor::get_output_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(type, "value");
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptConstructor::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return vformat(RTR("Construct %s"), Variant::get_type_name(type));
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptConstructor::get_category() const {
|
|
|
|
return "functions";
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptConstructor::set_constructor_type(Variant::Type p_type) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (type == p_type) {
|
2016-08-26 22:34:25 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_type;
|
2016-08-26 22:34:25 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptConstructor::get_constructor_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptConstructor::set_constructor(const Dictionary &p_info) {
|
|
|
|
constructor = MethodInfo::from_dict(p_info);
|
2016-08-31 22:58:51 +02:00
|
|
|
ports_changed_notify();
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary VisualScriptConstructor::get_constructor() const {
|
|
|
|
return constructor;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceConstructor : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-26 22:34:25 +02:00
|
|
|
Variant::Type type;
|
2022-05-02 16:28:25 +02:00
|
|
|
int argcount = 0;
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2020-02-19 20:27:19 +01:00
|
|
|
Callable::CallError ce;
|
2020-11-09 04:19:09 +01:00
|
|
|
Variant::construct(type, *p_outputs[0], p_inputs, argcount, ce);
|
2020-02-19 20:27:19 +01:00
|
|
|
if (ce.error != Callable::CallError::CALL_OK) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Invalid arguments for constructor";
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptConstructor::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceConstructor *instance = memnew(VisualScriptNodeInstanceConstructor);
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->type = type;
|
|
|
|
instance->argcount = constructor.arguments.size();
|
2016-08-26 22:34:25 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptConstructor::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_constructor_type", "type"), &VisualScriptConstructor::set_constructor_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_constructor_type"), &VisualScriptConstructor::get_constructor_type);
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_constructor", "constructor"), &VisualScriptConstructor::set_constructor);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_constructor"), &VisualScriptConstructor::get_constructor);
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2021-11-03 23:06:17 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor_type", "get_constructor_type");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "constructor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "set_constructor", "get_constructor");
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptConstructor::VisualScriptConstructor() {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = Variant::NIL;
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
|
2022-05-13 15:04:37 +02:00
|
|
|
static HashMap<String, Pair<Variant::Type, MethodInfo>> constructor_map;
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static Ref<VisualScriptNode> create_constructor_node(const String &p_name) {
|
|
|
|
ERR_FAIL_COND_V(!constructor_map.has(p_name), Ref<VisualScriptNode>());
|
2016-08-26 22:34:25 +02:00
|
|
|
|
|
|
|
Ref<VisualScriptConstructor> vsc;
|
2021-06-18 00:03:09 +02:00
|
|
|
vsc.instantiate();
|
2016-08-26 22:34:25 +02:00
|
|
|
vsc->set_constructor_type(constructor_map[p_name].first);
|
|
|
|
vsc->set_constructor(constructor_map[p_name].second);
|
|
|
|
|
|
|
|
return vsc;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////LocalVar///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptLocalVar::get_output_sequence_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptLocalVar::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return false;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptLocalVar::get_input_value_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptLocalVar::get_output_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVar::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptLocalVar::get_input_value_port_info(int p_idx) const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return PropertyInfo();
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptLocalVar::get_output_value_port_info(int p_idx) const {
|
2018-05-01 00:39:28 +02:00
|
|
|
return PropertyInfo(type, name);
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVar::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Get Local Var");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVar::get_category() const {
|
|
|
|
return "data";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptLocalVar::set_var_name(const StringName &p_name) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (name == p_name) {
|
2016-08-29 01:57:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
name = p_name;
|
2016-08-29 01:57:27 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptLocalVar::get_var_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptLocalVar::set_var_type(Variant::Type p_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_type;
|
2016-08-29 01:57:27 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptLocalVar::get_var_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceLocalVar : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-29 01:57:27 +02:00
|
|
|
StringName name;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int get_working_memory_size() const override { return 1; }
|
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[0] = *p_working_mem;
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptLocalVar::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceLocalVar *instance = memnew(VisualScriptNodeInstanceLocalVar);
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->name = name;
|
2016-08-29 01:57:27 +02:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptLocalVar::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVar::set_var_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVar::get_var_name);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_var_type", "type"), &VisualScriptLocalVar::set_var_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_var_type"), &VisualScriptLocalVar::get_var_type);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_var_name", "get_var_name");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptLocalVar::VisualScriptLocalVar() {
|
2017-03-05 16:44:50 +01:00
|
|
|
name = "new_local";
|
|
|
|
type = Variant::NIL;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2016-08-31 04:44:14 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////LocalVar///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptLocalVarSet::get_output_sequence_port_count() const {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptLocalVarSet::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptLocalVarSet::get_input_value_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptLocalVarSet::get_output_value_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVarSet::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptLocalVarSet::get_input_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(type, "set");
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptLocalVarSet::get_output_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(type, "get");
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVarSet::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return RTR("Set Local Var");
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVarSet::get_text() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptLocalVarSet::get_category() const {
|
|
|
|
return "data";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptLocalVarSet::set_var_name(const StringName &p_name) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (name == p_name) {
|
2016-08-31 04:44:14 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
name = p_name;
|
2016-08-31 04:44:14 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptLocalVarSet::get_var_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptLocalVarSet::set_var_type(Variant::Type p_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_type;
|
2016-08-31 04:44:14 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptLocalVarSet::get_var_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceLocalVarSet : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-31 04:44:14 +02:00
|
|
|
StringName name;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int get_working_memory_size() const override { return 1; }
|
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_working_mem = *p_inputs[0];
|
|
|
|
*p_outputs[0] = *p_working_mem;
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptLocalVarSet::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceLocalVarSet *instance = memnew(VisualScriptNodeInstanceLocalVarSet);
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->name = name;
|
2016-08-31 04:44:14 +02:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptLocalVarSet::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_var_name", "name"), &VisualScriptLocalVarSet::set_var_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_var_name"), &VisualScriptLocalVarSet::get_var_name);
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_var_type", "type"), &VisualScriptLocalVarSet::set_var_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_var_type"), &VisualScriptLocalVarSet::get_var_type);
|
2016-08-31 04:44:14 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "var_name"), "set_var_name", "get_var_name");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_var_type", "get_var_type");
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptLocalVarSet::VisualScriptLocalVarSet() {
|
2017-03-05 16:44:50 +01:00
|
|
|
name = "new_local";
|
|
|
|
type = Variant::NIL;
|
2016-08-31 04:44:14 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////LocalVar///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptInputAction::get_output_sequence_port_count() const {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptInputAction::has_input_sequence_port() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptInputAction::get_input_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptInputAction::get_output_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptInputAction::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptInputAction::get_input_value_port_info(int p_idx) const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return PropertyInfo();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptInputAction::get_output_value_port_info(int p_idx) const {
|
2017-07-01 02:30:17 +02:00
|
|
|
String mstr;
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (mode) {
|
2016-09-01 23:58:52 +02:00
|
|
|
case MODE_PRESSED: {
|
2017-07-01 02:30:17 +02:00
|
|
|
mstr = "pressed";
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
case MODE_RELEASED: {
|
2017-07-01 02:30:17 +02:00
|
|
|
mstr = "not pressed";
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
case MODE_JUST_PRESSED: {
|
2017-07-01 02:30:17 +02:00
|
|
|
mstr = "just pressed";
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
case MODE_JUST_RELEASED: {
|
2017-07-01 02:30:17 +02:00
|
|
|
mstr = "just released";
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2017-07-01 02:30:17 +02:00
|
|
|
return PropertyInfo(Variant::BOOL, mstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptInputAction::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return vformat(RTR("Action %s"), name);
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptInputAction::get_category() const {
|
|
|
|
return "data";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptInputAction::set_action_name(const StringName &p_name) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (name == p_name) {
|
2016-08-29 01:57:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
name = p_name;
|
2016-08-29 01:57:27 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
StringName VisualScriptInputAction::get_action_name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2016-09-01 23:58:52 +02:00
|
|
|
void VisualScriptInputAction::set_action_mode(Mode p_mode) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (mode == p_mode) {
|
2016-09-01 23:58:52 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-09-01 23:58:52 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mode = p_mode;
|
2016-09-01 23:58:52 +02:00
|
|
|
ports_changed_notify();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2016-09-01 23:58:52 +02:00
|
|
|
VisualScriptInputAction::Mode VisualScriptInputAction::get_action_mode() const {
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
class VisualScriptNodeInstanceInputAction : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-29 01:57:27 +02:00
|
|
|
StringName action;
|
2016-09-01 23:58:52 +02:00
|
|
|
VisualScriptInputAction::Mode mode;
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (mode) {
|
2016-09-01 23:58:52 +02:00
|
|
|
case VisualScriptInputAction::MODE_PRESSED: {
|
2020-04-28 15:19:37 +02:00
|
|
|
*p_outputs[0] = Input::get_singleton()->is_action_pressed(action);
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
case VisualScriptInputAction::MODE_RELEASED: {
|
2020-04-28 15:19:37 +02:00
|
|
|
*p_outputs[0] = !Input::get_singleton()->is_action_pressed(action);
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
case VisualScriptInputAction::MODE_JUST_PRESSED: {
|
2020-04-28 15:19:37 +02:00
|
|
|
*p_outputs[0] = Input::get_singleton()->is_action_just_pressed(action);
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
2017-03-05 16:44:50 +01:00
|
|
|
case VisualScriptInputAction::MODE_JUST_RELEASED: {
|
2020-04-28 15:19:37 +02:00
|
|
|
*p_outputs[0] = Input::get_singleton()->is_action_just_released(action);
|
2016-09-01 23:58:52 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptInputAction::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceInputAction *instance = memnew(VisualScriptNodeInstanceInputAction);
|
|
|
|
instance->instance = p_instance;
|
|
|
|
instance->action = name;
|
|
|
|
instance->mode = mode;
|
2016-08-29 01:57:27 +02:00
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptInputAction::_validate_property(PropertyInfo &property) const {
|
|
|
|
if (property.name == "action") {
|
|
|
|
property.hint = PROPERTY_HINT_ENUM;
|
2016-08-29 01:57:27 +02:00
|
|
|
String actions;
|
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
2017-07-19 22:00:46 +02:00
|
|
|
ProjectSettings::get_singleton()->get_property_list(&pinfo);
|
2016-08-29 01:57:27 +02:00
|
|
|
Vector<String> al;
|
|
|
|
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const PropertyInfo &pi : pinfo) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!pi.name.begins_with("input/")) {
|
2016-08-29 01:57:27 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
|
2016-08-29 01:57:27 +02:00
|
|
|
|
|
|
|
al.push_back(name);
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:03:38 +01:00
|
|
|
al.sort();
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < al.size(); i++) {
|
2021-12-09 10:42:46 +01:00
|
|
|
if (!actions.is_empty()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
actions += ",";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
actions += al[i];
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
property.hint_string = actions;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptInputAction::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_action_name", "name"), &VisualScriptInputAction::set_action_name);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_action_name"), &VisualScriptInputAction::get_action_name);
|
2016-09-01 23:58:52 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_action_mode", "mode"), &VisualScriptInputAction::set_action_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_action_mode"), &VisualScriptInputAction::get_action_mode);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action_name", "get_action_name");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Pressed,Released,JustPressed,JustReleased"), "set_action_mode", "get_action_mode");
|
2017-09-12 21:09:06 +02:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(MODE_PRESSED);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_RELEASED);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_JUST_PRESSED);
|
|
|
|
BIND_ENUM_CONSTANT(MODE_JUST_RELEASED);
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptInputAction::VisualScriptInputAction() {
|
2017-03-05 16:44:50 +01:00
|
|
|
name = "";
|
|
|
|
mode = MODE_PRESSED;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////
|
|
|
|
////////////////Constructor///////////
|
|
|
|
//////////////////////////////////////////
|
|
|
|
|
|
|
|
int VisualScriptDeconstruct::get_output_sequence_port_count() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return 0;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
bool VisualScriptDeconstruct::has_input_sequence_port() const {
|
2016-08-31 04:44:14 +02:00
|
|
|
return false;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptDeconstruct::get_input_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int VisualScriptDeconstruct::get_output_value_port_count() const {
|
2016-08-29 01:57:27 +02:00
|
|
|
return elements.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptDeconstruct::get_output_sequence_port_text(int p_port) const {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptDeconstruct::get_input_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(type, "value");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
PropertyInfo VisualScriptDeconstruct::get_output_value_port_info(int p_idx) const {
|
|
|
|
return PropertyInfo(elements[p_idx].type, elements[p_idx].name);
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptDeconstruct::get_caption() const {
|
2022-03-11 16:36:16 +01:00
|
|
|
return vformat(RTR("Deconstruct %s"), Variant::get_type_name(type));
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String VisualScriptDeconstruct::get_category() const {
|
|
|
|
return "functions";
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptDeconstruct::_update_elements() {
|
2017-01-14 18:03:38 +01:00
|
|
|
elements.clear();
|
2016-08-29 01:57:27 +02:00
|
|
|
Variant v;
|
2020-02-19 20:27:19 +01:00
|
|
|
Callable::CallError ce;
|
2020-11-09 04:19:09 +01:00
|
|
|
Variant::construct(type, v, nullptr, 0, ce);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
|
|
|
List<PropertyInfo> pinfo;
|
|
|
|
v.get_property_list(&pinfo);
|
|
|
|
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const PropertyInfo &E : pinfo) {
|
2016-08-29 01:57:27 +02:00
|
|
|
Element e;
|
2021-07-16 05:45:57 +02:00
|
|
|
e.name = E.name;
|
|
|
|
e.type = E.type;
|
2016-08-29 01:57:27 +02:00
|
|
|
elements.push_back(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptDeconstruct::set_deconstruct_type(Variant::Type p_type) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (type == p_type) {
|
2016-08-29 01:57:27 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
type = p_type;
|
2016-08-29 01:57:27 +02:00
|
|
|
_update_elements();
|
|
|
|
ports_changed_notify();
|
2021-02-10 21:18:45 +01:00
|
|
|
notify_property_list_changed(); //to make input appear/disappear
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Variant::Type VisualScriptDeconstruct::get_deconstruct_type() const {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptDeconstruct::_set_elem_cache(const Array &p_elements) {
|
|
|
|
ERR_FAIL_COND(p_elements.size() % 2 == 1);
|
|
|
|
elements.resize(p_elements.size() / 2);
|
|
|
|
for (int i = 0; i < elements.size(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
elements.write[i].name = p_elements[i * 2 + 0];
|
|
|
|
elements.write[i].type = Variant::Type(int(p_elements[i * 2 + 1]));
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Array VisualScriptDeconstruct::_get_elem_cache() const {
|
|
|
|
Array ret;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < elements.size(); i++) {
|
2016-08-29 01:57:27 +02:00
|
|
|
ret.push_back(elements[i].name);
|
|
|
|
ret.push_back(elements[i].type);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
class VisualScriptNodeInstanceDeconstruct : public VisualScriptNodeInstance {
|
|
|
|
public:
|
2022-05-02 16:28:25 +02:00
|
|
|
VisualScriptInstance *instance = nullptr;
|
2016-08-29 01:57:27 +02:00
|
|
|
Vector<StringName> outputs;
|
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
//virtual int get_working_memory_size() const override { return 0; }
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2022-04-05 12:40:26 +02:00
|
|
|
virtual int step(const Variant **p_inputs, Variant **p_outputs, StartMode p_start_mode, Variant *p_working_mem, Callable::CallError &r_error, String &r_error_str) override {
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant in = *p_inputs[0];
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < outputs.size(); i++) {
|
2016-08-29 01:57:27 +02:00
|
|
|
bool valid;
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_outputs[i] = in.get(outputs[i], &valid);
|
2016-08-29 01:57:27 +02:00
|
|
|
if (!valid) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_error_str = "Can't obtain element '" + String(outputs[i]) + "' from " + Variant::get_type_name(in.get_type());
|
2020-02-19 20:27:19 +01:00
|
|
|
r_error.error = Callable::CallError::CALL_ERROR_INVALID_METHOD;
|
2016-08-29 01:57:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-06-18 00:03:09 +02:00
|
|
|
VisualScriptNodeInstance *VisualScriptDeconstruct::instantiate(VisualScriptInstance *p_instance) {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptNodeInstanceDeconstruct *instance = memnew(VisualScriptNodeInstanceDeconstruct);
|
|
|
|
instance->instance = p_instance;
|
2016-08-29 01:57:27 +02:00
|
|
|
instance->outputs.resize(elements.size());
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < elements.size(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
instance->outputs.write[i] = elements[i].name;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void VisualScriptDeconstruct::_validate_property(PropertyInfo &property) const {
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisualScriptDeconstruct::_bind_methods() {
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_deconstruct_type", "type"), &VisualScriptDeconstruct::set_deconstruct_type);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_deconstruct_type"), &VisualScriptDeconstruct::get_deconstruct_type);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("_set_elem_cache", "_cache"), &VisualScriptDeconstruct::_set_elem_cache);
|
|
|
|
ClassDB::bind_method(D_METHOD("_get_elem_cache"), &VisualScriptDeconstruct::_get_elem_cache);
|
2016-08-29 01:57:27 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
String argt = "Any";
|
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
|
|
|
argt += "," + Variant::get_type_name(Variant::Type(i));
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "type", PROPERTY_HINT_ENUM, argt), "set_deconstruct_type", "get_deconstruct_type");
|
2021-11-03 23:06:17 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "elem_cache", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_elem_cache", "_get_elem_cache");
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VisualScriptDeconstruct::VisualScriptDeconstruct() {
|
2017-03-05 16:44:50 +01:00
|
|
|
type = Variant::NIL;
|
2016-08-29 01:57:27 +02:00
|
|
|
}
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2019-09-29 13:55:09 +02:00
|
|
|
template <Variant::Type T>
|
|
|
|
static Ref<VisualScriptNode> create_node_deconst_typed(const String &p_name) {
|
|
|
|
Ref<VisualScriptDeconstruct> node;
|
2021-06-18 00:03:09 +02:00
|
|
|
node.instantiate();
|
2019-09-29 13:55:09 +02:00
|
|
|
node->set_deconstruct_type(T);
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2016-08-03 00:11:05 +02:00
|
|
|
void register_visual_script_nodes() {
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/set_variable", create_node_generic<VisualScriptVariableSet>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/get_variable", create_node_generic<VisualScriptVariableGet>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/engine_singleton", create_node_generic<VisualScriptEngineSingleton>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/scene_node", create_node_generic<VisualScriptSceneNode>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/scene_tree", create_node_generic<VisualScriptSceneTree>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/resource_path", create_node_generic<VisualScriptResourcePath>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/self", create_node_generic<VisualScriptSelf>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/comment", create_node_generic<VisualScriptComment>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/get_local_variable", create_node_generic<VisualScriptLocalVar>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/set_local_variable", create_node_generic<VisualScriptLocalVarSet>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/preload", create_node_generic<VisualScriptPreload>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("data/action", create_node_generic<VisualScriptInputAction>);
|
|
|
|
|
2017-09-12 12:58:18 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("constants/constant", create_node_generic<VisualScriptConstant>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("constants/math_constant", create_node_generic<VisualScriptMathConstant>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("constants/class_constant", create_node_generic<VisualScriptClassConstant>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("constants/global_constant", create_node_generic<VisualScriptGlobalConstant>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("constants/basic_type_constant", create_node_generic<VisualScriptBasicTypeConstant>);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("custom/custom_node", create_node_generic<VisualScriptCustomNode>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("custom/sub_call", create_node_generic<VisualScriptSubCall>);
|
|
|
|
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("index/get_index", create_node_generic<VisualScriptIndexGet>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("index/set_index", create_node_generic<VisualScriptIndexSet>);
|
|
|
|
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/equal", create_op_node<Variant::OP_EQUAL>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/not_equal", create_op_node<Variant::OP_NOT_EQUAL>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/less", create_op_node<Variant::OP_LESS>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/less_equal", create_op_node<Variant::OP_LESS_EQUAL>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/greater", create_op_node<Variant::OP_GREATER>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/compare/greater_equal", create_op_node<Variant::OP_GREATER_EQUAL>);
|
2016-08-03 00:11:05 +02:00
|
|
|
//mathematic
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/add", create_op_node<Variant::OP_ADD>);
|
2017-09-17 02:32:05 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/subtract", create_op_node<Variant::OP_SUBTRACT>);
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/multiply", create_op_node<Variant::OP_MULTIPLY>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/divide", create_op_node<Variant::OP_DIVIDE>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/negate", create_op_node<Variant::OP_NEGATE>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/positive", create_op_node<Variant::OP_POSITIVE>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/math/remainder", create_op_node<Variant::OP_MODULE>);
|
2016-08-03 00:11:05 +02:00
|
|
|
//bitwise
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_left", create_op_node<Variant::OP_SHIFT_LEFT>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/shift_right", create_op_node<Variant::OP_SHIFT_RIGHT>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_and", create_op_node<Variant::OP_BIT_AND>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_or", create_op_node<Variant::OP_BIT_OR>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_xor", create_op_node<Variant::OP_BIT_XOR>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/bitwise/bit_negate", create_op_node<Variant::OP_BIT_NEGATE>);
|
2016-08-03 00:11:05 +02:00
|
|
|
//logic
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/and", create_op_node<Variant::OP_AND>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/or", create_op_node<Variant::OP_OR>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/xor", create_op_node<Variant::OP_XOR>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/not", create_op_node<Variant::OP_NOT>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/in", create_op_node<Variant::OP_IN>);
|
2017-07-01 02:30:17 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("operators/logic/select", create_node_generic<VisualScriptSelect>);
|
2016-08-03 00:11:05 +02:00
|
|
|
|
2019-09-29 13:55:09 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR2), create_node_deconst_typed<Variant::Type::VECTOR2>);
|
2020-04-02 19:54:18 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR2I), create_node_deconst_typed<Variant::Type::VECTOR2I>);
|
2019-09-29 13:55:09 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR3), create_node_deconst_typed<Variant::Type::VECTOR3>);
|
2020-04-02 19:54:18 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR3I), create_node_deconst_typed<Variant::Type::VECTOR3I>);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR4), create_node_deconst_typed<Variant::Type::VECTOR4>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::VECTOR4I), create_node_deconst_typed<Variant::Type::VECTOR4I>);
|
2019-09-29 13:55:09 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::COLOR), create_node_deconst_typed<Variant::Type::COLOR>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::RECT2), create_node_deconst_typed<Variant::Type::RECT2>);
|
2020-04-02 19:54:18 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::RECT2I), create_node_deconst_typed<Variant::Type::RECT2I>);
|
2019-09-29 13:55:09 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::TRANSFORM2D), create_node_deconst_typed<Variant::Type::TRANSFORM2D>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::PLANE), create_node_deconst_typed<Variant::Type::PLANE>);
|
2021-01-20 08:02:02 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::QUATERNION), create_node_deconst_typed<Variant::Type::QUATERNION>);
|
2019-09-29 13:55:09 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::AABB), create_node_deconst_typed<Variant::Type::AABB>);
|
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::BASIS), create_node_deconst_typed<Variant::Type::BASIS>);
|
2021-04-28 09:36:08 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::TRANSFORM3D), create_node_deconst_typed<Variant::Type::TRANSFORM3D>);
|
Implement Vector4, Vector4i, Projection
Implement built-in classes Vector4, Vector4i and Projection.
* Two versions of Vector4 (float and integer).
* A Projection class, which is a 4x4 matrix specialized in projection types.
These types have been requested for a long time, but given they were very corner case they were not added before.
Because in Godot 4, reimplementing parts of the rendering engine is now possible, access to these types (heavily used by the rendering code) becomes a necessity.
**Q**: Why Projection and not Matrix4?
**A**: Godot does not use Matrix2, Matrix3, Matrix4x3, etc. naming convention because, within the engine, these types always have a *purpose*. As such, Godot names them: Transform2D, Transform3D or Basis. In this case, this 4x4 matrix is _always_ used as a _Projection_, hence the naming.
2022-07-20 01:11:13 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/deconstruct/" + Variant::get_type_name(Variant::Type::PROJECTION), create_node_deconst_typed<Variant::Type::PROJECTION>);
|
2019-09-13 21:14:12 +02:00
|
|
|
VisualScriptLanguage::singleton->add_register_func("functions/compose_array", create_node_generic<VisualScriptComposeArray>);
|
2016-08-08 06:21:22 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 1; i < Variant::VARIANT_MAX; i++) {
|
2016-08-26 22:34:25 +02:00
|
|
|
List<MethodInfo> constructors;
|
2017-03-05 16:44:50 +01:00
|
|
|
Variant::get_constructor_list(Variant::Type(i), &constructors);
|
2016-08-26 22:34:25 +02:00
|
|
|
|
2021-07-24 15:46:25 +02:00
|
|
|
for (const MethodInfo &E : constructors) {
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E.arguments.size() > 0) {
|
2018-09-30 06:33:21 +02:00
|
|
|
String name = "functions/constructors/" + Variant::get_type_name(Variant::Type(i)) + "(";
|
2021-07-16 05:45:57 +02:00
|
|
|
for (int j = 0; j < E.arguments.size(); j++) {
|
2018-09-30 06:33:21 +02:00
|
|
|
if (j > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
name += ", ";
|
2018-09-30 06:33:21 +02:00
|
|
|
}
|
2021-07-16 05:45:57 +02:00
|
|
|
if (E.arguments.size() == 1) {
|
|
|
|
name += Variant::get_type_name(E.arguments[j].type);
|
2018-09-30 06:33:21 +02:00
|
|
|
} else {
|
2021-07-16 05:45:57 +02:00
|
|
|
name += E.arguments[j].name;
|
2018-09-30 06:33:21 +02:00
|
|
|
}
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
2018-09-30 06:33:21 +02:00
|
|
|
name += ")";
|
2017-03-05 16:44:50 +01:00
|
|
|
VisualScriptLanguage::singleton->add_register_func(name, create_constructor_node);
|
|
|
|
Pair<Variant::Type, MethodInfo> pair;
|
|
|
|
pair.first = Variant::Type(i);
|
2021-07-16 05:45:57 +02:00
|
|
|
pair.second = E;
|
2017-03-05 16:44:50 +01:00
|
|
|
constructor_map[name] = pair;
|
2016-08-26 22:34:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-03 00:11:05 +02:00
|
|
|
}
|
2016-08-26 22:34:25 +02:00
|
|
|
|
|
|
|
void unregister_visual_script_nodes() {
|
|
|
|
constructor_map.clear();
|
|
|
|
}
|