Skip to content

Commit 6361491

Browse files
committed
Deprecate ResourceConstrainedComponent access
Resource constrained components are never known to be safe to use. They should always be unwrapped with component(ofType:).
1 parent 6221cca commit 6361491

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Sources/GateEngine/ECS/Base/Entity.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ extension Entity {
9696
self.insert(newValue)
9797
}
9898
}
99+
100+
@inlinable
101+
@available(*, deprecated, message: "Accessing a ResourceConstrainedComponent directly is never safe. Use Entity.component(ofType:) instead.", renamed: "component(ofType:)")
102+
public subscript<T: ResourceConstrainedComponent>(_ type: T.Type) -> T {
103+
get {
104+
let componentID = type.componentID.value
105+
#if DEBUG
106+
Log.assert(hasComponent(at: componentID), "Component \"\(type)\" is not a member of this entity.")
107+
#endif
108+
return self.getComponent(at: componentID) as! T
109+
}
110+
set {
111+
self.insert(newValue)
112+
}
113+
}
99114

100115
/// Obtain an existing component by it's ID.
101116
/// - returns The existing component or nil if it's not present.

0 commit comments

Comments
 (0)