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

GDScript: Deprecate inst_to_dict() and dict_to_inst() functions #99121

Merged
merged 1 commit into from
Jan 6, 2025
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
7 changes: 4 additions & 3 deletions modules/gdscript/doc_classes/@GDScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
[/codeblock]
</description>
</method>
<method name="dict_to_inst">
<method name="dict_to_inst" deprecated="Consider using [method JSON.to_native] or [method Object.get_property_list] instead.">
<return type="Object" />
<param index="0" name="dictionary" type="Dictionary" />
<description>
Expand Down Expand Up @@ -103,12 +103,11 @@
[b]Note:[/b] Calling this function from a [Thread] is not supported. Doing so will return an empty array.
</description>
</method>
<method name="inst_to_dict">
<method name="inst_to_dict" deprecated="Consider using [method JSON.from_native] or [method Object.get_property_list] instead.">
<return type="Dictionary" />
<param index="0" name="instance" type="Object" />
<description>
Returns the passed [param instance] converted to a Dictionary. Can be useful for serializing.
[b]Note:[/b] Cannot be used to serialize objects with built-in scripts attached or objects allocated within built-in scripts.
[codeblock]
var foo = "bar"
func _ready():
Expand All @@ -121,6 +120,8 @@
[@subpath, @path, foo]
[, res://test.gd, bar]
[/codeblock]
[b]Note:[/b] This function can only be used to serialize objects with an attached [GDScript] stored in a separate file. Objects without an attached script, with a script written in another language, or with a built-in script are not supported.
[b]Note:[/b] This function is not recursive, which means that nested objects will not be represented as dictionaries. Also, properties passed by reference ([Object], [Dictionary], [Array], and packed arrays) are copied by reference, not duplicated.
</description>
</method>
<method name="is_instance_of">
Expand Down
6 changes: 4 additions & 2 deletions modules/gdscript/gdscript_utility_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ struct GDScriptUtilityFunctionsDefinitions {
*r_ret = ResourceLoader::load(*p_args[0]);
}

#ifndef DISABLE_DEPRECATED

static inline void inst_to_dict(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
DEBUG_VALIDATE_ARG_COUNT(1, 1);
DEBUG_VALIDATE_ARG_TYPE(0, Variant::OBJECT);
Expand Down Expand Up @@ -315,7 +317,6 @@ struct GDScriptUtilityFunctionsDefinitions {
}
}

#ifndef DISABLE_DEPRECATED
static inline void Color8(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
DEBUG_VALIDATE_ARG_COUNT(3, 4);
DEBUG_VALIDATE_ARG_TYPE(0, Variant::INT);
Expand All @@ -330,6 +331,7 @@ struct GDScriptUtilityFunctionsDefinitions {

*r_ret = Color::from_rgba8(*p_args[0], *p_args[1], *p_args[2], alpha);
}

#endif // DISABLE_DEPRECATED

static inline void print_debug(Variant *r_ret, const Variant **p_args, int p_arg_count, Callable::CallError &r_error) {
Expand Down Expand Up @@ -576,9 +578,9 @@ void GDScriptUtilityFunctions::register_functions() {
REGISTER_FUNC( _char, true, RET(STRING), ARGS( ARG("char", INT) ), false, varray( ));
REGISTER_FUNC( range, false, RET(ARRAY), NOARGS, true, varray( ));
REGISTER_FUNC( load, false, RETCLS("Resource"), ARGS( ARG("path", STRING) ), false, varray( ));
#ifndef DISABLE_DEPRECATED
REGISTER_FUNC( inst_to_dict, false, RET(DICTIONARY), ARGS( ARG("instance", OBJECT) ), false, varray( ));
REGISTER_FUNC( dict_to_inst, false, RET(OBJECT), ARGS( ARG("dictionary", DICTIONARY) ), false, varray( ));
#ifndef DISABLE_DEPRECATED
REGISTER_FUNC( Color8, true, RET(COLOR), ARGS( ARG("r8", INT), ARG("g8", INT),
ARG("b8", INT), ARG("a8", INT) ), false, varray( 255 ));
#endif // DISABLE_DEPRECATED
Expand Down