diff --git a/core/method_bind.h b/core/method_bind.h index d32050cc5d2..49c64bd11c3 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -98,7 +98,7 @@ struct VariantCaster {\ #define CHECK_ARG(m_arg)\ if ((m_arg-1)get_type(),argtype)) {\ + if (!Variant::can_convert_strict(p_args[m_arg-1]->get_type(),argtype)) {\ r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;\ r_error.argument=m_arg-1;\ r_error.expected=argtype;\ diff --git a/core/variant.cpp b/core/variant.cpp index c06afb2984c..f49b202a5b6 100644 --- a/core/variant.cpp +++ b/core/variant.cpp @@ -214,7 +214,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { static const Type valid[]={ INT, REAL, - //STRING, + STRING, NIL, }; @@ -225,7 +225,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { static const Type valid[]={ BOOL, REAL, - //STRING, + STRING, NIL, }; @@ -237,7 +237,7 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { static const Type valid[]={ BOOL, INT, - //STRING, + STRING, NIL, }; @@ -258,12 +258,12 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { case MATRIX32: { - static const Type invalid[]={ + static const Type valid[]={ TRANSFORM, NIL }; - invalid_types=invalid; + valid_types=valid; } break; case QUAT: { @@ -299,6 +299,256 @@ bool Variant::can_convert(Variant::Type p_type_from,Variant::Type p_type_to) { } break; + case COLOR: { + + static const Type valid[] = { + //STRING, + //INT, + NIL, + }; + + valid_types = valid; + + } break; + + case _RID: { + + static const Type valid[]={ + OBJECT, + NIL + }; + + valid_types=valid; + } break; + case OBJECT: { + + static const Type valid[]={ + NIL + }; + + valid_types=valid; + } break; + case NODE_PATH: { + + static const Type valid[]={ + STRING, + NIL + }; + + valid_types=valid; + } break; + case ARRAY: { + + + static const Type valid[]={ + RAW_ARRAY, + INT_ARRAY, + STRING_ARRAY, + REAL_ARRAY, + COLOR_ARRAY, + VECTOR2_ARRAY, + VECTOR3_ARRAY, + NIL + }; + + valid_types=valid; + } break; + // arrays + case RAW_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + } break; + case INT_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + } break; + case REAL_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + } break; + case STRING_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + } break; + case VECTOR2_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + + } break; + case VECTOR3_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + valid_types=valid; + + } break; + case COLOR_ARRAY: { + + static const Type valid[]={ + ARRAY, + NIL + }; + + valid_types=valid; + + } break; + default: {} + } + + + if (valid_types) { + + int i=0; + while(valid_types[i]!=NIL) { + + if (p_type_from==valid_types[i]) + return true; + i++; + } + } else if (invalid_types) { + + + int i=0; + while(invalid_types[i]!=NIL) { + + if (p_type_from==invalid_types[i]) + return false; + i++; + } + } + + return false; + +} + +bool Variant::can_convert_strict(Variant::Type p_type_from,Variant::Type p_type_to) { + + if (p_type_from==p_type_to) + return true; + if (p_type_to==NIL && p_type_from!=NIL) //nil can convert to anything + return true; + + if (p_type_from == NIL) { + return (p_type_to == OBJECT); + }; + + const Type *valid_types=NULL; + const Type *invalid_types=NULL; + + switch(p_type_to) { + case BOOL: { + + static const Type valid[]={ + //INT, + //REAL, + //STRING, + NIL, + }; + + valid_types=valid; + } break; + case INT: { + + static const Type valid[]={ + //BOOL, + REAL, + //STRING, + NIL, + }; + + valid_types=valid; + + } break; + case REAL: { + + static const Type valid[]={ + //BOOL, + INT, + //STRING, + NIL, + }; + + valid_types=valid; + + } break; + case STRING: { + + + static const Type valid[]={ + NODE_PATH, + NIL + }; + + valid_types=valid; + } break; + case MATRIX32: { + + + static const Type valid[]={ + TRANSFORM, + NIL + }; + + valid_types=valid; + } break; + case QUAT: { + + static const Type valid[]={ + MATRIX3, + NIL + }; + + valid_types=valid; + + } break; + case MATRIX3: { + + static const Type valid[]={ + QUAT, + NIL + }; + + valid_types=valid; + + + } break; + case TRANSFORM: { + + static const Type valid[]={ + MATRIX32, + QUAT, + MATRIX3, + NIL + }; + + valid_types=valid; + + } break; + case COLOR: { static const Type valid[] = { diff --git a/core/variant.h b/core/variant.h index 85c7b92c0da..5f338ef667f 100644 --- a/core/variant.h +++ b/core/variant.h @@ -165,7 +165,8 @@ public: _FORCE_INLINE_ Type get_type() const { return type; } static String get_type_name(Variant::Type p_type); - static bool can_convert(Type p_type_from,Type p_type_to); + static bool can_convert(Type p_type_from, Type p_type_to); + static bool can_convert_strict(Type p_type_from, Type p_type_to); diff --git a/demos/2d/platformer/enemy.gd b/demos/2d/platformer/enemy.gd index b4e70477a80..a264cd0cffa 100644 --- a/demos/2d/platformer/enemy.gd +++ b/demos/2d/platformer/enemy.gd @@ -56,7 +56,7 @@ func _integrate_forces(s): state=STATE_DYING #lv=s.get_contact_local_normal(i)*400 s.set_angular_velocity(sign(dp.x)*33.0) - set_friction(true) + set_friction(1) cc.disable() get_node("sound").play("hit") diff --git a/demos/3d/platformer/enemy.gd b/demos/3d/platformer/enemy.gd index 1d0e0315d92..cbbb2fe725c 100644 --- a/demos/3d/platformer/enemy.gd +++ b/demos/3d/platformer/enemy.gd @@ -45,7 +45,7 @@ func _integrate_forces(state): state.set_angular_velocity( -dp.cross(up).normalized() *33.0) get_node("AnimationPlayer").play("impact") get_node("AnimationPlayer").queue("explode") - set_friction(true) + set_friction(1) cc.disabled=true get_node("sound").play("hit") return diff --git a/scene/main/node.h b/scene/main/node.h index aeada3c5bb8..4d0a84d3472 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -170,6 +170,7 @@ public: NOTIFICATION_PROCESS = 17, NOTIFICATION_PARENTED=18, NOTIFICATION_UNPARENTED=19, + NOTIFICATION_INSTANCED=20, }; /* NODE/TREE */ diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 9f36510739b..a1cb1205e5c 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -182,6 +182,8 @@ Node *PackedScene::instance(bool p_gen_edit_state) const { if (get_path()!="" && get_path().find("::")==-1) s->set_filename(get_path()); + + s->notification(Node::NOTIFICATION_INSTANCED); return ret_nodes[0]; }