Skip to content

Commit

Permalink
GH-112 Correctly coerce ComposeFrom values
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Mar 2, 2024
1 parent e91d54f commit 7c398b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
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

0 comments on commit 7c398b2

Please sign in to comment.