Implemented ord function in VisualScript

This commit is contained in:
64epicks 2019-09-02 22:20:49 +02:00
parent d03ce5c227
commit e430f8ca61
2 changed files with 33 additions and 0 deletions

View file

@ -106,6 +106,7 @@ const char *VisualScriptBuiltinFunc::func_name[VisualScriptBuiltinFunc::FUNC_MAX
"smoothstep", "smoothstep",
"posmod", "posmod",
"lerp_angle", "lerp_angle",
"ord",
}; };
VisualScriptBuiltinFunc::BuiltinFunc VisualScriptBuiltinFunc::find_function(const String &p_string) { 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 OBJ_WEAKREF:
case TYPE_OF: case TYPE_OF:
case TEXT_CHAR: case TEXT_CHAR:
case TEXT_ORD:
case TEXT_STR: case TEXT_STR:
case TEXT_PRINT: case TEXT_PRINT:
case TEXT_PRINTERR: case TEXT_PRINTERR:
@ -438,6 +440,9 @@ PropertyInfo VisualScriptBuiltinFunc::get_input_value_port_info(int p_idx) const
case TYPE_EXISTS: { case TYPE_EXISTS: {
return PropertyInfo(Variant::STRING, "type"); return PropertyInfo(Variant::STRING, "type");
} break; } break;
case TEXT_ORD: {
return PropertyInfo(Variant::STRING, "character");
} break;
case TEXT_CHAR: { case TEXT_CHAR: {
return PropertyInfo(Variant::INT, "ascii"); return PropertyInfo(Variant::INT, "ascii");
} break; } break;
@ -594,6 +599,7 @@ PropertyInfo VisualScriptBuiltinFunc::get_output_value_port_info(int p_idx) cons
case TYPE_CONVERT: { case TYPE_CONVERT: {
} break; } break;
case TEXT_ORD:
case TYPE_OF: { case TYPE_OF: {
t = Variant::INT; t = Variant::INT;
@ -1131,6 +1137,30 @@ void VisualScriptBuiltinFunc::exec_func(BuiltinFunc p_func, const Variant **p_in
*r_return = String(result); *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; } break;
case VisualScriptBuiltinFunc::TEXT_STR: { case VisualScriptBuiltinFunc::TEXT_STR: {
@ -1374,6 +1404,7 @@ void VisualScriptBuiltinFunc::_bind_methods() {
BIND_ENUM_CONSTANT(MATH_SMOOTHSTEP); BIND_ENUM_CONSTANT(MATH_SMOOTHSTEP);
BIND_ENUM_CONSTANT(MATH_POSMOD); BIND_ENUM_CONSTANT(MATH_POSMOD);
BIND_ENUM_CONSTANT(MATH_LERP_ANGLE); BIND_ENUM_CONSTANT(MATH_LERP_ANGLE);
BIND_ENUM_CONSTANT(TEXT_ORD);
BIND_ENUM_CONSTANT(FUNC_MAX); 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/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/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/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/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/print", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINT>);
VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>); VisualScriptLanguage::singleton->add_register_func("functions/built_in/printerr", create_builtin_func_node<VisualScriptBuiltinFunc::TEXT_PRINTERR>);

View file

@ -106,6 +106,7 @@ public:
MATH_SMOOTHSTEP, MATH_SMOOTHSTEP,
MATH_POSMOD, MATH_POSMOD,
MATH_LERP_ANGLE, MATH_LERP_ANGLE,
TEXT_ORD,
FUNC_MAX FUNC_MAX
}; };