Skip to content

Commit 1bbfe63

Browse files
committed
Merge pull request #107357 from ProgrammerOnCoffee/fix-dictionary-style
Enforce GDScript and C# dictionary spacing style guidelines in code samples
2 parents fda6fae + 11af23a commit 1bbfe63

File tree

6 files changed

+39
-39
lines changed

6 files changed

+39
-39
lines changed

doc/classes/Callable.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
[/codeblock]
5454
[b]Note:[/b] [Dictionary] does not support the above due to ambiguity with keys.
5555
[codeblock]
56-
var dictionary = {"hello": "world"}
56+
var dictionary = { "hello": "world" }
5757

5858
# This will not work, `clear` is treated as a key.
5959
tween.tween_callback(dictionary.clear)

doc/classes/Dictionary.xml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
dict_variable_key: dict_variable_value,
1919
}
2020

21-
var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
21+
var points_dict = { "White": 50, "Yellow": 75, "Orange": 100 }
2222

2323
# Alternative Lua-style syntax.
2424
# Doesn't require quotes around keys, but only string constants can be used as key names.
@@ -32,17 +32,17 @@
3232
var myDict = new Godot.Collections.Dictionary(); // Creates an empty dictionary.
3333
var pointsDict = new Godot.Collections.Dictionary
3434
{
35-
{"White", 50},
36-
{"Yellow", 75},
37-
{"Orange", 100}
35+
{ "White", 50 },
36+
{ "Yellow", 75 },
37+
{ "Orange", 100 },
3838
};
3939
[/csharp]
4040
[/codeblocks]
4141
You can access a dictionary's value by referencing its corresponding key. In the above example, [code]points_dict["White"][/code] will return [code]50[/code]. You can also write [code]points_dict.White[/code], which is equivalent. However, you'll have to use the bracket syntax if the key you're accessing the dictionary with isn't a fixed string (such as a number or variable).
4242
[codeblocks]
4343
[gdscript]
4444
@export_enum("White", "Yellow", "Orange") var my_color: String
45-
var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
45+
var points_dict = { "White": 50, "Yellow": 75, "Orange": 100 }
4646
func _ready():
4747
# We can't use dot syntax here as `my_color` is a variable.
4848
var points = points_dict[my_color]
@@ -52,9 +52,9 @@
5252
public string MyColor { get; set; }
5353
private Godot.Collections.Dictionary _pointsDict = new Godot.Collections.Dictionary
5454
{
55-
{"White", 50},
56-
{"Yellow", 75},
57-
{"Orange", 100}
55+
{ "White", 50 },
56+
{ "Yellow", 75 },
57+
{ "Orange", 100 },
5858
};
5959

6060
public override void _Ready()
@@ -74,22 +74,22 @@
7474
[csharp]
7575
var myDict = new Godot.Collections.Dictionary
7676
{
77-
{"First Array", new Godot.Collections.Array{1, 2, 3, 4}}
77+
{ "First Array", new Godot.Collections.Array { 1, 2, 3, 4 } }
7878
};
7979
[/csharp]
8080
[/codeblocks]
8181
To add a key to an existing dictionary, access it like an existing key and assign to it:
8282
[codeblocks]
8383
[gdscript]
84-
var points_dict = {"White": 50, "Yellow": 75, "Orange": 100}
84+
var points_dict = { "White": 50, "Yellow": 75, "Orange": 100 }
8585
points_dict["Blue"] = 150 # Add "Blue" as a key and assign 150 as its value.
8686
[/gdscript]
8787
[csharp]
8888
var pointsDict = new Godot.Collections.Dictionary
8989
{
90-
{"White", 50},
91-
{"Yellow", 75},
92-
{"Orange", 100}
90+
{ "White", 50 },
91+
{ "Yellow", 75 },
92+
{ "Orange", 100 },
9393
};
9494
pointsDict["Blue"] = 150; // Add "Blue" as a key and assign 150 as its value.
9595
[/csharp]
@@ -104,29 +104,29 @@
104104
"String Key": 5,
105105
4: [1, 2, 3],
106106
7: "Hello",
107-
"sub_dict": {"sub_key": "Nested value"},
107+
"sub_dict": { "sub_key": "Nested value" },
108108
}
109109
[/gdscript]
110110
[csharp]
111111
// This is a valid dictionary.
112112
// To access the string "Nested value" below, use `((Godot.Collections.Dictionary)myDict["sub_dict"])["sub_key"]`.
113113
var myDict = new Godot.Collections.Dictionary {
114-
{"String Key", 5},
115-
{4, new Godot.Collections.Array{1,2,3}},
116-
{7, "Hello"},
117-
{"sub_dict", new Godot.Collections.Dictionary{{"sub_key", "Nested value"}}}
114+
{ "String Key", 5 },
115+
{ 4, new Godot.Collections.Array { 1, 2, 3 } },
116+
{ 7, "Hello" },
117+
{ "sub_dict", new Godot.Collections.Dictionary { { "sub_key", "Nested value" } } },
118118
};
119119
[/csharp]
120120
[/codeblocks]
121121
The keys of a dictionary can be iterated with the [code]for[/code] keyword:
122122
[codeblocks]
123123
[gdscript]
124-
var groceries = {"Orange": 20, "Apple": 2, "Banana": 4}
124+
var groceries = { "Orange": 20, "Apple": 2, "Banana": 4 }
125125
for fruit in groceries:
126126
var amount = groceries[fruit]
127127
[/gdscript]
128128
[csharp]
129-
var groceries = new Godot.Collections.Dictionary{{"Orange", 20}, {"Apple", 2}, {"Banana", 4}};
129+
var groceries = new Godot.Collections.Dictionary { { "Orange", 20 }, { "Apple", 2 }, { "Banana", 4 } };
130130
foreach (var (fruit, amount) in groceries)
131131
{
132132
// `fruit` is the key, `amount` is the value.
@@ -298,7 +298,7 @@
298298
[/codeblocks]
299299
In GDScript, this is equivalent to the [code]in[/code] operator:
300300
[codeblock]
301-
if "Godot" in {"Godot": 4}:
301+
if "Godot" in { "Godot": 4 }:
302302
print("The key is here!") # Will be printed.
303303
[/codeblock]
304304
[b]Note:[/b] This method returns [code]true[/code] as long as the [param key] exists, even if its corresponding value is [code]null[/code].
@@ -310,7 +310,7 @@
310310
<description>
311311
Returns [code]true[/code] if the dictionary contains all keys in the given [param keys] array.
312312
[codeblock]
313-
var data = {"width" : 10, "height" : 20}
313+
var data = { "width": 10, "height": 20 }
314314
data.has_all(["height", "width"]) # Returns true
315315
[/codeblock]
316316
</description>
@@ -321,14 +321,14 @@
321321
Returns a hashed 32-bit integer value representing the dictionary contents.
322322
[codeblocks]
323323
[gdscript]
324-
var dict1 = {"A": 10, "B": 2}
325-
var dict2 = {"A": 10, "B": 2}
324+
var dict1 = { "A": 10, "B": 2 }
325+
var dict2 = { "A": 10, "B": 2 }
326326

327327
print(dict1.hash() == dict2.hash()) # Prints true
328328
[/gdscript]
329329
[csharp]
330-
var dict1 = new Godot.Collections.Dictionary{{"A", 10}, {"B", 2}};
331-
var dict2 = new Godot.Collections.Dictionary{{"A", 10}, {"B", 2}};
330+
var dict1 = new Godot.Collections.Dictionary { { "A", 10 }, { "B", 2 } };
331+
var dict2 = new Godot.Collections.Dictionary { { "A", 10 }, { "B", 2 } };
332332

333333
// Godot.Collections.Dictionary has no Hash() method. Use GD.Hash() instead.
334334
GD.Print(GD.Hash(dict1) == GD.Hash(dict2)); // Prints True

doc/classes/EditorPlugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@
272272
[b]Note:[/b] You must implement [method _get_plugin_name] for the state to be stored and restored correctly.
273273
[codeblock]
274274
func _get_state():
275-
var state = {"zoom": zoom, "preferred_color": my_color}
275+
var state = { "zoom": zoom, "preferred_color": my_color }
276276
return state
277277
[/codeblock]
278278
</description>

doc/classes/EditorSettings.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@
5858

5959
var propertyInfo = new Godot.Collections.Dictionary
6060
{
61-
{"name", "category/propertyName"},
62-
{"type", Variant.Type.Int},
63-
{"hint", PropertyHint.Enum},
64-
{"hint_string", "one,two,three"}
61+
{ "name", "category/propertyName" },
62+
{ "type", Variant.Type.Int },
63+
{ "hint", PropertyHint.Enum },
64+
{ "hint_string", "one,two,three" },
6565
};
6666

6767
settings.AddPropertyInfo(propertyInfo);

doc/classes/HTTPClient.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
Generates a GET/POST application/x-www-form-urlencoded style query string from a provided dictionary, e.g.:
100100
[codeblocks]
101101
[gdscript]
102-
var fields = {"username": "user", "password": "pass"}
102+
var fields = { "username": "user", "password": "pass" }
103103
var query_string = http_client.query_string_from_dict(fields)
104104
# Returns "username=user&amp;password=pass"
105105
[/gdscript]
@@ -112,7 +112,7 @@
112112
Furthermore, if a key has a [code]null[/code] value, only the key itself is added, without equal sign and value. If the value is an array, for each value in it a pair with the same key is added.
113113
[codeblocks]
114114
[gdscript]
115-
var fields = {"single": 123, "not_valued": null, "multiple": [22, 33, 44]}
115+
var fields = { "single": 123, "not_valued": null, "multiple": [22, 33, 44] }
116116
var query_string = http_client.query_string_from_dict(fields)
117117
# Returns "single=123&amp;not_valued&amp;multiple=22&amp;multiple=33&amp;multiple=44"
118118
[/gdscript]
@@ -148,7 +148,7 @@
148148
To create a POST request with query strings to push to the server, do:
149149
[codeblocks]
150150
[gdscript]
151-
var fields = {"username" : "user", "password" : "pass"}
151+
var fields = { "username": "user", "password": "pass" }
152152
var query_string = http_client.query_string_from_dict(fields)
153153
var headers = ["Content-Type: application/x-www-form-urlencoded", "Content-Length: " + str(query_string.length())]
154154
var result = http_client.request(http_client.METHOD_POST, "/index.php", headers, query_string)

doc/classes/ProjectSettings.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242

4343
var propertyInfo = new Godot.Collections.Dictionary
4444
{
45-
{"name", "category/propertyName"},
46-
{"type", (int)Variant.Type.Int},
47-
{"hint", (int)PropertyHint.Enum},
48-
{"hint_string", "one,two,three"},
45+
{ "name", "category/propertyName" },
46+
{ "type", (int)Variant.Type.Int },
47+
{ "hint", (int)PropertyHint.Enum },
48+
{ "hint_string", "one,two,three" },
4949
};
5050

5151
ProjectSettings.AddPropertyInfo(propertyInfo);

0 commit comments

Comments
 (0)