LeviLamina
Loading...
Searching...
No Matches
EntityContext.h
1#pragma once
2
3#include "mc/_HeaderOutputPredefine.h"
4
5// auto generated inclusion list
6#include "mc/deps/ecs/EntityId.h"
7#include "mc/deps/game_refs/EnableGetWeakRef.h"
8
9// auto generated forward declare list
10// clang-format off
11class WeakEntityRef;
12class EntityRegistry;
13// clang-format on
14
15class EntityContext : public ::EnableGetWeakRef<::EntityContext> {
16public:
17 // EntityContext inner types declare
18 // clang-format off
19 struct Hash;
20 // clang-format on
21
22 // EntityContext inner types define
23 struct Hash {};
24
25public:
26 [[nodiscard]] inline entt::basic_registry<EntityId>& getRegistry() noexcept { return mEnTTRegistry; }
27
28 [[nodiscard]] inline entt::basic_registry<EntityId> const& getRegistry() const noexcept { return mEnTTRegistry; }
29
30 template <class T>
31 [[nodiscard]] inline optional_ref<T const> tryGetComponent() const {
32 return getRegistry().try_get<T>(mEntity);
33 }
34
35 template <class T>
36 [[nodiscard]] inline optional_ref<T> tryGetComponent() {
37 return const_cast<T*>(std::as_const(getRegistry()).try_get<T>(mEntity));
38 }
39
40 template <class T>
41 [[nodiscard]] inline bool hasComponent() const {
42 return getRegistry().all_of<T>(mEntity);
43 }
44
45 template <class T>
46 inline bool removeComponent() {
47 return getRegistry().remove<T>(mEntity);
48 }
49
50 template <class T, typename... Args>
51 [[nodiscard]] inline T& getOrAddComponent(Args&&... args) {
52 return getRegistry().get_or_emplace<T>(mEntity, std::forward<Args>(args)...);
53 }
54
55 LLNDAPI WeakEntityRef getWeakRef() const;
56
57public:
58 // member variables
59 // NOLINTBEGIN
60 ::EntityRegistry& mRegistry;
61 ::entt::basic_registry<::EntityId>& mEnTTRegistry;
62 ::EntityId const mEntity;
63 // NOLINTEND
64
65public:
66 // prevent constructor by default
67 EntityContext& operator=(EntityContext const&);
68 EntityContext(EntityContext const&) = default;
69 EntityContext();
70};
Definition EnableGetWeakRef.h:6
Definition EntityRegistry.h:10
Definition WeakEntityRef.h:14
Definition EntityContext.h:23