Files
axyz/src/Engine/Core/EntityWrapper.cpp
T
Jace fc06a4babc Editor keyboard shortcuts:
Ctrl+S to save the currently selected entity file (iterates to the base parent)
Ctrl+N to create a new empty entity under the selection
Ctrl+O to import an entity file
Del to delete an entity
2016-01-21 15:58:27 +01:00

68 lines
1.5 KiB
C++

#include "Core/EntityWrapper.h"
#include "Core/World.h"
const EntityWrapper EntityWrapper::Invalid = EntityWrapper(nullptr, EntityID_Invalid);
bool EntityWrapper::HasComponent(const std::string& componentName)
{
return World->HasComponent(ID, componentName);
}
EntityWrapper EntityWrapper::Parent()
{
if (this->World == nullptr || this->ID == EntityID_Invalid) {
return EntityWrapper::Invalid;
} else {
return EntityWrapper(this->World, this->World->GetParent(this->ID));
}
}
bool EntityWrapper::Valid()
{
if (this->World == nullptr) {
return false;
}
if (this->ID == EntityID_Invalid) {
return false;
}
if (!this->World->ValidEntity(this->ID)) {
this->ID = EntityID_Invalid;
return false;
}
return true;
}
ComponentWrapper EntityWrapper::operator[](const char* componentName)
{
if (World->HasComponent(ID, componentName)) {
return World->GetComponent(ID, componentName);
} else {
LOG_WARNING("EntityWrapper implicitly attached \"%s\" component to #%i as a result of a fetch request!", componentName, ID);
return World->AttachComponent(ID, componentName);
}
}
bool EntityWrapper::operator==(const EntityWrapper& e) const
{
return (this->ID == e.ID) && (this->World == e.World);
}
bool EntityWrapper::operator!=(const EntityWrapper& e) const
{
return !this->operator==(e);
}
EntityWrapper::operator EntityID() const
{
return this->ID;
}
EntityWrapper::operator bool()
{
return this->Valid();
}