GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
Public Member Functions | Protected Attributes | List of all members

Used as a base class for classes that will own objects (see gd::Object). More...

#include <ObjectsContainer.h>

Inherited by gd::EventsBasedObject, gd::Layout, and gd::Project.

Public Member Functions

 ObjectsContainer ()
 Default constructor creating a container without any objects.
 
std::vector< const ObjectFolderOrObject * > GetAllObjectFolderOrObjects () const
 
gd::ObjectFolderOrObjectGetRootFolder ()
 
void AddMissingObjectsInRootFolder ()
 
Objects management

Members functions related to objects management.

bool HasObjectNamed (const gd::String &name) const
 Return true if object called name exists.
 
ObjectGetObject (const gd::String &name)
 Return a reference to the object called name.
 
const gd::ObjectGetObject (const gd::String &name) const
 Return a reference to the object called name.
 
ObjectGetObject (std::size_t index)
 Return a reference to the object at position index in the objects list.
 
const gd::ObjectGetObject (std::size_t index) const
 Return a reference to the object at position index in the objects list.
 
std::size_t GetObjectPosition (const gd::String &name) const
 Return the position of the object called name in the objects list. More...
 
std::size_t GetObjectsCount () const
 Return the number of object.
 
gd::ObjectInsertNewObject (const gd::Project &project, const gd::String &objectType, const gd::String &name, std::size_t position)
 Add a new empty object of type objectType called name at the specified position in the list.
More...
 
gd::ObjectInsertNewObjectInFolder (const gd::Project &project, const gd::String &objectType, const gd::String &name, gd::ObjectFolderOrObject &objectFolderOrObject, std::size_t position)
 Add a new empty object of type objectType called name in the given folder at the specified position.
More...
 
gd::ObjectInsertObject (const gd::Object &object, std::size_t position)
 Add a new object to the list. More...
 
void RemoveObject (const gd::String &name)
 Delete an object. More...
 
void MoveObject (std::size_t oldIndex, std::size_t newIndex)
 
void MoveObjectFolderOrObjectToAnotherContainerInFolder (gd::ObjectFolderOrObject &objectFolderOrObject, gd::ObjectsContainer &newContainer, gd::ObjectFolderOrObject &newParentFolder, std::size_t newPosition)
 
std::vector< std::unique_ptr< gd::Object > > & GetObjects ()
 
const std::vector< std::unique_ptr< gd::Object > > & GetObjects () const
 
Saving and loading

Members functions related to saving and loading the objects of the class.

void SerializeObjectsTo (SerializerElement &element) const
 Serialize the objects container.
 
void UnserializeObjectsFrom (gd::Project &project, const SerializerElement &element)
 Unserialize the objects container.
 
void SerializeFoldersTo (SerializerElement &element) const
 Serialize folder structure.
 
void UnserializeFoldersFrom (gd::Project &project, const SerializerElement &element)
 Unserialize folder structure.
 
Objects groups management

Members functions related to global objects groups management.

ObjectGroupsContainerGetObjectGroups ()
 Return a reference to the project's objects groups.
 
const ObjectGroupsContainerGetObjectGroups () const
 Return a const reference to the project's objects groups.
 

Protected Attributes

std::vector< std::unique_ptr< gd::Object > > initialObjects
 Objects contained.
 
gd::ObjectGroupsContainer objectGroups
 

Detailed Description

Used as a base class for classes that will own objects (see gd::Object).

For example, gd::Project inherits from this class as it have global objects.
gd::Layout also inherits from this class as each layout has specific objects.

See also
gd::Project
gd::Layout
gd::Object

Member Function Documentation

◆ GetAllObjectFolderOrObjects()

std::vector< const ObjectFolderOrObject * > gd::ObjectsContainer::GetAllObjectFolderOrObjects ( ) const

Returns a vector containing all object and folders in this container. Only use this for checking if you hold a valid ObjectFolderOrObject - don't use this for rendering or anything else.

◆ GetObjectPosition()

std::size_t gd::ObjectsContainer::GetObjectPosition ( const gd::String name) const

Return the position of the object called name in the objects list.

Warning
This has nothing to do with an object position on a layout. Objects put on layouts are represented thanks to the gd::InitialInstance class.

◆ GetObjects() [1/2]

std::vector<std::unique_ptr<gd::Object> >& gd::ObjectsContainer::GetObjects ( )
inline

Provide a raw access to the vector containing the objects

◆ GetObjects() [2/2]

const std::vector<std::unique_ptr<gd::Object> >& gd::ObjectsContainer::GetObjects ( ) const
inline

Provide a raw access to the vector containing the objects

◆ InsertNewObject()

gd::Object & gd::ObjectsContainer::InsertNewObject ( const gd::Project project,
const gd::String objectType,
const gd::String name,
std::size_t  position 
)

Add a new empty object of type objectType called name at the specified position in the list.

Note
The object is created using the project's current platform.
Returns
A reference to the object in the list.

◆ InsertNewObjectInFolder()

gd::Object & gd::ObjectsContainer::InsertNewObjectInFolder ( const gd::Project project,
const gd::String objectType,
const gd::String name,
gd::ObjectFolderOrObject objectFolderOrObject,
std::size_t  position 
)

Add a new empty object of type objectType called name in the given folder at the specified position.

Note
The object is created using the project's current platform.
Returns
A reference to the object in the list.

◆ InsertObject()

gd::Object & gd::ObjectsContainer::InsertObject ( const gd::Object object,
std::size_t  position 
)

Add a new object to the list.

Note
The object passed by parameter is copied.
Parameters
objectThe object that must be copied and inserted into the project
positionInsertion position. If the position is invalid, the object is inserted at the end of the objects list.
Returns
A reference to the object in the list.

◆ MoveObject()

void gd::ObjectsContainer::MoveObject ( std::size_t  oldIndex,
std::size_t  newIndex 
)

Change the position of the specified object.

◆ MoveObjectFolderOrObjectToAnotherContainerInFolder()

void gd::ObjectsContainer::MoveObjectFolderOrObjectToAnotherContainerInFolder ( gd::ObjectFolderOrObject objectFolderOrObject,
gd::ObjectsContainer newContainer,
gd::ObjectFolderOrObject newParentFolder,
std::size_t  newPosition 
)

Move the specified object to another container, removing it from the current one and adding it to the new one at the specified position in the given folder.

Note
This does not invalidate the references to the object (object is not moved in memory, as referenced by smart pointers internally).

◆ RemoveObject()

void gd::ObjectsContainer::RemoveObject ( const gd::String name)

Delete an object.

Warning
When calling this function, be sure to drop any reference that you might hold to the object - otherwise you'll access deleted memory.
Parameters
nameThe name of the object to be deleted.

The documentation for this class was generated from the following files: