Skip to content

Commit 2d4eff7

Browse files
shinohara-rinnekomeowww
authored andcommitted
fix(minecraft): don't rebuild dispatch table every time
1 parent 3c7b42a commit 2d4eff7

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

services/minecraft/src/cognitive/perception/attention-detector.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ export class AttentionDetector {
3535
}
3636
>()
3737

38+
private readonly dispatch: Record<string, Record<string, (event: RawPerceptionEvent) => void>> = {
39+
sighted: {
40+
arm_swing: event => this.onPunch(event as any),
41+
sneak_toggle: event => this.onSneakToggle(event as any),
42+
entity_moved: event => this.onMove(event as any),
43+
},
44+
heard: {
45+
sound: event => this.onSound(event as any),
46+
},
47+
felt: {
48+
damage_taken: event => this.onDamage(event as any),
49+
item_collected: event => this.onPickup(event as any),
50+
},
51+
}
52+
3853
constructor(
3954
private readonly deps: {
4055
eventManager: EventManager
@@ -56,21 +71,7 @@ export class AttentionDetector {
5671
}
5772

5873
public ingest(event: RawPerceptionEvent): void {
59-
const dispatch: Record<string, Record<string, (event: RawPerceptionEvent) => void>> = {
60-
sighted: {
61-
arm_swing: event => this.onPunch(event as any),
62-
sneak_toggle: event => this.onSneakToggle(event as any),
63-
entity_moved: event => this.onMove(event as any),
64-
},
65-
heard: {
66-
sound: event => this.onSound(event as any),
67-
},
68-
felt: {
69-
damage_taken: event => this.onDamage(event as any),
70-
item_collected: event => this.onPickup(event as any),
71-
},
72-
}
73-
dispatch[event.modality]?.[event.kind]?.(event)
74+
this.dispatch[event.modality]?.[event.kind]?.(event)
7475
}
7576

7677
private onPunch(event: Extract<RawPerceptionEvent, { modality: 'sighted', kind: 'arm_swing' }>): void {

0 commit comments

Comments
 (0)