Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kiosk: map controller Y to escapebutton functionality #9741

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kiosk/src/Components/AddingGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ const AddingGame: React.FC<IProps> = ({}) => {
showMainMenu();
};

// Handle Escape button press
// Handle Back button press
useOnControlPress(
[],
gotoMainMenu,
GamepadManager.GamepadControl.EscapeButton,
GamepadManager.GamepadControl.BackButton,
GamepadManager.GamepadControl.BButton
);

Expand Down
2 changes: 1 addition & 1 deletion kiosk/src/Components/AppModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function AppModal() {

const hideAppModal = () => {
GamepadManager.lockControl(GamepadManager.GamepadControl.AButton);
GamepadManager.lockControl(GamepadManager.GamepadControl.EscapeButton);
GamepadManager.lockControl(GamepadManager.GamepadControl.BackButton);
dispatch(hideModal());
};

Expand Down
4 changes: 2 additions & 2 deletions kiosk/src/Components/GameOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const GameOver: React.FC<IProps> = ({}) => {
showMainMenu();
};

// Handle Escape button press
// Handle Back button press
useOnControlPress(
[],
gotoMainMenu,
GamepadManager.GamepadControl.EscapeButton
GamepadManager.GamepadControl.BackButton
);

return (
Expand Down
2 changes: 1 addition & 1 deletion kiosk/src/Components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const Modal = (props: ModalProps) => {
() => {
onClose?.();
},
GamepadManager.GamepadControl.EscapeButton
GamepadManager.GamepadControl.BackButton
);

const classes = classList("common-modal-container", className);
Expand Down
4 changes: 2 additions & 2 deletions kiosk/src/Components/NewScoreEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const NewScoreEntry: React.FC<IProps> = ({}) => {
GamepadManager.GamepadControl.BButton
);

// Handle Escape button press
// Handle Back button press
useOnControlPress(
[kiosk],
() => {
Expand All @@ -54,7 +54,7 @@ const NewScoreEntry: React.FC<IProps> = ({}) => {
);
navigate(KioskState.GameOver);
},
GamepadManager.GamepadControl.EscapeButton
GamepadManager.GamepadControl.BackButton
);

// Handle all initials entered
Expand Down
6 changes: 3 additions & 3 deletions kiosk/src/Components/PlayingGame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export default function PlayingGame() {
const { state: kiosk, dispatch } = useContext(AppStateContext);
const { launchedGameId: gameId } = kiosk;

// Handle Escape and Menu button presses
// Handle Back and Start button presses
useOnControlPress(
[],
() => {
playSoundEffect("select");
escapeGame();
},
GamepadManager.GamepadControl.EscapeButton,
GamepadManager.GamepadControl.ResetButton
GamepadManager.GamepadControl.BackButton,
GamepadManager.GamepadControl.StartButton
);

const playUrl = useMemo(() => {
Expand Down
73 changes: 41 additions & 32 deletions kiosk/src/Services/GamepadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export enum GamepadControl {
DPadLeft = "DPadLeft",
DPadRight = "DPadRight",
MenuButton = "MenuButton",
EscapeButton = "EscapeButton",
ResetButton = "ResetButton",
BackButton = "BackButton",
StartButton = "StartButton",
}

enum GamepadAxis {
Expand All @@ -21,16 +21,19 @@ enum GamepadAxis {
Right = "Right",
}

const gamepadControlToPinIndex: { [key in GamepadControl]: number } = {
[GamepadControl.AButton]: configData.GamepadAButtonPin,
[GamepadControl.BButton]: configData.GamepadBButtonPin,
[GamepadControl.DPadUp]: configData.GamepadDpadUpButtonPin,
[GamepadControl.DPadDown]: configData.GamepadDpadDownButtonPin,
[GamepadControl.DPadLeft]: configData.GamepadDpadLeftButtonPin,
[GamepadControl.DPadRight]: configData.GamepadDpadRightButtonPin,
[GamepadControl.MenuButton]: configData.GamepadMenuButtonPin,
[GamepadControl.EscapeButton]: configData.GamepadEscapeButtonPin,
[GamepadControl.ResetButton]: configData.GamepadResetButtonPin,
const gamepadControlToPinIndices: { [key in GamepadControl]: number[] } = {
[GamepadControl.AButton]: [configData.GamepadAButtonPin],
[GamepadControl.BButton]: [configData.GamepadBButtonPin],
[GamepadControl.DPadUp]: [configData.GamepadDpadUpButtonPin],
[GamepadControl.DPadDown]: [configData.GamepadDpadDownButtonPin],
[GamepadControl.DPadLeft]: [configData.GamepadDpadLeftButtonPin],
[GamepadControl.DPadRight]: [configData.GamepadDpadRightButtonPin],
[GamepadControl.MenuButton]: [configData.GamepadMenuButtonPin],
[GamepadControl.BackButton]: [
configData.GamepadBackButtonPin,
configData.GamepadYButtonPin,
],
[GamepadControl.StartButton]: [configData.GamepadStartButtonPin],
};

const gamepadControlToAxis: { [key in GamepadControl]: GamepadAxis } = {
Expand All @@ -41,8 +44,8 @@ const gamepadControlToAxis: { [key in GamepadControl]: GamepadAxis } = {
[GamepadControl.DPadLeft]: GamepadAxis.Left,
[GamepadControl.DPadRight]: GamepadAxis.Right,
[GamepadControl.MenuButton]: GamepadAxis.None,
[GamepadControl.EscapeButton]: GamepadAxis.None,
[GamepadControl.ResetButton]: GamepadAxis.None,
[GamepadControl.BackButton]: GamepadAxis.None,
[GamepadControl.StartButton]: GamepadAxis.None,
};

export enum ControlValue {
Expand All @@ -69,9 +72,9 @@ export const emptyControlStates = (): ControlStates => ({
[GamepadControl.DPadLeft]: ControlValue.Up,
[GamepadControl.DPadRight]: ControlValue.Up,
[GamepadControl.DPadUp]: ControlValue.Up,
[GamepadControl.EscapeButton]: ControlValue.Up,
[GamepadControl.BackButton]: ControlValue.Up,
[GamepadControl.MenuButton]: ControlValue.Up,
[GamepadControl.ResetButton]: ControlValue.Up,
[GamepadControl.StartButton]: ControlValue.Up,
});

const emptyControlCooldowns = (): ControlCooldowns => ({
Expand All @@ -81,9 +84,9 @@ const emptyControlCooldowns = (): ControlCooldowns => ({
[GamepadControl.DPadLeft]: 0,
[GamepadControl.DPadRight]: 0,
[GamepadControl.DPadUp]: 0,
[GamepadControl.EscapeButton]: 0,
[GamepadControl.BackButton]: 0,
[GamepadControl.MenuButton]: 0,
[GamepadControl.ResetButton]: 0,
[GamepadControl.StartButton]: 0,
});

const emptyControlLocks = (): ControlLocks => ({
Expand All @@ -93,9 +96,9 @@ const emptyControlLocks = (): ControlLocks => ({
[GamepadControl.DPadLeft]: false,
[GamepadControl.DPadRight]: false,
[GamepadControl.DPadUp]: false,
[GamepadControl.EscapeButton]: false,
[GamepadControl.BackButton]: false,
[GamepadControl.MenuButton]: false,
[GamepadControl.ResetButton]: false,
[GamepadControl.StartButton]: false,
});

type GamepadState = {
Expand Down Expand Up @@ -131,9 +134,9 @@ class GamepadManager {
this.minButtonPinRequired = Math.max(
configData.GamepadAButtonPin,
configData.GamepadBButtonPin,
configData.GamepadEscapeButtonPin,
configData.GamepadBackButtonPin,
configData.GamepadMenuButtonPin,
configData.GamepadResetButtonPin
configData.GamepadStartButtonPin
);

this.minAxisRequired = Math.max(
Expand Down Expand Up @@ -307,13 +310,13 @@ class GamepadManager {
gamepad,
GamepadControl.MenuButton
),
[GamepadControl.EscapeButton]: this.readGamepadButtonValue(
[GamepadControl.BackButton]: this.readGamepadButtonValue(
gamepad,
GamepadControl.EscapeButton
GamepadControl.BackButton
),
[GamepadControl.ResetButton]: this.readGamepadButtonValue(
[GamepadControl.StartButton]: this.readGamepadButtonValue(
gamepad,
GamepadControl.ResetButton
GamepadControl.StartButton
),
};
}
Expand Down Expand Up @@ -501,12 +504,18 @@ class GamepadManager {
gamepad: Gamepad,
control: GamepadControl
): ControlValue {
const pinIndex = gamepadControlToPinIndex[control];
if (pinIndex < 0 || pinIndex >= gamepad.buttons.length)
return ControlValue.Up;
return gamepad.buttons[pinIndex].pressed
? ControlValue.Down
: ControlValue.Up;
const pinIndices = gamepadControlToPinIndices[control];
let result = ControlValue.Up;
for (let pinIndex of pinIndices) {
if (pinIndex < 0 || pinIndex >= gamepad.buttons.length) continue;
result = this.mergeControlValues(
result,
gamepad.buttons[pinIndex].pressed
? ControlValue.Down
: ControlValue.Up
);
}
return result;
}

readGamepadDirectionValue(
Expand Down
8 changes: 4 additions & 4 deletions kiosk/src/Services/SimHostService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ export function initialize() {

// Look for the high scores reset combo
if (
controlStates[GamepadManager.GamepadControl.ResetButton] &&
controlStates[GamepadManager.GamepadControl.EscapeButton] &&
controlStates[GamepadManager.GamepadControl.StartButton] &&
controlStates[GamepadManager.GamepadControl.BackButton] &&
controlStates[GamepadManager.GamepadControl.BButton] &&
controlStates[GamepadManager.GamepadControl.DPadLeft]
) {
// Lock the combo so it doesn't get triggered repeatedly
GamepadManager.lockControl(
GamepadManager.GamepadControl.ResetButton
GamepadManager.GamepadControl.StartButton
);
GamepadManager.lockControl(
GamepadManager.GamepadControl.EscapeButton
GamepadManager.GamepadControl.BackButton
);
GamepadManager.lockControl(GamepadManager.GamepadControl.BButton);
GamepadManager.lockControl(GamepadManager.GamepadControl.DPadLeft);
Expand Down
4 changes: 2 additions & 2 deletions kiosk/src/Transforms/navigate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { playSoundEffect } from "../Services/SoundEffectService";
export function navigate(nextState: KioskState) {
const { dispatch } = stateAndDispatch();
pxt.tickEvent("kiosk.navigate." + nextState.toLowerCase());
// Lock the A button and Escape button to prevent accidental navigation upon entering the new state
// Lock the A button and Back button to prevent accidental navigation upon entering the new state
GamepadManager.lockControl(GamepadManager.GamepadControl.AButton);
GamepadManager.lockControl(GamepadManager.GamepadControl.EscapeButton);
GamepadManager.lockControl(GamepadManager.GamepadControl.BackButton);
playSoundEffect("select");
//NavGrid.resetUserInteraction();
// As a general safety measure, wait one frame before changing screens to allow any pending reducer
Expand Down
16 changes: 9 additions & 7 deletions kiosk/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"GamepadOnHeldCooldownMilli": 167,
"GamepadAButtonPin": 0,
"GamepadBButtonPin": 1,
"GamepadEscapeButtonPin": 8,
"GamepadResetButtonPin": 10,
"GamepadXButtonPin": 2,
"GamepadYButtonPin": 3,
"GamepadBackButtonPin": 8,
"GamepadStartButtonPin": 10,
"GamepadDpadUpButtonPin": 12,
"GamepadDpadDownButtonPin": 13,
"GamepadDpadLeftButtonPin": 14,
Expand Down Expand Up @@ -49,8 +51,8 @@
"GamepadControlToKeyboardKeyMap": {
"AButton": "Space",
"BButton": "Enter",
"EscapeButton": "Escape",
"ResetButton": "2",
"BackButton": "Escape",
"StartButton": "2",
"MenuButton": "1",
"DPadLeft": "ArrowLeft",
"DPadRight": "ArrowRight",
Expand All @@ -72,8 +74,8 @@
{
"Space": "AButton",
"Enter": "BButton",
"Escape": "EscapeButton",
"2": "ResetButton",
"Escape": "BackButton",
"2": "StartButton",
"1": "MenuButton",
"ArrowLeft": "DPadLeft",
"ArrowRight": "DPadRight",
Expand All @@ -86,7 +88,7 @@
"Right": "DPadRight",
"Up": "DPadUp",
"Down": "DPadDown",
"Esc": "EscapeButton"
"Esc": "BackButton"
},
{
"z": "AButton",
Expand Down
Loading