Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-112 Correctly coerce ComposeFrom values #113

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/common/variant_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ namespace VariantUtils
/// @param p_type the variant type
/// @return the default Variant value of the specified type
Variant make_default(Variant::Type p_type);

/// Cast to a desired type.
/// @param p_value the value to be cast
/// @param T the cast type
/// @return the value cast to the specified type <T>
template<typename T> T cast_to(const Variant& p_value) { return T(p_value); }
}

#endif // ORCHESTRATOR_VARIANT_UTILS_H
11 changes: 9 additions & 2 deletions src/script/nodes/data/compose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,19 @@ class OScriptNodeComposeFromInstance : public OScriptNodeInstance
switch (_target_type)
{
case Variant::BOOL:
p_context.set_output(0, VariantUtils::cast_to<bool>(p_context.get_input(0)));
break;
case Variant::INT:
p_context.set_output(0, VariantUtils::cast_to<int>(p_context.get_input(0)));
break;
case Variant::FLOAT:
p_context.set_output(0, VariantUtils::cast_to<float>(p_context.get_input(0)));
break;
case Variant::STRING:
p_context.set_output(0, VariantUtils::cast_to<String>(p_context.get_input(0)));
break;
case Variant::STRING_NAME:
// Perform optimization, no need to use the format solution
p_context.set_output(0, p_context.get_input(0));
p_context.set_output(0, VariantUtils::cast_to<StringName>(p_context.get_input(0)));
break;
default:
{
Expand Down
Loading