remram44 / pybabel-godot

Plugin for Babel to support Godot scene files (.tscn)
Other
14 stars 11 forks source link

Allow extracting text from instanced scenes #1

Closed asilvestre closed 4 years ago

asilvestre commented 4 years ago

I found that in order to extract text from exports in packed scenes the following changes are necessary.

The problem is packed scenes in tscn files don't have the type= property so they are not accepted by the regular expression that deals with nodes.

For instance, this packed scene with this property wouldn't be extracted:

[node name="LeavePortal" parent="." index="8" instance=ExtResource( 4 )]
text = "leave"

I make this PR in case you find it useful, thank you for your work!

remram44 commented 4 years ago

Hi @asilvestre, thank you so much for the patch!

How do you use this in practice, with empty node types? -k /text? I guess it would be nice to be able to differentiate which scene is instantiated but that would require more parsing 😅

asilvestre commented 4 years ago

Hi, actually I use -k text (which I guess might have the same effect as -k /text).

About parsing the type of node it wouldn't be that difficult, at the beginning of the tscn's there are listed all the ext_resource nodes reference to.

Following the previous example, its external resource would be:

[ext_resource path="res://scenes/map/teleporter/Teleporter.tscn" type="PackedScene" id=4]

This section of the file could be parsed to build an index of the types of each ext_resource and then with this information the missing type in the node could be filled up.

If you think this would be better I can change it.

remram44 commented 4 years ago

I forgot there was the case in the code, a field name alone will be matched by all node types.

If you think being able to filter on scenes is useful, don't hesitate to send a patch! I'm thinking this might be overkill though.