mapeditor / tiled

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

When I rename property in Custom Types Editor, it do not rename changed property on the object in map. #4011

Open ludek17052 opened 1 month ago

ludek17052 commented 1 month ago

Describe the bug When I rename property in Custom Types Editor, it do not rename changed property on the object in map.

To Reproduce Steps to reproduce the behavior:

  1. Custom Types Editor -> Add Class "MyClass" -> Add Member "MyMember" (string)
  2. Add "MyClass" to any object "MyObject" in Tileset (*.tsx) / Property name = "MMPropName"
  3. Add "MyObject" into map (*.tmx)
  4. Change value of "MyMember" on the object in the map (*.tmx). Value = "MMValue"
  5. Rename "MyMember" to "MyNewMember" in Custom Types Editor
  6. In map we can see "MyNewMember" on the object, but old value (MMValue) is missing and the value is empty. And now we will change value of "MyNewMember" on the object in the map. Value = "MnewMValue"

In map file (*.tmx) is still "MyMember" with value "MMValue": <property name="MMPropName" type="class" propertytype="MyClass"> <properties> <property name="MyMember" value="MMValue"/> <--- THIS ROW SHOULD BE REMOVED, because we renamed "MyMember" and paramater with this name no more exists <property name="MyNewMember" value="MnewMValue"/> </properties> </property>

If I will repeat steps 4-5-6 there will be more and more parameters that already not exists.

Expected behavior In map file (*.tmx) parameter "MyMember" will be renamed to "MyNewMember" and old value will stay there. And old parametr "MyMember" will be removed.

EDIT: And probably : when I remove "MyClass" from the object in Tileset (*.tsx), it should remove "MyClass" from the object in the map (*.tmx) too. Now "MyClass" is still on the object in map even the object in *.tsx no more contains the "MyClass".

Specifications:

bjorn commented 1 month ago

In map file (*.tmx) parameter "MyMember" will be renamed to "MyNewMember" and old value will stay there. And old parametr "MyMember" will be removed.

I agree this would certainly be nice to do, though the question is how to go about it. The class value is stored as a string/value map and it could be anywhere (ideally part of open file, but it could also be just a script value or a value stored in a file that's not currently loaded).

So to make this work I think we'd need to store the history of class member rename actions along with the class. Then, when loading properties and/or when displaying them in the UI, we can apply these renames as needed.

Of course there should probably also be some way to apply the renames project-wide and possibly to clear the rename history once the user is sure that it is no longer necessary.

THIS ROW SHOULD BE REMOVED, because we renamed "MyMember" and paramater with this name no more exists

Right now, that value is not automatically removed since that would potentially mean a silent loss of data. After renaming a member, you might be able to use search & replace to update existing files to the new name.

eishiya commented 1 month ago

Of course there should probably also be some way to apply the renames project-wide and possibly to clear the rename history once the user is sure that it is no longer necessary.

This is what I'd like to see. I'd even be happy with the rename history only being saved while the Custom Types Editor is open, and it asking if you want to update all your files when you try to close it. Of course, letting the user decide when to perform this potentially lengthy operation (due to all the file loads required) would be best.

ludek17052 commented 1 month ago

Ok. I understand. But this property could be visible in Property Toolbar. If object in map have got a property, that do not exists in Tileset object or in Custom Types, the property could be still visible in Property Toolbar. Maybe with color backgroud? Now the property is "hidden" and can be found only in file. Like a "silent loss of data" this is "silent keeping of data" and it is not ideal too.

bjorn commented 1 month ago

If object in map have got a property, that do not exists in Tileset object or in Custom Types, the property could be still visible in Property Toolbar. Maybe with color background? Now the property is "hidden" and can be found only in file. Like a "silent loss of data" this is "silent keeping of data" and it is not ideal too.

Yes, I agree it would be nice to still show this property, possibly in italics or strike-through. It is a little tricky, since at the moment the child properties are added only based on the class but then it depends on the value as well.