summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
author64epicks <jacob_paul@outlook.com>2019-09-02 22:20:49 +0200
committer64epicks <jacob_paul@outlook.com>2019-09-03 17:06:11 +0200
commite430f8ca61262f5b3594191f0ea51fbc240c0ec3 (patch)
treefd243f0c8d4f219b3438318cfd0e50494bc4fd7a /modules
parentd03ce5c2271ef2d8f7f44003a6aa678149943f4a (diff)
Implemented `ord` function in VisualScript
Diffstat (limited to 'modules')
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.cpp32
-rw-r--r--modules/visual_script/visual_script_builtin_funcs.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/modules/visual_script/visual_script_builtin_funcs.cpp b/modules/visual_script/visual_script_builtin_funcs.cpp
index 8088a71198..3fdceacebb 100644
--- a/modules/visual_script/visual_script_builtin_funcs.cpp
+++ b/modules/visual_script/visual_script_builtin_funcs.cpp
@@ -106,6 +106,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"smoothstep",
"posmod",
"lerp_angle",
+ "ord",
};
VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) {
@@ -181,6 +182,7 @@ int VisualScriptBuiltinFunc::get_func_argument_count(BuiltinFunc p_func) {
case OBJ_WEAKREF:
case TYPE_OF:
case TEXT_CHAR:
+ case TEXT_ORD:
case TEXT_STR:
case TEXT_PRINT:
case TEXT_PRINTERR:
@@ -438,6 +440,9 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case TYPE_EXISTS: {
return PropertyInfo(Variant::STRING, "type");
} break;
+ case TEXT_ORD: {
+ return PropertyInfo(Variant::STRING, "character");
+ } break;
case TEXT_CHAR: {
return PropertyInfo(Variant::INT, "ascii");
} break;
@@ -594,6 +599,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case TYPE_CONVERT: {
} break;
+ case TEXT_ORD:
case TYPE_OF: {
t = Variant::INT;
@@ -1132,6 +1138,30 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
*r_return = String(result);
} break;
+ case VisualScriptBuiltinFunc::TEXT_ORD: {
+
+ if (p_inputs[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+
+ return;
+ }
+
+ String str = p_inputs[0]->operator String();
+
+ if (str.length() != 1) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
+ *r_return = "Expected a string of length 1 (a character).";
+
+ return;
+ }
+
+ *r_return = str.get(0);
+
+ } break;
case VisualScriptBuiltinFunc::TEXT_STR: {
String str = *p_inputs[0];
@@ -1374,6 +1404,7 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_SMOOTHSTEP);
BIND_ENUM_CONSTANT(MATH_POSMOD);
BIND_ENUM_CONSTANT(MATH_LERP_ANGLE);
+ BIND_ENUM_CONSTANT(TEXT_ORD);
BIND_ENUM_CONSTANT(FUNC_MAX);
}
@@ -1460,6 +1491,7 @@ void register_visual_script_builtin_func_node() {
VisualScriptLanguage::singleton->add_register_func("functions/built_in/typeof", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_OF>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/type_exists", create_builtin_func_node<VisualScriptBuiltinFunc::TYPE_EXISTS>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/char", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_CHAR>);
+ VisualScriptLanguage::singleton->add_register_func("functions/built_in/ord", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_ORD>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/str", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_STR>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>);
diff --git a/modules/visual_script/visual_script_builtin_funcs.h b/modules/visual_script/visual_script_builtin_funcs.h
index cf475d675d..998a6cbc6a 100644
--- a/modules/visual_script/visual_script_builtin_funcs.h
+++ b/modules/visual_script/visual_script_builtin_funcs.h
@@ -106,6 +106,7 @@ public:
MATH_SMOOTHSTEP,
MATH_POSMOD,
MATH_LERP_ANGLE,
+ TEXT_ORD,
FUNC_MAX
};