#pragma once #include "MinimalEngine.h" #include "Scene/Scene.h" #include #include #include namespace Seele { // An entity describes a part of a scene // It is just a wrapper the ID of a registry class Entity { public: Entity(PScene scene); virtual ~Entity(); // True if this entity currently has the given component attached. Pure handle-space // (no entt::entity crosses the boundary) - the building block the editor's component // inspector uses to ask "what is attached to this OEntity?" without ever touching the // registry directly. Uses the entt try_get idiom: it returns a pointer to the component // storage the entity holds, or null if the component is not attached - so the check is // null-safe (no assertion) and works for any displayable component type. template bool hasComponent() const { return scene->registry.try_get(identifier) != nullptr; } // The entt record this handle wraps. Exposed (not as the old raw `getId()`, but scoped // and documented as internal) so the *scene* can keep its roster in lock-step with the // registry during Entity ctor/dtor. The editor never calls this - it works entirely in // handle space via hasComponent/accessComponent. entt::entity getIdentifier() const { return identifier; } // A short, stable, human-facing label for tooling (the inspector's row text). Formatted // *inside* the engine so the editor never has to name the entt::entity type at all - // it just asks "what should I display for this OEntity?" and gets a string. This is the // "display the ID of an entity" requirement satisfied in pure handle space: the numeric // id is rendered to text here and never leaks out as an entt type. std::string getLabel() const { std::ostringstream oss; oss << "#" << static_cast(identifier); return oss.str(); } template Component& attachComponent(Args&&... args) { return scene->attachComponent(identifier, std::forward(args)...); } template Component& accessComponent() { return scene->accessComponent(identifier); } template const Component& accessComponent() const { return scene->accessComponent(identifier); } protected: PScene scene; entt::entity identifier; }; DEFINE_REF(Entity) } // namespace Seele