@@ -84,15 +84,47 @@ export abstract class Actor {
84
84
}
85
85
86
86
/**
87
- * Adds a task to the actor's scheduler queue. These tasks will be stopped when the become inactive.
87
+ * Instantiate a task with the Actor instance and a set of arguments.
88
+ *
89
+ * @param taskClass The task class to instantiate. Must be a subclass of {@link Task}
90
+ * @param args The arguments to pass to the task constructor
91
+ *
92
+ * If the task has a stack type of `NEVER`, other tasks in the same {@link TaskStackGroup} will be cancelled.
93
+ */
94
+ public enqueueTask ( taskClass : new ( actor : Actor ) => Task , ...args : never [ ] ) : void ;
95
+ public enqueueTask < T1 , T2 , T3 , T4 , T5 , T6 > ( taskClass : new ( actor : Actor , arg1 : T1 , arg2 : T2 , arg3 : T3 , arg4 : T4 , arg5 : T5 , arg6 : T6 ) => Task , args : [ T1 , T2 , T3 , T4 , T5 , T6 ] ) : void ;
96
+ public enqueueTask < T1 , T2 , T3 , T4 , T5 > ( taskClass : new ( actor : Actor , arg1 : T1 , arg2 : T2 , arg3 : T3 , arg4 : T4 , arg5 : T5 ) => Task , args : [ T1 , T2 , T3 , T4 , T5 ] ) : void ;
97
+ public enqueueTask < T1 , T2 , T3 , T4 > ( taskClass : new ( actor : Actor , arg1 : T1 , arg2 : T2 , arg3 : T3 , arg4 : T4 ) => Task , args : [ T1 , T2 , T3 , T4 ] ) : void ;
98
+ public enqueueTask < T1 , T2 , T3 > ( taskClass : new ( actor : Actor , arg1 : T1 , arg2 : T2 , arg3 : T3 ) => Task , args : [ T1 , T2 , T3 ] ) : void ;
99
+ public enqueueTask < T1 , T2 > ( taskClass : new ( actor : Actor , arg1 : T1 , arg2 : T2 ) => Task , args : [ T1 , T2 ] ) : void ;
100
+ public enqueueTask < T1 > ( taskClass : new ( actor : Actor , arg1 : T1 ) => Task , args : [ T1 ] ) : void ;
101
+ public enqueueTask < T > ( taskClass : new ( actor : Actor , ...args : T [ ] ) => Task , args : T [ ] ) : void {
102
+ if ( ! this . active ) {
103
+ logger . warn ( `Attempted to instantiate task for inactive actor` ) ;
104
+ return ;
105
+ }
106
+
107
+ if ( args ) {
108
+ this . enqueueBaseTask (
109
+ new taskClass ( this , ...args )
110
+ ) ;
111
+ } else {
112
+ this . enqueueBaseTask (
113
+ new taskClass ( this )
114
+ ) ;
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Adds a task to the actor's scheduler queue. These tasks will be stopped when they become inactive.
88
120
*
89
121
* If the task has a stack type of `NEVER`, other tasks in the same group will be cancelled.
90
122
*
91
123
* @param task The task to add
92
124
*/
93
- public enqueueTask ( task : Task ) : void {
125
+ public enqueueBaseTask ( task : Task ) : void {
94
126
if ( ! this . active ) {
95
- logger . warn ( `Attempted to enqueue task for logged out player ` ) ;
127
+ logger . warn ( `Attempted to enqueue task for inactive actor ` ) ;
96
128
return ;
97
129
}
98
130
0 commit comments