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

Write Object variants with '\n' between properties #92102

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

robert-wallis
Copy link
Contributor

@robert-wallis robert-wallis commented May 19, 2024

Adds line feeds '\n' after commas for each property in an Object.

This mirroring the format for Dictionary variants in core/variant/variant_parser.cpp lines 2054-2066

Before

before diff

After

after diff

This makes reading the diff easier. It will likely help auto-merge conflicts when a different properties in an Object are changed at the same time.

Proposal

@robert-wallis
Copy link
Contributor Author

Old ui_accept Example

project.godot

ui_accept={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194309,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194310,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":0,"pressure":0.0,"pressed":false,"script":null)
]
}

New ui_accept Example

project.godot

ui_accept={
"deadzone": 0.5,
"events": [Object(
InputEventKey,
"resource_local_to_scene":false,
"resource_name":"",
"device":0,
"window_id":0,
"alt_pressed":false,
"shift_pressed":false,
"ctrl_pressed":false,
"meta_pressed":false,
"pressed":false,
"keycode":4194309,
"physical_keycode":0,
"key_label":0,
"unicode":0,
"location":0,
"echo":false,
"script":null
), Object(
InputEventKey,
"resource_local_to_scene":false,
"resource_name":"",
"device":0,
"window_id":0,
"alt_pressed":false,
"shift_pressed":false,
"ctrl_pressed":false,
"meta_pressed":false,
"pressed":false,
"keycode":4194310,
"physical_keycode":0,
"key_label":0,
"unicode":0,
"location":0,
"echo":false,
"script":null
), Object(
InputEventKey,
"resource_local_to_scene":false,
"resource_name":"",
"device":0,
"window_id":0,
"alt_pressed":false,
"shift_pressed":false,
"ctrl_pressed":false,
"meta_pressed":false,
"pressed":false,
"keycode":32,
"physical_keycode":0,
"key_label":0,
"unicode":32,
"location":0,
"echo":false,
"script":null
), Object(
InputEventJoypadButton,
"resource_local_to_scene":false,
"resource_name":"",
"device":-1,
"button_index":0,
"pressure":0.0,
"pressed":false,
"script":null
)]
}

@AThousandShips
Copy link
Member

You need to change this part of the GDScript tests to compensate for the new newlines:

diff --git a/modules/gdscript/tests/scripts/runtime/features/metatypes.gd b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd
index 6c5df32ffe..8a57127271 100644
--- a/modules/gdscript/tests/scripts/runtime/features/metatypes.gd
+++ b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd
@@ -12,7 +12,7 @@ var test_class := MyClass
 var test_enum := MyEnum

 func check_gdscript_native_class(value: Variant) -> void:
-       print(var_to_str(value).get_slice(",", 0).trim_prefix("Object("))
+       print(var_to_str(value).get_slice(",", 0).trim_prefix("Object(\n"))

 func check_gdscript(value: GDScript) -> void:
        print(value.get_class())

@Calinou
Copy link
Member

Calinou commented May 21, 2024

This would also be a good opportunity to add a space between the key and value (i.e. add a space after :). This should further improve readability.

@robert-wallis
Copy link
Contributor Author

This would also be a good opportunity to add a space between the key and value (i.e. add a space after :).

Also it matches how Dictionary serializes.

✅ Done :)

@robert-wallis
Copy link
Contributor Author

Example serialized object with spaces after :

Object(
InputEventKey,
"resource_local_to_scene": false,
"resource_name": "",
"device": 0,
"window_id": 0,
"alt_pressed": false,
"shift_pressed": false,
"ctrl_pressed": false,
"meta_pressed": false,
"pressed": false,
"keycode": 4194309,
"physical_keycode": 0,
"key_label": 0,
"unicode": 0,
"location": 0,
"echo": false,
"script": null
)

robert-wallis added a commit to robert-wallis/godot-object-lf-git that referenced this pull request May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Object text-based serialization more readable and VCS-friendly
4 participants