22import * as THREE from "three" ;
33
44// Import Internal Dependencies
5- import { type GameInstance } from "../systems/GameInstance.ts" ;
6- import type { ActorComponent } from "./ActorComponent.ts" ;
75import { ActorTree } from "./ActorTree.ts" ;
86import { Transform } from "./Transform.ts" ;
7+ import type { GameInstance , GameInstanceDefaultContext } from "../systems/GameInstance.ts" ;
8+ import type { ActorComponent } from "./ActorComponent.ts" ;
99import type { Behavior } from "../components/script/Behavior.ts" ;
1010import type {
1111 Component
@@ -18,14 +18,18 @@ type RequiresOptions<T extends ComponentConstructor> =
1818 ? undefined extends O ? false : true
1919 : false ;
2020
21- export interface ActorOptions < TContext = Record < string , unknown > > {
21+ export interface ActorOptions <
22+ TContext = GameInstanceDefaultContext
23+ > {
2224 name : string ;
2325 parent ?: Actor < TContext > | null ;
2426 visible ?: boolean ;
2527 layer ?: number | number [ ] ;
2628}
2729
28- export class Actor < TContext = Record < string , unknown > > extends ActorTree < TContext > {
30+ export class Actor <
31+ TContext = GameInstanceDefaultContext
32+ > extends ActorTree < TContext > {
2933 gameInstance : GameInstance < any , TContext > ;
3034
3135 name : string ;
@@ -39,13 +43,16 @@ export class Actor<TContext = Record<string, unknown>> extends ActorTree<TContex
3943 threeObject = new THREE . Group ( ) ;
4044
4145 constructor (
42- gameInstance : GameInstance < any , any > ,
46+ gameInstance : GameInstance < any , TContext > ,
4347 options : ActorOptions < TContext >
4448 ) {
4549 super ( ) ;
4650 const { name, parent = null , visible = true , layer } = options ;
4751
48- if ( parent !== null && parent . pendingForDestruction ) {
52+ if (
53+ parent !== null &&
54+ parent . pendingForDestruction
55+ ) {
4956 throw new Error ( "Cannot add actor to a parent that is pending for destruction." ) ;
5057 }
5158
@@ -111,14 +118,13 @@ export class Actor<TContext = Record<string, unknown>> extends ActorTree<TContex
111118 }
112119
113120 getComponentByName < T extends ActorComponent < TContext > > (
114- actor : Actor < TContext > ,
115- componentName : string
121+ componentTypeName : string
116122 ) : T {
117- const component = actor . components . find (
118- ( comp ) => comp . typeName === componentName
123+ const component = this . components . find (
124+ ( comp ) => comp . typeName === componentTypeName
119125 ) ;
120126 if ( ! component ) {
121- throw new Error ( `Component with typeName "${ componentName } " not found on actor "${ actor . name } "` ) ;
127+ throw new Error ( `Component with typeName "${ componentTypeName } " not found on actor "${ this . name } "` ) ;
122128 }
123129
124130 return component as T ;
0 commit comments