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

Added object support to Godot exporter #3615

Merged
merged 7 commits into from
Feb 21, 2024
Merged

Conversation

Skrapion
Copy link
Contributor

@Skrapion Skrapion commented Mar 12, 2023

Now supporting objects in the Godot 4 exporter initially added in pull #3550.

Video showing it off here: https://www.youtube.com/watch?v=3UfOOdepDDw

Copy link
Member

@bjorn bjorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for continuing work on this plugin!

I've left a number of comments.

src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
}

QString baseName = sanitizeSpecialChars(match.captured(1));
int uniqueifier = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the object ID should always be unique for a given map, would it make sense to use it instead of an incremental uniqueifier?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID should be unique per res path, not per object. I've updated the comments to reflect that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. But in that case, this whole thing seems to be only a bit complicated due to the use of the base name derived from the path. Couldn't we just give these ext_resource entries unique IDs like "object_resource_1", "object_resource_2", etc.? Or is the current mechanism preferred for its human readability of the exported file?

I toyed a bit in Godot to see what it uses as IDs when using "Save Branch as Scene", and it appears to be quite random:

[ext_resource type="PackedScene" uid="uid://nbxmprynxcyd" path="res://collision_shape_2d.tscn" id="2_6ieet"]
[ext_resource type="PackedScene" uid="uid://cqy4y2ac8ub0n" path="res://collision_shape_2d_2.tscn" id="3_r05t1"]

Copy link
Contributor Author

@Skrapion Skrapion Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change in the last commit. I could take it or leave it. The pros:

  • This reduces the line count from 14 to 8.
  • This is more efficient.

The cons:

  • The generated files are less human readable.
  • It makes the files less git-friendly. For instance, given:
[node name="Object8" parent="." instance=ExtResource("object_resource_0")]
position = Vector2(320, 10)

[node name="Object9" parent="." instance=ExtResource("object_resource_1")]
position = Vector2(125, 29.5)

[node name="Object10" parent="." instance=ExtResource("object_resource_2")]
position = Vector2(172, 29.5)

If you delete the first object from the map, then every object afterwards will change, because object_resource_1 will be renamed to object_resource_0, etc.

With the old code, it would remove Object8 and leave it at that.

Copy link
Member

@bjorn bjorn Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked the simplification, but I think your concerns are valid and likely the previous approach will be preferred by some.

src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
@Lexpeartha
Copy link

Lexpeartha commented Aug 9, 2023

Also it might be useful to have custom properties to rename node added as object (which I really think should be default node's name by default).

@Lexpeartha
Copy link

@Skrapion @bjorn any news on this PR?

@Blucky87
Copy link

@bjorn is there any movement on this PR?

@bjorn
Copy link
Member

bjorn commented Jan 24, 2024

@Lexpeartha @Blucky87 The original author hasn't responded to my feedback and I'm not sure if they are still interested in finishing this change. I could try to do it myself, but I am not very familiar with Godot.

If you need object support when using Tiled maps in Godot 4 now, I would suggest you give https://github.com/Kiamo2/YATI a try instead. If there is a reason to prefer Tiled's export plugin, please let me know!

@Skrapion Skrapion force-pushed the godot4objects branch 2 times, most recently from c81059b to c8aa5f6 Compare February 4, 2024 06:48
@Skrapion
Copy link
Contributor Author

Skrapion commented Feb 4, 2024

Finally got back to this! Thanks for your review, and your patience, @bjorn.

}

QString baseName = sanitizeSpecialChars(match.captured(1));
int uniqueifier = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok. But in that case, this whole thing seems to be only a bit complicated due to the use of the base name derived from the path. Couldn't we just give these ext_resource entries unique IDs like "object_resource_1", "object_resource_2", etc.? Or is the current mechanism preferred for its human readability of the exported file?

I toyed a bit in Godot to see what it uses as IDs when using "Save Branch as Scene", and it appears to be quite random:

[ext_resource type="PackedScene" uid="uid://nbxmprynxcyd" path="res://collision_shape_2d.tscn" id="2_6ieet"]
[ext_resource type="PackedScene" uid="uid://cqy4y2ac8ub0n" path="res://collision_shape_2d_2.tscn" id="3_r05t1"]

src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
src/plugins/tscn/tscnplugin.cpp Show resolved Hide resolved
src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
src/plugins/tscn/tscnplugin.cpp Outdated Show resolved Hide resolved
Added some 'static' and 'const', used 'append' instead of 'push_back'
and adjusted indentation.
@bjorn
Copy link
Member

bjorn commented Feb 7, 2024

@Skrapion I'm glad you've come back to life! I left some additional feedback. :-)

@Skrapion
Copy link
Contributor Author

Okay, this should be good to go as soon as CI completes. But whether we use commit 6bde51c or dd6eb6d requires a judgement call. See the review

@bjorn bjorn merged commit b184313 into mapeditor:master Feb 21, 2024
12 of 13 checks passed
@bjorn
Copy link
Member

bjorn commented Feb 21, 2024

@Skrapion Thanks a lot for finishing this nice addition!

@Skrapion Skrapion deleted the godot4objects branch February 24, 2024 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants