mirror of
https://github.com/ad044/lainTSX.git
synced 2024-10-22 23:19:06 +00:00
minimal tests for input handlers
This commit is contained in:
parent
851b3ff597
commit
918ee5da13
15 changed files with 435 additions and 83 deletions
|
@ -13,7 +13,7 @@ import TaKScene from "./scenes/TaKScene";
|
||||||
import ChangeDiscScene from "./scenes/ChangeDiscScene";
|
import ChangeDiscScene from "./scenes/ChangeDiscScene";
|
||||||
import EndScene from "./scenes/EndScene";
|
import EndScene from "./scenes/EndScene";
|
||||||
import IdleMediaScene from "./scenes/IdleMediaScene";
|
import IdleMediaScene from "./scenes/IdleMediaScene";
|
||||||
import KeyPressHandler from "./components/KeyPressHandler";
|
import InputHandler from "./components/InputHandler";
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const currentScene = useStore((state) => state.currentScene);
|
const currentScene = useStore((state) => state.currentScene);
|
||||||
|
@ -43,7 +43,7 @@ const App = () => {
|
||||||
<div id="game-root" className="game">
|
<div id="game-root" className="game">
|
||||||
<span className="canvas">
|
<span className="canvas">
|
||||||
<Canvas concurrent>
|
<Canvas concurrent>
|
||||||
<KeyPressHandler />
|
<InputHandler />
|
||||||
<Suspense fallback={null}>
|
<Suspense fallback={null}>
|
||||||
{/*<Preloader />*/}
|
{/*<Preloader />*/}
|
||||||
{dispatchScene[currentScene as keyof typeof dispatchScene]}
|
{dispatchScene[currentScene as keyof typeof dispatchScene]}
|
||||||
|
|
88
src/__tests__/input-handlers/handleBootSceneInput.test.ts
Normal file
88
src/__tests__/input-handlers/handleBootSceneInput.test.ts
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
import * as eventTemplates from "../../core/eventTemplates";
|
||||||
|
import { getBootSceneContext } from "../../store";
|
||||||
|
import handleBootSceneInput from "../../core/input-handlers/handleBootSceneInput";
|
||||||
|
import {
|
||||||
|
enterLoadData,
|
||||||
|
enterUserAuthorization,
|
||||||
|
exitUserAuthorization,
|
||||||
|
startNewGame,
|
||||||
|
} from "../../core/eventTemplates";
|
||||||
|
import {
|
||||||
|
BootSceneContext,
|
||||||
|
BootSubscene,
|
||||||
|
MainMenuComponent,
|
||||||
|
} from "../../types/types";
|
||||||
|
|
||||||
|
it("Checks whether or not the boot scene input handler reacts appropriately for each input", () => {
|
||||||
|
{
|
||||||
|
// change main menu active component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeMainMenuComponent");
|
||||||
|
const testContext = getBootSceneContext();
|
||||||
|
handleBootSceneInput(testContext, "UP");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
// select main menu component
|
||||||
|
{
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
activeMainMenuComponent: "authorize_user" as MainMenuComponent,
|
||||||
|
};
|
||||||
|
expect(handleBootSceneInput(testContext, "CIRCLE")).toEqual(
|
||||||
|
enterUserAuthorization
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
activeMainMenuComponent: "load_data" as MainMenuComponent,
|
||||||
|
};
|
||||||
|
expect(handleBootSceneInput(testContext, "CIRCLE")).toEqual(enterLoadData);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// change letter in authorize user scene
|
||||||
|
const spy = jest.spyOn(eventTemplates, "updateAuthorizeUserLetterIdx");
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
subscene: "authorize_user" as BootSubscene,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleBootSceneInput(testContext, "RIGHT");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// start new game
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
subscene: "authorize_user" as BootSubscene,
|
||||||
|
playerName: "チ",
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(handleBootSceneInput(testContext, "START")).toEqual(startNewGame);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// delete last char if player name is not empty
|
||||||
|
const spy = jest.spyOn(eventTemplates, "removePlayerNameLastChar");
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
subscene: "authorize_user" as BootSubscene,
|
||||||
|
playerName: "チ",
|
||||||
|
};
|
||||||
|
|
||||||
|
handleBootSceneInput(testContext, "X");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// go back to main menu if player name is empty
|
||||||
|
const testContext = {
|
||||||
|
...getBootSceneContext(),
|
||||||
|
subscene: "authorize_user" as BootSubscene,
|
||||||
|
playerName: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(handleBootSceneInput(testContext, "X")).toEqual(
|
||||||
|
exitUserAuthorization
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
38
src/__tests__/input-handlers/handleEndSceneInput.test.ts
Normal file
38
src/__tests__/input-handlers/handleEndSceneInput.test.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import * as eventTemplates from "../../core/eventTemplates";
|
||||||
|
import { getEndSceneContext } from "../../store";
|
||||||
|
import handleEndSceneInput from "../../core/input-handlers/handleEndSceneInput";
|
||||||
|
import { EndComponent } from "../../types/types";
|
||||||
|
|
||||||
|
it("Checks whether or not the end scene input handler reacts appropriately for each input", () => {
|
||||||
|
{
|
||||||
|
// changing end active component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeEndComponent");
|
||||||
|
const testContext = { ...getEndSceneContext(), selectionVisible: true };
|
||||||
|
|
||||||
|
handleEndSceneInput(testContext, "DOWN");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
// selecting end component
|
||||||
|
{
|
||||||
|
const spy = jest.spyOn(eventTemplates, "endGame");
|
||||||
|
const testContext = { ...getEndSceneContext(), selectionVisible: true };
|
||||||
|
|
||||||
|
handleEndSceneInput(testContext, "CIRCLE");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeSite");
|
||||||
|
const testContext = {
|
||||||
|
...getEndSceneContext(),
|
||||||
|
selectionVisible: true,
|
||||||
|
activeEndComponent: "continue" as EndComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleEndSceneInput(testContext, "CIRCLE");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
131
src/__tests__/input-handlers/handleMainSceneInput.test.ts
Normal file
131
src/__tests__/input-handlers/handleMainSceneInput.test.ts
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
import { getMainSceneContext } from "../../store";
|
||||||
|
import handleMainSceneInput from "../../core/input-handlers/handleMainSceneInput";
|
||||||
|
import * as eventTemplates from "../../core/eventTemplates";
|
||||||
|
import site_a from "../../resources/site_a.json";
|
||||||
|
import {
|
||||||
|
enterLevelSelection,
|
||||||
|
pauseGame,
|
||||||
|
ripNode,
|
||||||
|
showAbout,
|
||||||
|
throwNode,
|
||||||
|
} from "../../core/eventTemplates";
|
||||||
|
import { nodeToScene } from "../../helpers/node-helpers";
|
||||||
|
import { PauseComponent } from "../../types/types";
|
||||||
|
|
||||||
|
const expectOr = (...tests: (() => void)[]) => {
|
||||||
|
try {
|
||||||
|
tests.shift()!();
|
||||||
|
} catch (e) {
|
||||||
|
if (tests.length) expectOr(...tests);
|
||||||
|
else throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
it("Checks whether or not the main scene input handler reacts appropriately for each input", () => {
|
||||||
|
{
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeNode");
|
||||||
|
const testContext = getMainSceneContext();
|
||||||
|
handleMainSceneInput(testContext, "UP");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// move vertically when utmost up node is currently selected
|
||||||
|
const spy = jest.spyOn(eventTemplates, "siteMoveVertical");
|
||||||
|
const testContext = {
|
||||||
|
...getMainSceneContext(),
|
||||||
|
activeNode: {
|
||||||
|
...site_a["04"]["0422"],
|
||||||
|
matrixIndices: { matrixIdx: 7, rowIdx: 0, colIdx: 0 },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
handleMainSceneInput(testContext, "UP");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// move horizontally when utmost left node is currently selected
|
||||||
|
const spy = jest.spyOn(eventTemplates, "siteMoveHorizontal");
|
||||||
|
const testContext = getMainSceneContext();
|
||||||
|
handleMainSceneInput(testContext, "LEFT");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// play throw node/rip node animation and set the scene when the player selects a node
|
||||||
|
const testContext = getMainSceneContext();
|
||||||
|
|
||||||
|
const output = handleMainSceneInput(testContext, "CIRCLE");
|
||||||
|
expectOr(
|
||||||
|
() =>
|
||||||
|
expect(output).toEqual(
|
||||||
|
ripNode({ currentScene: nodeToScene(testContext.activeNode)! })
|
||||||
|
),
|
||||||
|
() =>
|
||||||
|
expect(output).toEqual(
|
||||||
|
throwNode({ currentScene: nodeToScene(testContext.activeNode)! })
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// entering level selection
|
||||||
|
const testContext = getMainSceneContext();
|
||||||
|
|
||||||
|
expect(handleMainSceneInput(testContext, "L2")).toEqual(
|
||||||
|
enterLevelSelection({ selectedLevel: testContext.level })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// entering pause
|
||||||
|
const testContext = getMainSceneContext();
|
||||||
|
|
||||||
|
expect(handleMainSceneInput(testContext, "TRIANGLE")).toEqual(
|
||||||
|
pauseGame({ siteRot: [Math.PI / 2, testContext.siteRotY, 0] })
|
||||||
|
);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// changing level inside level selection
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeSelectedLevel");
|
||||||
|
|
||||||
|
const testContext = {
|
||||||
|
...getMainSceneContext(),
|
||||||
|
subscene: "level_selection",
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMainSceneInput(testContext, "UP");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// selecting new level when currently below it
|
||||||
|
|
||||||
|
const spy = jest.spyOn(eventTemplates, "selectLevel");
|
||||||
|
const testContext = {
|
||||||
|
...getMainSceneContext(),
|
||||||
|
selectedLevel: 10,
|
||||||
|
subscene: "level_selection",
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMainSceneInput(testContext, "CIRCLE");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// changing pause active component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changePauseComponent");
|
||||||
|
const testContext = {
|
||||||
|
...getMainSceneContext(),
|
||||||
|
subscene: "pause",
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMainSceneInput(testContext, "UP");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// selecting pause component
|
||||||
|
const testContext = {
|
||||||
|
...getMainSceneContext(),
|
||||||
|
subscene: "pause",
|
||||||
|
activePauseComponent: "about" as PauseComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(handleMainSceneInput(testContext, "CIRCLE")).toEqual(showAbout);
|
||||||
|
}
|
||||||
|
});
|
72
src/__tests__/input-handlers/handleMediaSceneInput.test.ts
Normal file
72
src/__tests__/input-handlers/handleMediaSceneInput.test.ts
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import * as eventTemplates from "../../core/eventTemplates";
|
||||||
|
import { getMediaSceneContext } from "../../store";
|
||||||
|
import handleMediaSceneInput from "../../core/input-handlers/handleMediaSceneInput";
|
||||||
|
import { exitMedia } from "../../core/eventTemplates";
|
||||||
|
import {
|
||||||
|
LeftMediaComponent,
|
||||||
|
MediaSide,
|
||||||
|
RightMediaComponent,
|
||||||
|
} from "../../types/types";
|
||||||
|
|
||||||
|
it("Checks whether or not the media scene input handler reacts appropriately for each input", () => {
|
||||||
|
{
|
||||||
|
// changing left side media active component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeLeftMediaComponent");
|
||||||
|
const testContext = getMediaSceneContext();
|
||||||
|
|
||||||
|
handleMediaSceneInput(testContext, "DOWN");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// changing media side from left to right
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeMediaSide");
|
||||||
|
const testContext = getMediaSceneContext();
|
||||||
|
|
||||||
|
handleMediaSceneInput(testContext, "RIGHT");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// exit media
|
||||||
|
const testContext = {
|
||||||
|
...getMediaSceneContext(),
|
||||||
|
activeMediaComponent: "exit" as LeftMediaComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(handleMediaSceneInput(testContext, "CIRCLE")).toEqual(exitMedia);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// play media
|
||||||
|
const spy = jest.spyOn(eventTemplates, "playMedia");
|
||||||
|
const testContext = getMediaSceneContext();
|
||||||
|
handleMediaSceneInput(testContext, "CIRCLE");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// change right side media component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeRightMediaComponent");
|
||||||
|
const testContext = {
|
||||||
|
...getMediaSceneContext(),
|
||||||
|
currentMediaSide: "right" as MediaSide,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMediaSceneInput(testContext, "DOWN");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// change from right side to left
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeMediaSide");
|
||||||
|
const testContext = {
|
||||||
|
...getMediaSceneContext(),
|
||||||
|
currentMediaSide: "right" as MediaSide,
|
||||||
|
};
|
||||||
|
|
||||||
|
handleMediaSceneInput(testContext, "LEFT");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
34
src/__tests__/input-handlers/handleSsknSceneInput.test.ts
Normal file
34
src/__tests__/input-handlers/handleSsknSceneInput.test.ts
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
import * as eventTemplates from "../../core/eventTemplates";
|
||||||
|
import { getSsknSceneContext } from "../../store";
|
||||||
|
import handleSsknSceneInput from "../../core/input-handlers/handleSsknSceneInput";
|
||||||
|
import { exitSskn } from "../../core/eventTemplates";
|
||||||
|
import { SsknComponent } from "../../types/types";
|
||||||
|
|
||||||
|
it("Checks whether or not the sskn scene input handler reacts appropriately for each input", () => {
|
||||||
|
{
|
||||||
|
// changing sskn active component
|
||||||
|
const spy = jest.spyOn(eventTemplates, "changeSsknComponent");
|
||||||
|
const testContext = getSsknSceneContext();
|
||||||
|
|
||||||
|
handleSsknSceneInput(testContext, "DOWN");
|
||||||
|
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// select ok
|
||||||
|
const spy = jest.spyOn(eventTemplates, "upgradeSskn");
|
||||||
|
const testContext = getSsknSceneContext();
|
||||||
|
|
||||||
|
handleSsknSceneInput(testContext, "CIRCLE");
|
||||||
|
expect(spy).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
{
|
||||||
|
// select cancel
|
||||||
|
const testContext = {
|
||||||
|
...getSsknSceneContext(),
|
||||||
|
activeSsknComponent: "cancel" as SsknComponent,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(handleSsknSceneInput(testContext, "CIRCLE")).toEqual(exitSskn);
|
||||||
|
}
|
||||||
|
});
|
|
@ -9,18 +9,18 @@ import {
|
||||||
useStore,
|
useStore,
|
||||||
} from "../store";
|
} from "../store";
|
||||||
import { getKeyCodeAssociation } from "../utils/parseUserInput";
|
import { getKeyCodeAssociation } from "../utils/parseUserInput";
|
||||||
import handleMediaSceneKeyPress from "../core/scene-keypress-handlers/handleMediaSceneKeyPress";
|
import handleMediaSceneInput from "../core/input-handlers/handleMediaSceneInput";
|
||||||
import handleSsknSceneKeyPress from "../core/scene-keypress-handlers/handleSsknSceneKeyPress";
|
import handleSsknSceneInput from "../core/input-handlers/handleSsknSceneInput";
|
||||||
import handleMainSceneKeyPress from "../core/scene-keypress-handlers/handleMainSceneKeyPress";
|
import handleMainSceneInput from "../core/input-handlers/handleMainSceneInput";
|
||||||
import handleBootSceneKeyPress from "../core/scene-keypress-handlers/handleBootSceneKeyPress";
|
import handleBootSceneInput from "../core/input-handlers/handleBootSceneInput";
|
||||||
import { useFrame } from "react-three-fiber";
|
import { useFrame } from "react-three-fiber";
|
||||||
import { getRandomIdleLainAnim } from "../helpers/idle-helpers";
|
import { getRandomIdleLainAnim } from "../helpers/idle-helpers";
|
||||||
import * as audio from "../static/audio/sfx";
|
import * as audio from "../static/audio/sfx";
|
||||||
import handleEndSceneKeyPress from "../core/scene-keypress-handlers/handleEndSceneKeyPress";
|
import handleEndSceneInput from "../core/input-handlers/handleEndSceneInput";
|
||||||
import handleEvent from "../core/handleEvent";
|
import handleEvent from "../core/handleEvent";
|
||||||
import { GameEvent } from "../types/types";
|
import { GameEvent } from "../types/types";
|
||||||
|
|
||||||
const KeyPressHandler = () => {
|
const InputHandler = () => {
|
||||||
const scene = useStore((state) => state.currentScene);
|
const scene = useStore((state) => state.currentScene);
|
||||||
const mainSubscene = useStore((state) => state.mainSubscene);
|
const mainSubscene = useStore((state) => state.mainSubscene);
|
||||||
const inputCooldown = useStore((state) => state.inputCooldown);
|
const inputCooldown = useStore((state) => state.inputCooldown);
|
||||||
|
@ -90,27 +90,27 @@ const KeyPressHandler = () => {
|
||||||
case "main":
|
case "main":
|
||||||
return {
|
return {
|
||||||
contextProvider: getMainSceneContext,
|
contextProvider: getMainSceneContext,
|
||||||
keyPressHandler: handleMainSceneKeyPress,
|
keyPressHandler: handleMainSceneInput,
|
||||||
};
|
};
|
||||||
case "media":
|
case "media":
|
||||||
return {
|
return {
|
||||||
contextProvider: getMediaSceneContext,
|
contextProvider: getMediaSceneContext,
|
||||||
keyPressHandler: handleMediaSceneKeyPress,
|
keyPressHandler: handleMediaSceneInput,
|
||||||
};
|
};
|
||||||
case "sskn":
|
case "sskn":
|
||||||
return {
|
return {
|
||||||
contextProvider: getSsknSceneContext,
|
contextProvider: getSsknSceneContext,
|
||||||
keyPressHandler: handleSsknSceneKeyPress,
|
keyPressHandler: handleSsknSceneInput,
|
||||||
};
|
};
|
||||||
case "boot":
|
case "boot":
|
||||||
return {
|
return {
|
||||||
contextProvider: getBootSceneContext,
|
contextProvider: getBootSceneContext,
|
||||||
keyPressHandler: handleBootSceneKeyPress,
|
keyPressHandler: handleBootSceneInput,
|
||||||
};
|
};
|
||||||
case "end":
|
case "end":
|
||||||
return {
|
return {
|
||||||
contextProvider: getEndSceneContext,
|
contextProvider: getEndSceneContext,
|
||||||
keyPressHandler: handleEndSceneKeyPress,
|
keyPressHandler: handleEndSceneInput,
|
||||||
};
|
};
|
||||||
case "gate":
|
case "gate":
|
||||||
case "polytan":
|
case "polytan":
|
||||||
|
@ -128,8 +128,11 @@ const KeyPressHandler = () => {
|
||||||
if (sceneFns) {
|
if (sceneFns) {
|
||||||
const { contextProvider, keyPressHandler } = sceneFns;
|
const { contextProvider, keyPressHandler } = sceneFns;
|
||||||
|
|
||||||
const ctx = contextProvider(keyPress);
|
const ctx = contextProvider();
|
||||||
const event: GameEvent | undefined = keyPressHandler(ctx as any);
|
const event: GameEvent | undefined = keyPressHandler(
|
||||||
|
ctx as any,
|
||||||
|
keyPress
|
||||||
|
);
|
||||||
if (event) handleEvent(event);
|
if (event) handleEvent(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,4 +151,4 @@ const KeyPressHandler = () => {
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default KeyPressHandler;
|
export default InputHandler;
|
|
@ -17,11 +17,11 @@ import {
|
||||||
} from "../eventTemplates";
|
} from "../eventTemplates";
|
||||||
import { BootSceneContext, GameEvent } from "../../types/types";
|
import { BootSceneContext, GameEvent } from "../../types/types";
|
||||||
|
|
||||||
const handleBootSceneKeyPress = (
|
const handleBootSceneInput = (
|
||||||
bootSceneContext: BootSceneContext
|
bootSceneContext: BootSceneContext,
|
||||||
|
keyPress: string
|
||||||
): GameEvent | undefined => {
|
): GameEvent | undefined => {
|
||||||
const {
|
const {
|
||||||
keyPress,
|
|
||||||
subscene,
|
subscene,
|
||||||
activeMainMenuComponent,
|
activeMainMenuComponent,
|
||||||
activePromptComponent,
|
activePromptComponent,
|
||||||
|
@ -73,9 +73,7 @@ const handleBootSceneKeyPress = (
|
||||||
case "authorize_user":
|
case "authorize_user":
|
||||||
switch (keyPress) {
|
switch (keyPress) {
|
||||||
case "START":
|
case "START":
|
||||||
if (playerName.length > 0) {
|
if (playerName.length > 0) return startNewGame;
|
||||||
return startNewGame;
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
case "X":
|
case "X":
|
||||||
if (playerName.length > 0) {
|
if (playerName.length > 0) {
|
||||||
|
@ -202,4 +200,4 @@ const handleBootSceneKeyPress = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleBootSceneKeyPress;
|
export default handleBootSceneInput;
|
|
@ -2,11 +2,11 @@ import { changeEndComponent, changeSite, endGame } from "../eventTemplates";
|
||||||
import { EndSceneContext, GameEvent } from "../../types/types";
|
import { EndSceneContext, GameEvent } from "../../types/types";
|
||||||
import { getCurrentUserState } from "../../store";
|
import { getCurrentUserState } from "../../store";
|
||||||
|
|
||||||
const handleEndSceneKeyPress = (
|
const handleEndSceneInput = (
|
||||||
endSceneContext: EndSceneContext
|
endSceneContext: EndSceneContext,
|
||||||
|
keyPress: string
|
||||||
): GameEvent | undefined => {
|
): GameEvent | undefined => {
|
||||||
const {
|
const {
|
||||||
keyPress,
|
|
||||||
selectionVisible,
|
selectionVisible,
|
||||||
activeEndComponent,
|
activeEndComponent,
|
||||||
siteSaveState,
|
siteSaveState,
|
||||||
|
@ -49,4 +49,4 @@ const handleEndSceneKeyPress = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleEndSceneKeyPress;
|
export default handleEndSceneInput;
|
|
@ -2,6 +2,7 @@ import {
|
||||||
findNode,
|
findNode,
|
||||||
getNodeById,
|
getNodeById,
|
||||||
isNodeVisible,
|
isNodeVisible,
|
||||||
|
nodeToScene,
|
||||||
unknownNodeTemplate,
|
unknownNodeTemplate,
|
||||||
} from "../../helpers/node-helpers";
|
} from "../../helpers/node-helpers";
|
||||||
import {
|
import {
|
||||||
|
@ -35,8 +36,9 @@ import {
|
||||||
import { GameEvent, MainSceneContext } from "../../types/types";
|
import { GameEvent, MainSceneContext } from "../../types/types";
|
||||||
import { getCurrentUserState } from "../../store";
|
import { getCurrentUserState } from "../../store";
|
||||||
|
|
||||||
const handleMainSceneKeyPress = (
|
const handleMainSceneInput = (
|
||||||
mainSceneContext: MainSceneContext
|
mainSceneContext: MainSceneContext,
|
||||||
|
keyPress: string
|
||||||
): GameEvent | undefined => {
|
): GameEvent | undefined => {
|
||||||
const {
|
const {
|
||||||
subscene,
|
subscene,
|
||||||
|
@ -47,7 +49,6 @@ const handleMainSceneKeyPress = (
|
||||||
siteRotY,
|
siteRotY,
|
||||||
activeNode,
|
activeNode,
|
||||||
level,
|
level,
|
||||||
keyPress,
|
|
||||||
showingAbout,
|
showingAbout,
|
||||||
promptVisible,
|
promptVisible,
|
||||||
activePromptComponent,
|
activePromptComponent,
|
||||||
|
@ -189,8 +190,6 @@ const handleMainSceneKeyPress = (
|
||||||
case "CIRCLE":
|
case "CIRCLE":
|
||||||
const eventAnimation = Math.random() < 0.4 ? throwNode : ripNode;
|
const eventAnimation = Math.random() < 0.4 ? throwNode : ripNode;
|
||||||
|
|
||||||
const nodeType = activeNode.type;
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
activeNode.id === "" ||
|
activeNode.id === "" ||
|
||||||
!isNodeVisible(activeNode, gameProgress)
|
!isNodeVisible(activeNode, gameProgress)
|
||||||
|
@ -202,26 +201,8 @@ const handleMainSceneKeyPress = (
|
||||||
return rejectEvents[Math.floor(Math.random() * 3)];
|
return rejectEvents[Math.floor(Math.random() * 3)];
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (nodeType) {
|
const newScene = nodeToScene(activeNode);
|
||||||
case 0:
|
if (newScene) return eventAnimation({ currentScene: newScene });
|
||||||
case 2:
|
|
||||||
case 4:
|
|
||||||
case 3:
|
|
||||||
case 5:
|
|
||||||
return eventAnimation({ currentScene: "media" });
|
|
||||||
case 6:
|
|
||||||
if (activeNode.node_name.substr(0, 3) === "TaK") {
|
|
||||||
return eventAnimation({ currentScene: "tak" });
|
|
||||||
} else {
|
|
||||||
return eventAnimation({ currentScene: "media" });
|
|
||||||
}
|
|
||||||
case 7:
|
|
||||||
return eventAnimation({ currentScene: "sskn" });
|
|
||||||
case 8:
|
|
||||||
return eventAnimation({ currentScene: "gate" });
|
|
||||||
case 9:
|
|
||||||
return eventAnimation({ currentScene: "polytan" });
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case "L2":
|
case "L2":
|
||||||
return enterLevelSelection({ selectedLevel: level });
|
return enterLevelSelection({ selectedLevel: level });
|
||||||
|
@ -326,4 +307,4 @@ const handleMainSceneKeyPress = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleMainSceneKeyPress;
|
export default handleMainSceneInput;
|
|
@ -15,11 +15,11 @@ import {
|
||||||
RightMediaComponent,
|
RightMediaComponent,
|
||||||
} from "../../types/types";
|
} from "../../types/types";
|
||||||
|
|
||||||
const handleMediaSceneKeyPress = (
|
const handleMediaSceneInput = (
|
||||||
mediaSceneContext: MediaSceneContext
|
mediaSceneContext: MediaSceneContext,
|
||||||
|
keyPress: string
|
||||||
): GameEvent | undefined => {
|
): GameEvent | undefined => {
|
||||||
const {
|
const {
|
||||||
keyPress,
|
|
||||||
activeMediaComponent,
|
activeMediaComponent,
|
||||||
wordPosStateIdx,
|
wordPosStateIdx,
|
||||||
activeNode,
|
activeNode,
|
||||||
|
@ -139,4 +139,4 @@ const handleMediaSceneKeyPress = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleMediaSceneKeyPress;
|
export default handleMediaSceneInput;
|
|
@ -1,15 +1,11 @@
|
||||||
import { changeSsknComponent, exitSskn, upgradeSskn } from "../eventTemplates";
|
import { changeSsknComponent, exitSskn, upgradeSskn } from "../eventTemplates";
|
||||||
import { GameEvent, SsknSceneContext } from "../../types/types";
|
import { GameEvent, SsknSceneContext } from "../../types/types";
|
||||||
|
|
||||||
const handleSsknSceneKeyPress = (
|
const handleSsknSceneInput = (
|
||||||
ssknSceneContext: SsknSceneContext
|
ssknSceneContext: SsknSceneContext,
|
||||||
|
keyPress: string
|
||||||
): GameEvent | undefined => {
|
): GameEvent | undefined => {
|
||||||
const {
|
const { activeSsknComponent, activeNode } = ssknSceneContext;
|
||||||
keyPress,
|
|
||||||
activeSsknComponent,
|
|
||||||
activeNode,
|
|
||||||
gameProgress,
|
|
||||||
} = ssknSceneContext;
|
|
||||||
|
|
||||||
switch (keyPress) {
|
switch (keyPress) {
|
||||||
case "UP":
|
case "UP":
|
||||||
|
@ -27,4 +23,4 @@ const handleSsknSceneKeyPress = (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default handleSsknSceneKeyPress;
|
export default handleSsknSceneInput;
|
|
@ -288,3 +288,26 @@ export const unknownNodeTemplate = {
|
||||||
"3": "",
|
"3": "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const nodeToScene = (node: NodeData) => {
|
||||||
|
switch (node.type) {
|
||||||
|
case 0:
|
||||||
|
case 2:
|
||||||
|
case 4:
|
||||||
|
case 3:
|
||||||
|
case 5:
|
||||||
|
return "media";
|
||||||
|
case 6:
|
||||||
|
if (node.node_name.substr(0, 3) === "TaK") {
|
||||||
|
return "tak";
|
||||||
|
} else {
|
||||||
|
return "media";
|
||||||
|
}
|
||||||
|
case 7:
|
||||||
|
return "sskn";
|
||||||
|
case 8:
|
||||||
|
return "gate";
|
||||||
|
case 9:
|
||||||
|
return "polytan";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
16
src/store.ts
16
src/store.ts
|
@ -346,12 +346,11 @@ const getPromptContext = () => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMainSceneContext = (keyPress: string): MainSceneContext => {
|
export const getMainSceneContext = (): MainSceneContext => {
|
||||||
const state = useStore.getState();
|
const state = useStore.getState();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getPromptContext(),
|
...getPromptContext(),
|
||||||
keyPress: keyPress,
|
|
||||||
subscene: state.mainSubscene,
|
subscene: state.mainSubscene,
|
||||||
selectedLevel: state.selectedLevel,
|
selectedLevel: state.selectedLevel,
|
||||||
activePauseComponent: state.activePauseComponent,
|
activePauseComponent: state.activePauseComponent,
|
||||||
|
@ -366,21 +365,18 @@ export const getMainSceneContext = (keyPress: string): MainSceneContext => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getSsknSceneContext = (keyPress: string): SsknSceneContext => {
|
export const getSsknSceneContext = (): SsknSceneContext => {
|
||||||
const state = useStore.getState();
|
const state = useStore.getState();
|
||||||
return {
|
return {
|
||||||
keyPress: keyPress,
|
|
||||||
activeSsknComponent: state.activeSsknComponent,
|
activeSsknComponent: state.activeSsknComponent,
|
||||||
activeNode: state.activeNode,
|
activeNode: state.activeNode,
|
||||||
gameProgress: state.gameProgress,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getMediaSceneContext = (keyPress: string): MediaSceneContext => {
|
export const getMediaSceneContext = (): MediaSceneContext => {
|
||||||
const state = useStore.getState();
|
const state = useStore.getState();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keyPress: keyPress,
|
|
||||||
lastActiveMediaComponents: state.lastActiveMediaComponents,
|
lastActiveMediaComponents: state.lastActiveMediaComponents,
|
||||||
currentMediaSide: state.currentMediaSide,
|
currentMediaSide: state.currentMediaSide,
|
||||||
activeMediaComponent: state.activeMediaComponent,
|
activeMediaComponent: state.activeMediaComponent,
|
||||||
|
@ -391,12 +387,11 @@ export const getMediaSceneContext = (keyPress: string): MediaSceneContext => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBootSceneContext = (keyPress: string): BootSceneContext => {
|
export const getBootSceneContext = (): BootSceneContext => {
|
||||||
const state = useStore.getState();
|
const state = useStore.getState();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...getPromptContext(),
|
...getPromptContext(),
|
||||||
keyPress: keyPress,
|
|
||||||
playerName: state.playerName,
|
playerName: state.playerName,
|
||||||
subscene: state.bootSubscene,
|
subscene: state.bootSubscene,
|
||||||
activeMainMenuComponent: state.activeMainMenuComponent,
|
activeMainMenuComponent: state.activeMainMenuComponent,
|
||||||
|
@ -404,11 +399,10 @@ export const getBootSceneContext = (keyPress: string): BootSceneContext => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getEndSceneContext = (keyPress: string): EndSceneContext => {
|
export const getEndSceneContext = (): EndSceneContext => {
|
||||||
const state = useStore.getState();
|
const state = useStore.getState();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
keyPress: keyPress,
|
|
||||||
activeEndComponent: state.activeEndComponent,
|
activeEndComponent: state.activeEndComponent,
|
||||||
selectionVisible: state.endSceneSelectionVisible,
|
selectionVisible: state.endSceneSelectionVisible,
|
||||||
siteSaveState: state.siteSaveState,
|
siteSaveState: state.siteSaveState,
|
||||||
|
|
|
@ -98,7 +98,6 @@ type PromptContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface MainSceneContext extends PromptContext {
|
export interface MainSceneContext extends PromptContext {
|
||||||
keyPress: string;
|
|
||||||
activeNode: NodeData;
|
activeNode: NodeData;
|
||||||
showingAbout: boolean;
|
showingAbout: boolean;
|
||||||
level: number;
|
level: number;
|
||||||
|
@ -113,14 +112,11 @@ export interface MainSceneContext extends PromptContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SsknSceneContext = {
|
export type SsknSceneContext = {
|
||||||
keyPress: string;
|
|
||||||
activeSsknComponent: SsknComponent;
|
activeSsknComponent: SsknComponent;
|
||||||
activeNode: NodeData;
|
activeNode: NodeData;
|
||||||
gameProgress: GameProgress;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type MediaSceneContext = {
|
export type MediaSceneContext = {
|
||||||
keyPress: string;
|
|
||||||
wordPosStateIdx: number;
|
wordPosStateIdx: number;
|
||||||
currentMediaSide: MediaSide;
|
currentMediaSide: MediaSide;
|
||||||
activeMediaComponent: MediaComponent;
|
activeMediaComponent: MediaComponent;
|
||||||
|
@ -134,7 +130,6 @@ export type MediaSceneContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface BootSceneContext extends PromptContext {
|
export interface BootSceneContext extends PromptContext {
|
||||||
keyPress: string;
|
|
||||||
playerName: string;
|
playerName: string;
|
||||||
subscene: BootSubscene;
|
subscene: BootSubscene;
|
||||||
activeMainMenuComponent: MainMenuComponent;
|
activeMainMenuComponent: MainMenuComponent;
|
||||||
|
@ -142,7 +137,6 @@ export interface BootSceneContext extends PromptContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type EndSceneContext = {
|
export type EndSceneContext = {
|
||||||
keyPress: string;
|
|
||||||
activeEndComponent: EndComponent;
|
activeEndComponent: EndComponent;
|
||||||
selectionVisible: boolean;
|
selectionVisible: boolean;
|
||||||
siteSaveState: SiteSaveState;
|
siteSaveState: SiteSaveState;
|
||||||
|
|
Loading…
Reference in a new issue