#include "fsCEntityFactory.h"
#include <fsCore/src/debug/fsAssert.h>
#include "fsCEntity.h"
void fsCEntityFactory::merge(fsCEntityFactory* const pRHS)
{
mPlans.insert(pRHS->mPlans.begin(), pRHS->mPlans.end());
}
fsCEntity* fsCEntityFactory::emptyEntityCreate(const fsStr& pEntityName) const<--- The member function 'fsCEntityFactory::emptyEntityCreate' can be static.
{
fsCEntity* const retEnt = new fsCEntity(pEntityName);
return retEnt;
}
fsCEntity* fsCEntityFactory::entityConstructWithComponent(const fsStr& pEntityName, fsCUniqueId pComponentId) const
{
fsCEntity* const retEnt = emptyEntityCreate(pEntityName);
retEnt->componentAdd(pComponentId);
retEnt->init();
return retEnt;
}
fsCEntity* fsCEntityFactory::entityConstruct(const fsStr& pEntityName) const
{
fsCEntity* const retEnt = emptyEntityCreate(pEntityName);
const fsStr& entPrefix = entityPrefixGet(pEntityName);
auto plan = mPlans.find(entPrefix);
if (mPlans.end() != plan)
{
for (fsCUniqueId compId : plan->second)
{
retEnt->componentAdd(compId);
}
retEnt->init();
}
return retEnt;
}
fsStr fsCEntityFactory::entityPrefixGet(const fsStr& pEntityName) const<--- The member function 'fsCEntityFactory::entityPrefixGet' can be static.
{
fsStr::sizeT matchPos = pEntityName.find("-");
fsAssert(fsStr::npos != matchPos, "Expected a prefix on entity name %s.\n", pEntityName.utf8Get());
fsStr prefix;
prefix.copy(pEntityName.utf8Get(), 0, matchPos + 1);
return prefix;
}
void fsCEntityFactory::constructionPlansRegister()
{
mHierarchyCheck = false;
constructionPlansRegisterDo();
fsAssert(mHierarchyCheck, "All derived classes need to call super::constructionPlansRegisterDo()\n");
}
void fsCEntityFactory::constructionPlansRegisterDo()
{
mHierarchyCheck = true;
}
fsCEntityFactory::fsCEntityFactory() :
mHierarchyCheck(false)
{
}
fsCEntityFactory::~fsCEntityFactory()
{
}