Generate UUIDs for Layers lazily

This commit is contained in:
Martín Capello 2025-02-24 11:12:54 -03:00
parent d398bd7a2a
commit 7a03e45475
2 changed files with 13 additions and 11 deletions

View File

@ -36,9 +36,6 @@ Layer::Layer(ObjectType type, Sprite* sprite)
type == ObjectType::LayerTilemap); type == ObjectType::LayerTilemap);
setName("Layer"); setName("Layer");
// Always generate a UUID for this layer, but take into account that it could
// be replaced. For instance, when loading a layer that already had a UUID.
m_uuid = base::Uuid::Generate();
} }
Layer::~Layer() Layer::~Layer()

View File

@ -129,7 +129,12 @@ public:
int opacity() const { return m_opacity; } int opacity() const { return m_opacity; }
void setOpacity(int opacity) { m_opacity = opacity; } void setOpacity(int opacity) { m_opacity = opacity; }
const base::Uuid& uuid() const { return m_uuid; } const base::Uuid& uuid() const
{
if (m_uuid == base::Uuid())
m_uuid = base::Uuid::Generate();
return m_uuid;
}
void setUuid(const base::Uuid& uuid) { m_uuid = uuid; } void setUuid(const base::Uuid& uuid) { m_uuid = uuid; }
virtual Grid grid() const; virtual Grid grid() const;
@ -142,7 +147,7 @@ private:
Sprite* m_sprite; // owner of the layer Sprite* m_sprite; // owner of the layer
LayerGroup* m_parent; // parent layer LayerGroup* m_parent; // parent layer
LayerFlags m_flags; // stack order cannot be changed LayerFlags m_flags; // stack order cannot be changed
base::Uuid m_uuid; // The UUID is generated the first time the "HasUUID" flag mutable base::Uuid m_uuid; // The UUID is generated the first time the "HasUUID" flag
// is activated when it is a null UUID. If this field had // is activated when it is a null UUID. If this field had
// a valid UUID already, it won't be replaced by a new one. // a valid UUID already, it won't be replaced by a new one.