mapeditor / tiled

Flexible level editor
https://www.mapeditor.org/
Other
11.26k stars 1.76k forks source link

No option to change layer ID #4020

Closed ManPython closed 3 months ago

ManPython commented 3 months ago

Describe the bug No option to change layer ID. This made problem when deleting old to add new due some mistakes, then ID is always incremented.

To Reproduce Steps to reproduce the behavior:

  1. Add layer twice or more to have eg 5 layers
  2. Delete layer 2 and 4
  3. Try to change ID layer 3 to 2 and 4 to 3

Expected behavior Manage ID due automation for discover layers, eg. levels as some template (1st main terain, 2nd sprite_1 3th sprite_3) It's bad case to no option to change or manage when many maps and something was in bad case.

Media If applicable, add screenshots or videos to help explain your problem.

Specifications:

eishiya commented 3 months ago

Why is this necessary, what is your use for sequential IDs? Layer IDs are a Tiled implementation detail and their specific value shouldn't matter as long as they remain unique within a map. If you are relying on layer IDs for something in your game, that is a mistake - use layer names or custom properties instead.

That said, I do wish Tiled assigned layer IDs sequentially based on the IDs currently in use, rather than always incrementing. This would avoid the need to store "nextlayerid" in map files, and it would prevent the IDs from getting silly large when layers are created and deleted repeatedly. I have some maps with perhaps a dozen layers with IDs in the hundreds if not thousands, and it just feels silly. It's not a "real" problem since, as I said, the IDs should not be treated as static or "important" (and in fact, could be randomised on each save without making them any less useful), but the IDs getting huge does bother me a bit.

Ditto for Objects, which have the same problem. With Objects, the IDs are done the way they are to prevent object references from accidentally referring to the wrong object when the values are changed, but I'd rather see IDs reused and no-longer-valid references cleared.

ManPython commented 3 months ago

Coz is often fake and bad intuition due names in case code need int ID.. https://github.com/mapeditor/tiled/issues/4018

ManPython commented 3 months ago

I think You are wrong.. coz .tmx should be like a data base and template, so if you building logic levels eg. 3 similar, then layers should be this same id for each. And when some mistake or something.. accidentally pushed add layer, etc. changing this data structure with no option to manage. I tried manually in file, but then app have problem with this.. as broken - probably I made this in bad way or it not allowing to some changes maybe.

bjorn commented 3 months ago

It's not a "real" problem since, as I said, the IDs should not be treated as static or "important" (and in fact, could be randomised on each save without making them any less useful), but the IDs getting huge does bother me a bit.

When layer IDs were introduced, it was specifically to allow other files to associate data with specific layers, in the knowledge that a layer ID would be both unique and stable. Layer IDs are also used for making the current layer and expanded layers persistent across sessions.

So allowing layer IDs to be changed or randomized would mess with the original use-case for layer IDs and could cause issues (although minor) with restoring the session. Internally, they are also used in cases where a direct pointer isn't possible (a kind of weak reference).

We can see these IDs as similar to the unique IDs assigned to rows in a database table. These IDs are generally also never changed and not reused after rows have been deleted.

I understand that not everybody works the same, but I'd really suggest to use layer names rather than trying to rely on their IDs. Or maybe you can just rely on their order / index if you don't want to look them up by their name, since you can reorder layers as needed.

ManPython commented 3 months ago

Ok.. ID as key. But maybe should be something like queue? Then as int can be constant and more easy to manage and to have "parallel" model between other files.

bjorn commented 3 months ago

@ManPython Sorry, I have no idea what you mean.

ManPython commented 3 months ago

I can change position queue in GUI, but can't use queue id in case want use IDqueue not IDkey.

eishiya commented 3 months ago

As bjorn suggested earlier, you can use the layer index (i.e. its position in the list of layers) instead of the layer ID if you want. It would be against the purpose of the layer ID for it to change when layers are reordered. The index isn't displayed in the GUI, but it would be simple to calculate it, or to write a script to calculate it for you.

And if you want a fully controllable "ID" that only changes when you want it to, you can use custom properties.