godotengine / godot-proposals

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

Allow assigning names to TileSet patterns #5550

Open aschuhardt opened 2 years ago

aschuhardt commented 2 years ago

Describe the project you are working on

A 2D game that makes use of the new TileMap system and leverages procedurally-generated content

Describe the problem or limitation you are having in your project

I want to programmatically access TileSet patterns in my scripts, however the only way to do this is by index.

This is complicated by two facts:

The result is that I have to use hard-coded indices in order to access TileSet patterns, and cross my fingers in the hopes that those values don't unexpectedly change.

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

I would like to be able to assign a name to each TileSet pattern that I create using the new editor.

Being able to refer to patterns by a developer-defined name would eliminate both the need to use hard-coded indices, as well as the uncertainty inherent in not having control over what those indices correspond to.

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

Each pattern can be assigned a sequential name by default, which can then be modified by the user (via double-clicking on the name itself I presume). Names might appear in a list to the left of the pattern selection window. Clicking on a name should select/activate the associated pattern in the existing patterns view, and vice-versa (click a pattern to highlight its name). See the mockup below:

fc59d538-89e5-48d8-b611-b26f35b9a840

The script method that accesses TileSet patterns can then have an override written which accepts a name parameter rather than a numerical index.

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

I imagine that this would be used often enough for it to warrant inclusion in the editor.

It could be implemented using an editor plugin, but I'm not sure whether plugins can modify existing editor tabs. Otherwise such a plugin would have to essentially duplicate much of the existing pattern tab.

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

Being able to refer to resources by name seems like a core feature that really ought to be included in the editor.

thely commented 1 year ago

I was about to submit exactly this! City builders would benefit immensely from being able to reference a name. The API would look something like tile_map.get_pattern_by_hash("basic_house"). Additionally, being able to name them means that if you need to adjust a pattern later, you can delete the old one but give the new one the name "basic_house" without needing to jump back into your code to switch out an old index for the new one.

In addition to being able to name patterns, I would also love to see some means of categorizing them, to make it easier to organize them visually and access them via code later. Categories I'd make would be things like trees, large rocks, buildings, etc. In addition to visual clarity, having a tile_set.get_patterns_in_category("trees") means procedural tilemaps could more easily pick a random visual from a list when spawning scenes.