Skip to content

Commit

Permalink
Merge branch 'godotengine:3.x' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicMastr authored Oct 17, 2024
2 parents 13a1360 + 3841d76 commit 5191fcb
Show file tree
Hide file tree
Showing 18 changed files with 173 additions and 30 deletions.
4 changes: 4 additions & 0 deletions core/dictionary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Variant Dictionary::get_or_add(const Variant &p_key, const Variant &p_default) {
return *result;
}

void Dictionary::set(const Variant &p_key, const Variant &p_value) {
operator[](p_key) = p_value;
}

int Dictionary::size() const {
return _p->variant_map.size();
}
Expand Down
1 change: 1 addition & 0 deletions core/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class Dictionary {
Variant get_valid(const Variant &p_key) const;
Variant get(const Variant &p_key, const Variant &p_default) const;
Variant get_or_add(const Variant &p_key, const Variant &p_default);
void set(const Variant &p_key, const Variant &p_value);

int size() const;
bool empty() const;
Expand Down
80 changes: 50 additions & 30 deletions core/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ void TranslationServer::init_locale_info() {
}

String TranslationServer::standardize_locale(const String &p_locale) const {
return _standardize_locale(p_locale, false);
}

String TranslationServer::_standardize_locale(const String &p_locale, bool p_add_defaults) const {
// Replaces '-' with '_' for macOS style locales.
String univ_locale = p_locale.replace("-", "_");

Expand Down Expand Up @@ -322,24 +326,26 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
}

// Add script code base on language and country codes for some ambiguous cases.
if (script.empty()) {
for (int i = 0; i < locale_script_info.size(); i++) {
const LocaleScriptInfo &info = locale_script_info[i];
if (info.name == lang) {
if (country.empty() || info.supported_countries.has(country)) {
script = info.script;
break;
if (p_add_defaults) {
if (script.empty()) {
for (int i = 0; i < locale_script_info.size(); i++) {
const LocaleScriptInfo &info = locale_script_info[i];
if (info.name == lang) {
if (country.empty() || info.supported_countries.has(country)) {
script = info.script;
break;
}
}
}
}
}
if (!script.empty() && country.empty()) {
// Add conntry code based on script for some ambiguous cases.
for (int i = 0; i < locale_script_info.size(); i++) {
const LocaleScriptInfo &info = locale_script_info[i];
if (info.name == lang && info.script == script) {
country = info.default_country;
break;
if (!script.empty() && country.empty()) {
// Add conntry code based on script for some ambiguous cases.
for (int i = 0; i < locale_script_info.size(); i++) {
const LocaleScriptInfo &info = locale_script_info[i];
if (info.name == lang && info.script == script) {
country = info.default_country;
break;
}
}
}
}
Expand All @@ -359,32 +365,46 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
}

int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const {
String locale_a = standardize_locale(p_locale_a);
String locale_b = standardize_locale(p_locale_b);
if (p_locale_a == p_locale_b) {
// Exact match.
return 10;
}

const String cache_key = p_locale_a + "|" + p_locale_b;
const int *cached_result = locale_compare_cache.getptr(cache_key);
if (cached_result) {
return *cached_result;
}

String locale_a = _standardize_locale(p_locale_a, true);
String locale_b = _standardize_locale(p_locale_b, true);

if (locale_a == locale_b) {
// Exact match.
locale_compare_cache.set(cache_key, 10);
return 10;
}

Vector<String> locale_a_elements = locale_a.split("_");
Vector<String> locale_b_elements = locale_b.split("_");
if (locale_a_elements[0] == locale_b_elements[0]) {
// Matching language, both locales have extra parts.
// Return number of matching elements.
int matching_elements = 1;
for (int i = 1; i < locale_a_elements.size(); i++) {
for (int j = 1; j < locale_b_elements.size(); j++) {
if (locale_a_elements[i] == locale_b_elements[j]) {
matching_elements++;
}
}
}
return matching_elements;
} else {
if (locale_a_elements[0] != locale_b_elements[0]) {
// No match.
locale_compare_cache.set(cache_key, 0);
return 0;
}

// Matching language, both locales have extra parts.
// Return number of matching elements.
int matching_elements = 1;
for (int i = 1; i < locale_a_elements.size(); i++) {
for (int j = 1; j < locale_b_elements.size(); j++) {
if (locale_a_elements[i] == locale_b_elements[j]) {
matching_elements++;
}
}
}
locale_compare_cache.set(cache_key, matching_elements);
return matching_elements;
}

String TranslationServer::get_locale_name(const String &p_locale) const {
Expand Down
3 changes: 3 additions & 0 deletions core/translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class TranslationServer : public Object {
Ref<Translation> tool_translation;
Ref<Translation> doc_translation;

mutable HashMap<String, int> locale_compare_cache;

bool enabled;

static TranslationServer *singleton;
Expand Down Expand Up @@ -122,6 +124,7 @@ class TranslationServer : public Object {

int compare_locales(const String &p_locale_a, const String &p_locale_b) const;
String standardize_locale(const String &p_locale) const;
String _standardize_locale(const String &p_locale, bool p_add_defaults) const;

Vector<String> get_all_languages() const;
String get_language_name(const String &p_language) const;
Expand Down
11 changes: 11 additions & 0 deletions core/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Dictionary, duplicate);
VCALL_LOCALMEM2R(Dictionary, get);
VCALL_LOCALMEM2R(Dictionary, get_or_add);
VCALL_LOCALMEM2(Dictionary, set);

VCALL_LOCALMEM2(Array, set);
VCALL_LOCALMEM1R(Array, get);
Expand Down Expand Up @@ -1990,6 +1991,7 @@ void register_variant_methods() {
ADDFUNC0R(DICTIONARY, BOOL, Dictionary, empty, varray());
ADDFUNC0NC(DICTIONARY, NIL, Dictionary, clear, varray());
ADDFUNC2NC(DICTIONARY, NIL, Dictionary, merge, DICTIONARY, "dictionary", BOOL, "overwrite", varray(false));
ADDFUNC2NC(DICTIONARY, NIL, Dictionary, set, NIL, "key", NIL, "value", varray());
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has, NIL, "key", varray());
ADDFUNC1R(DICTIONARY, BOOL, Dictionary, has_all, ARRAY, "keys", varray());
ADDFUNC1R(DICTIONARY, NIL, Dictionary, find_key, NIL, "value", varray());
Expand All @@ -2005,6 +2007,8 @@ void register_variant_methods() {
ADDFUNC0R(ARRAY, BOOL, Array, empty, varray());
ADDFUNC0NC(ARRAY, NIL, Array, clear, varray());
ADDFUNC0R(ARRAY, INT, Array, hash, varray());
ADDFUNC1R(ARRAY, NIL, Array, get, INT, "index", varray());
ADDFUNC2NC(ARRAY, NIL, Array, set, INT, "index", NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, push_back, NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, push_front, NIL, "value", varray());
ADDFUNC1NC(ARRAY, NIL, Array, fill, NIL, "value", varray());
Expand Down Expand Up @@ -2038,6 +2042,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_BYTE_ARRAY, INT, PoolByteArray, size, varray());
ADDFUNC0R(POOL_BYTE_ARRAY, BOOL, PoolByteArray, empty, varray());
ADDFUNC1R(POOL_BYTE_ARRAY, INT, PoolByteArray, get, INT, "index", varray());
ADDFUNC2(POOL_BYTE_ARRAY, NIL, PoolByteArray, set, INT, "idx", INT, "byte", varray());
ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, push_back, INT, "byte", varray());
ADDFUNC1(POOL_BYTE_ARRAY, NIL, PoolByteArray, fill, INT, "byte", varray());
Expand All @@ -2064,6 +2069,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_INT_ARRAY, INT, PoolIntArray, size, varray());
ADDFUNC0R(POOL_INT_ARRAY, BOOL, PoolIntArray, empty, varray());
ADDFUNC1R(POOL_INT_ARRAY, INT, PoolIntArray, get, INT, "index", varray());
ADDFUNC2(POOL_INT_ARRAY, NIL, PoolIntArray, set, INT, "idx", INT, "integer", varray());
ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, push_back, INT, "integer", varray());
ADDFUNC1(POOL_INT_ARRAY, NIL, PoolIntArray, fill, INT, "integer", varray());
Expand All @@ -2082,6 +2088,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_REAL_ARRAY, INT, PoolRealArray, size, varray());
ADDFUNC0R(POOL_REAL_ARRAY, BOOL, PoolRealArray, empty, varray());
ADDFUNC1R(POOL_REAL_ARRAY, REAL, PoolRealArray, get, INT, "index", varray());
ADDFUNC2(POOL_REAL_ARRAY, NIL, PoolRealArray, set, INT, "idx", REAL, "value", varray());
ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, push_back, REAL, "value", varray());
ADDFUNC1(POOL_REAL_ARRAY, NIL, PoolRealArray, fill, REAL, "value", varray());
Expand All @@ -2100,6 +2107,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_STRING_ARRAY, INT, PoolStringArray, size, varray());
ADDFUNC0R(POOL_STRING_ARRAY, BOOL, PoolStringArray, empty, varray());
ADDFUNC1R(POOL_STRING_ARRAY, STRING, PoolStringArray, get, INT, "index", varray());
ADDFUNC2(POOL_STRING_ARRAY, NIL, PoolStringArray, set, INT, "idx", STRING, "string", varray());
ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, push_back, STRING, "string", varray());
ADDFUNC1(POOL_STRING_ARRAY, NIL, PoolStringArray, fill, STRING, "string", varray());
Expand All @@ -2119,6 +2127,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, size, varray());
ADDFUNC0R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, empty, varray());
ADDFUNC1R(POOL_VECTOR2_ARRAY, VECTOR2, PoolVector2Array, get, INT, "index", varray());
ADDFUNC2(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, set, INT, "idx", VECTOR2, "vector2", varray());
ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, push_back, VECTOR2, "vector2", varray());
ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, fill, VECTOR2, "vector2", varray());
Expand All @@ -2137,6 +2146,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, size, varray());
ADDFUNC0R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, empty, varray());
ADDFUNC1R(POOL_VECTOR3_ARRAY, VECTOR3, PoolVector3Array, get, INT, "index", varray());
ADDFUNC2(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, set, INT, "idx", VECTOR3, "vector3", varray());
ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, push_back, VECTOR3, "vector3", varray());
ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, fill, VECTOR3, "vector3", varray());
Expand All @@ -2155,6 +2165,7 @@ void register_variant_methods() {

ADDFUNC0R(POOL_COLOR_ARRAY, INT, PoolColorArray, size, varray());
ADDFUNC0R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, empty, varray());
ADDFUNC1R(POOL_COLOR_ARRAY, COLOR, PoolColorArray, get, INT, "index", varray());
ADDFUNC2(POOL_COLOR_ARRAY, NIL, PoolColorArray, set, INT, "idx", COLOR, "color", varray());
ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, push_back, COLOR, "color", varray());
ADDFUNC1(POOL_COLOR_ARRAY, NIL, PoolColorArray, fill, COLOR, "color", varray());
Expand Down
14 changes: 14 additions & 0 deletions doc/classes/Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,13 @@
[b]Note:[/b] Calling this function is not the same as writing [code]array[0][/code]. If the array is empty, accessing by index will pause project execution when running from the editor.
</description>
</method>
<method name="get">
<return type="Variant" />
<argument index="0" name="index" type="int" />
<description>
Returns the element at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="Variant" />
Expand Down Expand Up @@ -329,6 +336,13 @@
Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array. If the adjusted start index is out of bounds, this method searches from the end of the array.
</description>
</method>
<method name="set">
<argument index="0" name="index" type="int" />
<argument index="1" name="value" type="Variant" />
<description>
Sets the value of the element at the given [code]index[/code] to the given [code]value[/code]. This will not change the size of the array, it only changes the value at an index already in the array. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]).
</description>
</method>
<method name="shuffle">
<description>
Shuffles the array such that the items will have a random order. This method uses the global random number generator common to methods such as [method @GDScript.randi]. Call [method @GDScript.randomize] to ensure that a new seed will be used each time if you want non-reproducible shuffling.
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/Dictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@
Adds elements from [code]dictionary[/code] to this [Dictionary]. By default, duplicate keys will not be copied over, unless [code]overwrite[/code] is [code]true[/code].
</description>
</method>
<method name="set">
<argument index="0" name="key" type="Variant" />
<argument index="1" name="value" type="Variant" />
<description>
Sets the value of the element at the given [code]key[/code] to the given [code]value[/code]. This is the same as using the [code][][/code] operator ([code]array[index] = value[/code]).
</description>
</method>
<method name="size">
<return type="int" />
<description>
Expand Down
2 changes: 2 additions & 0 deletions doc/classes/Input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
If [code]exact[/code] is [code]false[/code], it ignores additional input modifiers for [InputEventKey] and [InputEventMouseButton] events, and the direction for [InputEventJoypadMotion] events.
[b]Note:[/b] Returning [code]true[/code] does not imply that the action is [i]still[/i] pressed. An action can be pressed and released again rapidly, and [code]true[/code] will still be returned so as not to miss input.
[b]Note:[/b] Due to keyboard ghosting, [method is_action_just_pressed] may return [code]false[/code] even if one of the action's keys is pressed. See [url=$DOCS_URL/tutorials/inputs/input_examples.html#keyboard-events]Input examples[/url] in the documentation for more information.
[b]Note:[/b] During input handling (e.g. [method Node._input]), use [method InputEvent.is_action_pressed] instead to query the action state of the current event.
</description>
</method>
<method name="is_action_just_released" qualifiers="const">
Expand All @@ -221,6 +222,7 @@
Returns [code]true[/code] when the user [i]stops[/i] pressing the action event in the current frame or physics tick. It will only return [code]true[/code] on the frame or tick that the user releases the button.
If [code]exact[/code] is [code]false[/code], it ignores additional input modifiers for [InputEventKey] and [InputEventMouseButton] events, and the direction for [InputEventJoypadMotion] events.
[b]Note:[/b] Returning [code]true[/code] does not imply that the action is [i]still[/i] not pressed. An action can be released and pressed again rapidly, and [code]true[/code] will still be returned so as not to miss input.
[b]Note:[/b] During input handling (e.g. [method Node._input]), use [method InputEvent.is_action_released] instead to query the action state of the current event.
</description>
</method>
<method name="is_action_pressed" qualifiers="const">
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolByteArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="int" />
<argument index="0" name="index" type="int" />
<description>
Returns the byte at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="get_string_from_ascii">
<return type="String" />
<description>
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolColorArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="Color" />
<argument index="0" name="index" type="int" />
<description>
Returns the Color at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="Color" />
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolIntArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="int" />
<argument index="0" name="index" type="int" />
<description>
Returns the integer at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="int" />
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolRealArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="float" />
<argument index="0" name="index" type="int" />
<description>
Returns the float at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="float" />
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolStringArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="String" />
<argument index="0" name="index" type="int" />
<description>
Returns the String at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="String" />
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolVector2Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="Vector2" />
<argument index="0" name="index" type="int" />
<description>
Returns the Vector2 at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="Vector2" />
Expand Down
7 changes: 7 additions & 0 deletions doc/classes/PoolVector3Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@
Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. Returns [code]-1[/code] if [code]from[/code] is out of bounds.
</description>
</method>
<method name="get">
<return type="Vector3" />
<argument index="0" name="index" type="int" />
<description>
Returns the Vector3 at the given [code]index[/code] in the array. This is the same as using the [code][][/code] operator ([code]array[index][/code]).
</description>
</method>
<method name="has">
<return type="bool" />
<argument index="0" name="value" type="Vector3" />
Expand Down
Loading

0 comments on commit 5191fcb

Please sign in to comment.