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