generated from jacklehamster/bun-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Controls so that we can support other controls than Keyboard.
- Loading branch information
1 parent
aceaa73
commit d08c99d
Showing
26 changed files
with
25,474 additions
and
2,785 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface ControlsListener { | ||
onQuickAction?(): void; | ||
onQuickTiltReset?(): void; | ||
} | ||
|
||
export interface IControls { | ||
get forward(): boolean; | ||
get backward(): boolean; | ||
get left(): boolean; | ||
get right(): boolean; | ||
get up(): boolean; | ||
get down(): boolean; | ||
get turnLeft(): boolean; | ||
get turnRight(): boolean; | ||
get action(): boolean; | ||
addListener(listener: ControlsListener): () => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { ControlsListener, IControls } from "./IControls"; | ||
import { IKeyboard } from "./IKeyboard"; | ||
|
||
export class KeyboardControls implements IControls { | ||
constructor(private keyboard: IKeyboard) { | ||
} | ||
|
||
addListener(listener: ControlsListener): () => void { | ||
return this.keyboard.addListener({ | ||
onQuickTap(keyCode) { | ||
switch (keyCode) { | ||
case 'Space': | ||
listener.onQuickAction?.(); | ||
break; | ||
case 'ShiftRight': | ||
listener.onQuickTiltReset?.(); | ||
break; | ||
} | ||
}, | ||
}); | ||
} | ||
|
||
get forward(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyW || (keys.ArrowUp && !keys.ShiftRight)); | ||
} | ||
|
||
get backward(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyS || (keys.ArrowDown && !keys.ShiftRight)); | ||
} | ||
|
||
get left(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyA || (keys.ArrowLeft && !keys.ShiftRight)); | ||
} | ||
|
||
get right(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyD || (keys.ArrowRight && !keys.ShiftRight)); | ||
} | ||
|
||
get turnLeft(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyQ || (keys.ArrowLeft && keys.ShiftRight)); | ||
} | ||
|
||
get turnRight(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.KeyE || (keys.ArrowRight && keys.ShiftRight)); | ||
} | ||
|
||
get up(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.ArrowUp && keys.ShiftRight); | ||
} | ||
|
||
get down(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.ArrowDown && keys.ShiftRight); | ||
} | ||
|
||
get action(): boolean { | ||
const { keys } = this.keyboard; | ||
return !!(keys.Space); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.