2021-02-09 17:26:08 +00:00
|
|
|
import authorize_user_letters from "../../resources/authorize_user_letters.json";
|
2021-03-03 16:19:36 +00:00
|
|
|
import {
|
|
|
|
handleNameSelection,
|
|
|
|
handleUserAuthorizationMove,
|
|
|
|
} from "../../helpers/name-selection-helpers";
|
2021-02-20 14:35:23 +00:00
|
|
|
import {
|
|
|
|
changeMainMenuComponent,
|
|
|
|
changePromptComponent,
|
|
|
|
enterLoadData,
|
|
|
|
enterUserAuthorization,
|
|
|
|
exitLoadData,
|
|
|
|
exitUserAuthorization,
|
|
|
|
failUpdatePlayerName,
|
|
|
|
loadGame,
|
2021-02-23 17:04:53 +00:00
|
|
|
loadGameFail,
|
2021-02-20 14:35:23 +00:00
|
|
|
removePlayerNameLastChar,
|
|
|
|
startNewGame,
|
2021-03-02 16:37:14 +00:00
|
|
|
updateAuthorizeUserLetterMatrixIndices,
|
2021-02-20 14:35:23 +00:00
|
|
|
updatePlayerName,
|
|
|
|
} from "../eventTemplates";
|
2021-02-23 17:04:53 +00:00
|
|
|
import { BootSceneContext, GameEvent } from "../../types/types";
|
2021-02-09 17:26:08 +00:00
|
|
|
|
2021-02-25 17:47:42 +00:00
|
|
|
const handleBootSceneInput = (
|
|
|
|
bootSceneContext: BootSceneContext,
|
|
|
|
keyPress: string
|
2021-02-20 14:35:23 +00:00
|
|
|
): GameEvent | undefined => {
|
2021-02-08 17:53:28 +00:00
|
|
|
const {
|
|
|
|
subscene,
|
|
|
|
activeMainMenuComponent,
|
|
|
|
activePromptComponent,
|
|
|
|
promptVisible,
|
2021-02-09 17:26:08 +00:00
|
|
|
playerName,
|
2021-03-02 16:37:14 +00:00
|
|
|
authorizeUserMatrixIndices,
|
2021-02-08 17:53:28 +00:00
|
|
|
} = bootSceneContext;
|
|
|
|
|
|
|
|
if (promptVisible) {
|
|
|
|
switch (keyPress) {
|
|
|
|
case "LEFT":
|
2021-02-20 14:35:23 +00:00
|
|
|
return changePromptComponent({ activePromptComponent: "yes" });
|
2021-02-08 17:53:28 +00:00
|
|
|
case "RIGHT":
|
2021-02-20 14:35:23 +00:00
|
|
|
return changePromptComponent({ activePromptComponent: "no" });
|
2021-02-08 17:53:28 +00:00
|
|
|
case "CIRCLE":
|
|
|
|
switch (activePromptComponent) {
|
|
|
|
case "no":
|
2021-02-20 14:35:23 +00:00
|
|
|
return exitLoadData;
|
2021-02-08 17:53:28 +00:00
|
|
|
case "yes":
|
2021-02-23 17:04:53 +00:00
|
|
|
const stateToLoad = localStorage.getItem("lainSaveState");
|
|
|
|
|
|
|
|
if (stateToLoad)
|
|
|
|
return loadGame({
|
|
|
|
userSaveState: JSON.parse(stateToLoad),
|
|
|
|
});
|
|
|
|
else return loadGameFail;
|
2021-02-08 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (subscene) {
|
|
|
|
case "main_menu":
|
|
|
|
switch (keyPress) {
|
|
|
|
case "UP":
|
|
|
|
case "DOWN":
|
2021-02-20 14:35:23 +00:00
|
|
|
const newComponent =
|
|
|
|
keyPress === "UP" ? "authorize_user" : "load_data";
|
|
|
|
return changeMainMenuComponent({
|
|
|
|
activeMainMenuComponent: newComponent,
|
|
|
|
});
|
2021-02-08 17:53:28 +00:00
|
|
|
case "CIRCLE":
|
2021-02-20 14:35:23 +00:00
|
|
|
switch (activeMainMenuComponent) {
|
|
|
|
case "authorize_user":
|
|
|
|
return enterUserAuthorization;
|
|
|
|
case "load_data":
|
|
|
|
return enterLoadData;
|
|
|
|
}
|
2021-02-08 17:53:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case "authorize_user":
|
|
|
|
switch (keyPress) {
|
2021-02-10 16:05:20 +00:00
|
|
|
case "START":
|
2021-02-25 17:47:42 +00:00
|
|
|
if (playerName.length > 0) return startNewGame;
|
2021-02-20 14:35:23 +00:00
|
|
|
return;
|
2021-03-01 17:53:02 +00:00
|
|
|
case "CROSS":
|
2021-02-09 17:26:08 +00:00
|
|
|
if (playerName.length > 0) {
|
2021-02-20 14:35:23 +00:00
|
|
|
return removePlayerNameLastChar({
|
2021-02-09 17:26:08 +00:00
|
|
|
playerName: playerName.slice(0, -1),
|
2021-02-20 14:35:23 +00:00
|
|
|
});
|
2021-02-09 17:26:08 +00:00
|
|
|
} else {
|
2021-02-20 14:35:23 +00:00
|
|
|
return exitUserAuthorization;
|
2021-02-09 17:26:08 +00:00
|
|
|
}
|
2021-03-03 16:19:36 +00:00
|
|
|
case "LEFT":
|
|
|
|
case "UP":
|
|
|
|
case "DOWN":
|
|
|
|
case "RIGHT":
|
|
|
|
const direction = keyPress.toLowerCase();
|
|
|
|
const newMatrixIndices = handleUserAuthorizationMove(
|
|
|
|
authorizeUserMatrixIndices,
|
|
|
|
direction
|
|
|
|
);
|
2021-03-02 16:37:14 +00:00
|
|
|
|
2021-03-03 16:19:36 +00:00
|
|
|
if (newMatrixIndices)
|
|
|
|
return updateAuthorizeUserLetterMatrixIndices({
|
|
|
|
authorizeUserLetterMatrixIndices: newMatrixIndices,
|
|
|
|
});
|
|
|
|
break;
|
2021-02-09 17:26:08 +00:00
|
|
|
case "CIRCLE":
|
|
|
|
const chosenCharacter =
|
2021-03-02 16:37:14 +00:00
|
|
|
authorize_user_letters.matrix[authorizeUserMatrixIndices.rowIdx][
|
|
|
|
authorizeUserMatrixIndices.colIdx
|
2021-02-09 17:26:08 +00:00
|
|
|
];
|
|
|
|
|
2021-03-02 16:37:14 +00:00
|
|
|
if (chosenCharacter) {
|
|
|
|
const newName = handleNameSelection(playerName, chosenCharacter);
|
2021-02-09 17:26:08 +00:00
|
|
|
|
2021-03-03 16:19:36 +00:00
|
|
|
if (newName && newName.length > 8) return;
|
2021-03-02 16:37:14 +00:00
|
|
|
if (newName !== undefined)
|
|
|
|
return updatePlayerName({ playerName: newName });
|
|
|
|
else return failUpdatePlayerName;
|
|
|
|
}
|
2021-02-08 17:53:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-02-25 17:47:42 +00:00
|
|
|
export default handleBootSceneInput;
|