Made EntityFileParser::MergeEntities return the base entity that was created, and also take an optional parent entity to create it under.
This commit is contained in:
@@ -77,7 +77,7 @@ public:
|
|||||||
: m_Handler(handler)
|
: m_Handler(handler)
|
||||||
, m_Reader(reader)
|
, m_Reader(reader)
|
||||||
{
|
{
|
||||||
// 0 is imaginary world entity
|
// 0 is imaginary base parent
|
||||||
m_EntityStack.push(0);
|
m_EntityStack.push(0);
|
||||||
m_StateStack.push(State::Unknown);
|
m_StateStack.push(State::Unknown);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,13 @@ class EntityFileParser
|
|||||||
public:
|
public:
|
||||||
EntityFileParser(const EntityFile* entityFile);
|
EntityFileParser(const EntityFile* entityFile);
|
||||||
|
|
||||||
void MergeEntities(World* world);
|
EntityID MergeEntities(World* world, EntityID baseParent = EntityID_Invalid);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const EntityFile* m_EntityFile;
|
const EntityFile* m_EntityFile;
|
||||||
EntityFileHandler m_Handler;
|
EntityFileHandler m_Handler;
|
||||||
World* m_World = nullptr;
|
World* m_World = nullptr;
|
||||||
|
EntityID m_FirstEntity = EntityID_Invalid;
|
||||||
// Maps EntityIDs local to the file to real IDs in the world after they've been
|
// Maps EntityIDs local to the file to real IDs in the world after they've been
|
||||||
// created in order to resolve parent-child relationships.
|
// created in order to resolve parent-child relationships.
|
||||||
std::map<EntityID, EntityID> m_EntityIDMapper;
|
std::map<EntityID, EntityID> m_EntityIDMapper;
|
||||||
|
|||||||
@@ -9,17 +9,21 @@ EntityFileParser::EntityFileParser(const EntityFile* entityFile)
|
|||||||
m_Handler.SetStartFieldDataCallback(std::bind(&EntityFileParser::onFieldData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
m_Handler.SetStartFieldDataCallback(std::bind(&EntityFileParser::onFieldData, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityFileParser::MergeEntities(World* world)
|
EntityID EntityFileParser::MergeEntities(World* world, EntityID baseParent /*= EntityID_Invalid */)
|
||||||
{
|
{
|
||||||
m_World = world;
|
m_World = world;
|
||||||
m_EntityIDMapper[0] = 0;
|
m_EntityIDMapper[0] = baseParent;
|
||||||
m_EntityFile->Parse(&m_Handler);
|
m_EntityFile->Parse(&m_Handler);
|
||||||
|
return m_FirstEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std::string& name)
|
void EntityFileParser::onStartEntity(EntityID entity, EntityID parent, const std::string& name)
|
||||||
{
|
{
|
||||||
EntityID realParent = m_EntityIDMapper.at(parent);
|
EntityID realParent = m_EntityIDMapper.at(parent);
|
||||||
EntityID realEntity = m_World->CreateEntity(realParent);
|
EntityID realEntity = m_World->CreateEntity(realParent);
|
||||||
|
if (m_FirstEntity == EntityID_Invalid) {
|
||||||
|
m_FirstEntity = realEntity;
|
||||||
|
}
|
||||||
if (!name.empty()) {
|
if (!name.empty()) {
|
||||||
m_World->SetName(realEntity, name);
|
m_World->SetName(realEntity, name);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user