|
@@ -410,41 +410,43 @@ Class Entity Extends DynamicObject
|
|
|
|
|
|
#rem monkeydoc Gets the number of components of a given type attached to the entity.
|
|
|
#end
|
|
|
- Method NumComponents:Int( type:ComponentType )
|
|
|
+ Method NumComponents<T>:Int() Where T Extends Component
|
|
|
|
|
|
Local n:=0
|
|
|
For Local c:=Eachin _components
|
|
|
- If c.Type=type n+=1
|
|
|
+ If Cast<T>( c ) n+=1
|
|
|
Next
|
|
|
- Return n
|
|
|
- End
|
|
|
-
|
|
|
- Method NumComponents<T>:Int() Where T Extends Component
|
|
|
|
|
|
- Return NumComponents( T.Type )
|
|
|
+ Return n
|
|
|
End
|
|
|
-
|
|
|
+
|
|
|
#rem monkeydoc Gets a component of a given type attached to the entity.
|
|
|
|
|
|
- If there is not exactly one component of the given type attached to the entity, null is returned.
|
|
|
+ If there is more than one component of the given type attached, the first is returned.
|
|
|
|
|
|
#end
|
|
|
- Method GetComponent:Component( type:ComponentType )
|
|
|
-
|
|
|
- Local t:Component
|
|
|
-
|
|
|
+ Method GetComponent<T>:T() Where T Extends Component
|
|
|
+
|
|
|
For Local c:=Eachin _components
|
|
|
- If c.Type<>type Continue
|
|
|
- If t Return Null
|
|
|
- t=c
|
|
|
+ Local t:=Cast<T>( c )
|
|
|
+ If t Return t
|
|
|
Next
|
|
|
|
|
|
- Return t
|
|
|
+ Return Null
|
|
|
End
|
|
|
|
|
|
- Method GetComponent<T>:T() Where T Extends Component
|
|
|
+ Method GetComponents<T>:T[]() Where T Extends Component
|
|
|
+
|
|
|
+ Local cs:=New Component[NumComponents<T>()],i:=0
|
|
|
+
|
|
|
+ For Local c:=Eachin _components
|
|
|
+ Local t:=Cast<T>( c )
|
|
|
+ If Not t Continue
|
|
|
+ cs[i]=t
|
|
|
+ i+=1
|
|
|
+ Next
|
|
|
|
|
|
- Return Cast<T>( GetComponent( T.Type ) )
|
|
|
+ Return cs
|
|
|
End
|
|
|
|
|
|
#rem monkeydoc Attaches a component to the entity.
|