Sdk/World: Add CloneEntity(const EntityHandle&) overload

This commit is contained in:
Lynix 2019-10-15 09:32:30 +02:00
parent aee9a38f76
commit f6bbe396fa
3 changed files with 16 additions and 4 deletions

View File

@ -289,6 +289,7 @@ Nazara Development Kit:
- ⚠️ Made AbstractTextAreaWidget which is inherited by TextAreaWidget
- ⚠️ Added RichTextAreaWidget
- ⚠️ Console now supports text color in history
- Added World::CloneEntity overload taking an EntityHandle const reference, allowing to copy entities from other worlds
# 0.4:

View File

@ -46,6 +46,7 @@ namespace Ndk
void Clear() noexcept;
const EntityHandle& CloneEntity(EntityId id);
const EntityHandle& CloneEntity(const EntityHandle& entity);
inline void DisableProfiler();
inline void EnableProfiler(bool enable = true);

View File

@ -157,16 +157,26 @@ namespace Ndk
return EntityHandle::InvalidHandle;
}
return CloneEntity(original);
}
/*!
* \brief Clones the entity
* \return The clone newly created
*
* \param original Entity handle
*
* \remark Cloning a disabled entity will produce an enabled clone
*/
const EntityHandle& World::CloneEntity(const EntityHandle& original)
{
const EntityHandle& clone = CreateEntity();
if (!original->IsEnabled())
clone->Disable();
const Nz::Bitset<>& componentBits = original->GetComponentBits();
for (std::size_t i = componentBits.FindFirst(); i != componentBits.npos; i = componentBits.FindNext(i))
{
std::unique_ptr<BaseComponent> component(original->GetComponent(ComponentIndex(i)).Clone());
clone->AddComponent(std::move(component));
}
clone->AddComponent(original->GetComponent(ComponentIndex(i)).Clone());
clone->Enable();