mapeditor / tiled

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

Add scripting for custom property types #3971

Open dogboydog opened 5 months ago

dogboydog commented 5 months ago

Aims to fix #3419

Related to #2902

Demo of the functionality so far in the console:

> for (let t of tiled.project.propertyTypes) { tiled.log( t.name) }
Breakable
Door
Enemy
KillZone
> tiled.project.findTypeByName('Enemy').name
$0 = Enemy
> tiled.project.findTypeByName('Enemy').color
$1 = #ff0000
> tiled.project.findTypeByName('Enemy').isClass
$2 = true 
> tiled.project.findTypeByName('Enemy').usageFlags  & ClassPropertyType.LayerClass
$2 = 0
> tiled.project.findTypeByName('Enemy').usageFlags  & ClassPropertyType.MapObjectClass
$3 = 4

TODO:

dogboydog commented 2 months ago

I rebased this from master and tried to take another look, but I still don't feel confident in how to proceed. PropertyTypes returns const pointers which I can't use to modify values nor to try to store a pointer back to the script type to manage cleaning up. Also, you mentioned that there may be a change in how property types are stored coming up, so that they aren't sorted by name and rather allow the user to re-order them, so if I were to try to change PropertyTypes now I'm not sure if that would conflict.

Sorry, I don't write much C++ and so I'm not used to dealing with pointers/const qualifiers

bjorn commented 2 months ago

@dogboydog That's alright, thank you for rebasing the PR!

I would say not to worry about introducing conflicts, since I'd anyway be around to help resolve them again. But yeah, I understand the ownership and const stuff can be a little much if you're not used to C++. I'll see if I can have another look this week.