Minor - Implements component serialization - V12.9.0
Adds serialization and deserialization functionality to the ECS component system. This allows components to be saved and loaded, enabling scene persistence. The IdentityComponent is updated to support serialization/deserialization. The scene saving logic in scene_manager is updated to serialize components instead of hardcoded values.
This commit is contained in:
@@ -92,6 +92,52 @@ public:
|
||||
return ObjectType::Unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the component to a string.
|
||||
* Format: "id:name:type"
|
||||
* @return A string representation of the component.
|
||||
*/
|
||||
std::string Serialize() const override
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << m_id << ":" << m_name << ":" << ObjectTypeToString(m_type);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize the component from a string.
|
||||
* Expected format: "id:name:type"
|
||||
* @param data The string data to deserialize from.
|
||||
* @return True if deserialization was successful, otherwise false.
|
||||
*/
|
||||
bool Deserialize(const std::string& data) override
|
||||
{
|
||||
std::stringstream ss(data);
|
||||
std::string segment;
|
||||
std::vector<std::string> segments;
|
||||
|
||||
while (std::getline(ss, segment, ':'))
|
||||
{
|
||||
segments.push_back(segment);
|
||||
}
|
||||
|
||||
if (segments.empty()) return false;
|
||||
if (segments.size() != 3) return false;
|
||||
|
||||
try
|
||||
{
|
||||
m_id = std::stoi(segments[0]);
|
||||
m_name = segments[1];
|
||||
m_type = StringToObjectType(segments[2]);
|
||||
return true;
|
||||
} catch (const std::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
int m_id; // ID unique de l'objet
|
||||
std::string m_name; // Nom de l'objet
|
||||
|
||||
Reference in New Issue
Block a user