Skip to content

Commit

Permalink
Fix some DEFVALs to use the right type
Browse files Browse the repository at this point in the history
- Use `StringName()` in DEFVAL for StringNames.
- Use `Variant()` in DEFVAL for Variants.
  • Loading branch information
raulsntos committed Feb 23, 2024
1 parent 16d6142 commit 5ba92e5
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 74 deletions.
40 changes: 40 additions & 0 deletions core/object/object.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**************************************************************************/
/* object.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

#include "core/object/class_db.h"

void Object::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(""));
}

#endif
6 changes: 4 additions & 2 deletions core/object/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "object.h"
#include "object.compat.inc"

#include "core/core_string_names.h"
#include "core/extension/gdextension_manager.h"
Expand Down Expand Up @@ -1472,6 +1473,7 @@ void Object::initialize_class() {
}
ClassDB::_add_class<Object>();
_bind_methods();
_bind_compatibility_methods();
initialized = true;
}

Expand Down Expand Up @@ -1647,8 +1649,8 @@ void Object::_bind_methods() {

ClassDB::bind_method(D_METHOD("set_message_translation", "enable"), &Object::set_message_translation);
ClassDB::bind_method(D_METHOD("can_translate_messages"), &Object::can_translate_messages);
ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(""));
ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(""));
ClassDB::bind_method(D_METHOD("tr", "message", "context"), &Object::tr, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("tr_n", "message", "plural_message", "n", "context"), &Object::tr_n, DEFVAL(StringName()));

ClassDB::bind_method(D_METHOD("is_queued_for_deletion"), &Object::is_queued_for_deletion);
ClassDB::bind_method(D_METHOD("cancel_free"), &Object::cancel_free);
Expand Down
4 changes: 4 additions & 0 deletions core/object/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,11 @@ class Object {
virtual void _notificationv(int p_notification, bool p_reversed) {}

static void _bind_methods();
#ifndef DISABLE_DEPRECATED
static void _bind_compatibility_methods();
#else
static void _bind_compatibility_methods() {}
#endif
bool _set(const StringName &p_name, const Variant &p_property) { return false; };
bool _get(const StringName &p_name, Variant &r_property) const { return false; };
void _get_property_list(List<PropertyInfo> *p_list) const {};
Expand Down
46 changes: 46 additions & 0 deletions core/string/translation.compat.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**************************************************************************/
/* translation.compat.inc */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef DISABLE_DEPRECATED

void Translation::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("add_message", "src_message", "xlated_message", "context"), &Translation::add_message, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("add_plural_message", "src_message", "xlated_messages", "context"), &Translation::add_plural_message, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_message", "src_message", "context"), &Translation::get_message, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("get_plural_message", "src_message", "src_plural_message", "n", "context"), &Translation::get_plural_message, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("erase_message", "src_message", "context"), &Translation::erase_message, DEFVAL(""));
}

void TranslationServer::_bind_compatibility_methods() {
ClassDB::bind_compatibility_method(D_METHOD("translate", "message", "context"), &TranslationServer::translate, DEFVAL(""));
ClassDB::bind_compatibility_method(D_METHOD("translate_plural", "message", "plural_message", "n", "context"), &TranslationServer::translate_plural, DEFVAL(""));
}

#endif
15 changes: 8 additions & 7 deletions core/string/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include "translation.h"
#include "translation.compat.inc"

#include "core/config/project_settings.h"
#include "core/io/resource_loader.h"
Expand Down Expand Up @@ -155,11 +156,11 @@ int Translation::get_message_count() const {
void Translation::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_locale", "locale"), &Translation::set_locale);
ClassDB::bind_method(D_METHOD("get_locale"), &Translation::get_locale);
ClassDB::bind_method(D_METHOD("add_message", "src_message", "xlated_message", "context"), &Translation::add_message, DEFVAL(""));
ClassDB::bind_method(D_METHOD("add_plural_message", "src_message", "xlated_messages", "context"), &Translation::add_plural_message, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_message", "src_message", "context"), &Translation::get_message, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_plural_message", "src_message", "src_plural_message", "n", "context"), &Translation::get_plural_message, DEFVAL(""));
ClassDB::bind_method(D_METHOD("erase_message", "src_message", "context"), &Translation::erase_message, DEFVAL(""));
ClassDB::bind_method(D_METHOD("add_message", "src_message", "xlated_message", "context"), &Translation::add_message, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("add_plural_message", "src_message", "xlated_messages", "context"), &Translation::add_plural_message, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("get_message", "src_message", "context"), &Translation::get_message, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("get_plural_message", "src_message", "src_plural_message", "n", "context"), &Translation::get_plural_message, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("erase_message", "src_message", "context"), &Translation::erase_message, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("get_message_list"), &Translation::_get_message_list);
ClassDB::bind_method(D_METHOD("get_translated_message_list"), &Translation::get_translated_message_list);
ClassDB::bind_method(D_METHOD("get_message_count"), &Translation::get_message_count);
Expand Down Expand Up @@ -1002,8 +1003,8 @@ void TranslationServer::_bind_methods() {

ClassDB::bind_method(D_METHOD("get_locale_name", "locale"), &TranslationServer::get_locale_name);

ClassDB::bind_method(D_METHOD("translate", "message", "context"), &TranslationServer::translate, DEFVAL(""));
ClassDB::bind_method(D_METHOD("translate_plural", "message", "plural_message", "n", "context"), &TranslationServer::translate_plural, DEFVAL(""));
ClassDB::bind_method(D_METHOD("translate", "message", "context"), &TranslationServer::translate, DEFVAL(StringName()));
ClassDB::bind_method(D_METHOD("translate_plural", "message", "plural_message", "n", "context"), &TranslationServer::translate_plural, DEFVAL(StringName()));

ClassDB::bind_method(D_METHOD("add_translation", "translation"), &TranslationServer::add_translation);
ClassDB::bind_method(D_METHOD("remove_translation", "translation"), &TranslationServer::remove_translation);
Expand Down
8 changes: 8 additions & 0 deletions core/string/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class Translation : public Resource {
protected:
static void _bind_methods();

#ifndef DISABLE_DEPRECATED
static void _bind_compatibility_methods();
#endif

GDVIRTUAL2RC(StringName, _get_message, StringName, StringName);
GDVIRTUAL4RC(StringName, _get_plural_message, StringName, StringName, int, StringName);

Expand Down Expand Up @@ -111,6 +115,10 @@ class TranslationServer : public Object {

static void _bind_methods();

#ifndef DISABLE_DEPRECATED
static void _bind_compatibility_methods();
#endif

struct LocaleScriptInfo {
String name;
String script;
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/AnimationPlayer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</method>
<method name="play">
<return type="void" />
<param index="0" name="name" type="StringName" default="&quot;&quot;" />
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
<param index="1" name="custom_blend" type="float" default="-1" />
<param index="2" name="custom_speed" type="float" default="1.0" />
<param index="3" name="from_end" type="bool" default="false" />
Expand All @@ -103,7 +103,7 @@
</method>
<method name="play_backwards">
<return type="void" />
<param index="0" name="name" type="StringName" default="&quot;&quot;" />
<param index="0" name="name" type="StringName" default="&amp;&quot;&quot;" />
<param index="1" name="custom_blend" type="float" default="-1" />
<description>
Plays the animation with key [param name] in reverse.
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/CodeEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<param index="2" name="insert_text" type="String" />
<param index="3" name="text_color" type="Color" default="Color(1, 1, 1, 1)" />
<param index="4" name="icon" type="Resource" default="null" />
<param index="5" name="value" type="Variant" default="0" />
<param index="5" name="value" type="Variant" default="null" />
<param index="6" name="location" type="int" default="1024" />
<description>
Submits an item to the queue of potential candidates for the autocomplete menu. Call [method update_code_completion_options] to update the list.
Expand Down
24 changes: 12 additions & 12 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@
<method name="get_theme_color" qualifiers="const">
<return type="Color" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns a [Color] from the first matching [Theme] in the tree if that [Theme] has a color item with the specified [param name] and [param theme_type]. If [param theme_type] is omitted the class name of the current control is used as the type, or [member theme_type_variation] if it is defined. If the type is a class name its parent classes are also checked, in order of inheritance. If the type is a variation its base types are checked, in order of dependency, then the control's class name and its parent classes are checked.
For the current control its local overrides are considered first (see [method add_theme_color_override]), then its assigned [member theme]. After the current control, each parent control and its assigned [member theme] are considered; controls without a [member theme] assigned are skipped. If no matching [Theme] is found in the tree, the custom project [Theme] (see [member ProjectSettings.gui/theme/custom]) and the default [Theme] are used (see [ThemeDB]).
Expand All @@ -484,7 +484,7 @@
<method name="get_theme_constant" qualifiers="const">
<return type="int" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns a constant from the first matching [Theme] in the tree if that [Theme] has a constant item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand Down Expand Up @@ -514,7 +514,7 @@
<method name="get_theme_font" qualifiers="const">
<return type="Font" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns a [Font] from the first matching [Theme] in the tree if that [Theme] has a font item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -523,7 +523,7 @@
<method name="get_theme_font_size" qualifiers="const">
<return type="int" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns a font size from the first matching [Theme] in the tree if that [Theme] has a font size item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -532,7 +532,7 @@
<method name="get_theme_icon" qualifiers="const">
<return type="Texture2D" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns an icon from the first matching [Theme] in the tree if that [Theme] has an icon item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -541,7 +541,7 @@
<method name="get_theme_stylebox" qualifiers="const">
<return type="StyleBox" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns a [StyleBox] from the first matching [Theme] in the tree if that [Theme] has a stylebox item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand Down Expand Up @@ -590,7 +590,7 @@
<method name="has_theme_color" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has a color item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -607,7 +607,7 @@
<method name="has_theme_constant" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has a constant item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -624,7 +624,7 @@
<method name="has_theme_font" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has a font item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -641,7 +641,7 @@
<method name="has_theme_font_size" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has a font size item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -658,7 +658,7 @@
<method name="has_theme_icon" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has an icon item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand All @@ -675,7 +675,7 @@
<method name="has_theme_stylebox" qualifiers="const">
<return type="bool" />
<param index="0" name="name" type="StringName" />
<param index="1" name="theme_type" type="StringName" default="&quot;&quot;" />
<param index="1" name="theme_type" type="StringName" default="&amp;&quot;&quot;" />
<description>
Returns [code]true[/code] if there is a matching [Theme] in the tree that has a stylebox item with the specified [param name] and [param theme_type].
See [method get_theme_color] for details.
Expand Down
Loading

0 comments on commit 5ba92e5

Please sign in to comment.