Skip to content

Commit

Permalink
Enforce key type on NAME_TO_COMPONENT
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Sep 21, 2023
1 parent 60b6709 commit b0e4f86
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/bit-systems/behavior-graph/entity-nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
NetworkedBehavior,
MediaFrame
} from "../../bit-components";
import { GLTFComponentData } from "../../utils/jsx-entity";

type SocketTypeName =
| "string"
Expand Down Expand Up @@ -62,17 +63,18 @@ type EntityEventState = {
};
export const entityEvents = new Map<EntityID, EntityEventState>();

type TextToComponentType = { [key: string]: ComponentType<any> };
type ComponentKeyType = keyof GLTFComponentData;
type TextToComponentType = { [K in ComponentKeyType]: ComponentType<any> };
const NAME_TO_COMPONENT = {
video: MediaVideo,
audio: MediaVideo,
text: TextTag,
"media-frame": MediaFrame,
"networked-animation": NetworkedAnimation,
"rigid-body": Rigidbody,
"physics-shape": PhysicsShape,
"networked-transform": NetworkedTransform,
"networked-behavior": NetworkedBehavior
mediaFrame: MediaFrame,
networkedAnimation: NetworkedAnimation,
rigidbody: Rigidbody,
physicsShape: PhysicsShape,
networkedTransform: NetworkedTransform,
networkedBehavior: NetworkedBehavior
} as TextToComponentType;

type EntityEventData = {
Expand Down Expand Up @@ -623,7 +625,7 @@ function makeMaterialPropertyNodes<T extends SettableMaterialProperties, S exten
in: [{ entity: "entity" }, { component: "string" }],
out: [{ entity: "entity" }],
exec: (entity: EntityID, component: string) => {
const cmp = findChildWithComponent(APP.world, NAME_TO_COMPONENT[component], entity);
const cmp = findChildWithComponent(APP.world, NAME_TO_COMPONENT[component as ComponentKeyType], entity);
return { entity: cmp };
}
})
Expand Down

0 comments on commit b0e4f86

Please sign in to comment.