godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.16k stars 97 forks source link

Expose raw tilemap data to GDScript #8914

Closed JUSTCAMH closed 9 months ago

JUSTCAMH commented 9 months ago

Describe the project you are working on

A metroidvania game

Describe the problem or limitation you are having in your project

I've made a super convenient script that handles saving and loading via node paths. If I input the node path "World/Tilemap:position", then the position of the tilemap will automatically get saved and loaded, no extra code needed! The issue with this is I can only save / load data that is exposed to GDScript, and it currently seems that the layers of a tilemap are not exposed.

Inspecting the .tscn of a file containing a tilemap in a text editor reveals a list of PackedInt32Arrays containing all the tile data for each layer, this is what I would like access to in GDScript.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Add a tilemap.raw_data variable which returns the array of PackedInt32Arrays that represents the raw data of the tilemap. The user can get and set this like usual, and setting this variable would update the tilemap internals

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Expose tilemap.raw_data which simply returns the raw data that the tilemap uses, as seen in the .tscn of a scene containing a tilemap.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Nope, can't currently access this data

Is there a reason why this should be core and not an add-on in the asset library?

Tilemaps are core

KoBeWi commented 9 months ago

Well, you do have access to that. Just call tile_map.get("layer_0/tile_data").

JUSTCAMHRara commented 9 months ago

Oh wow, that function is so much more powerful than I had thought, thanks!