mirror of
https://github.com/ad044/lainTSX.git
synced 2024-10-22 23:19:06 +00:00
merged sskn/gate lvl with game progress, committed more tests, cleaned up some functions
This commit is contained in:
parent
1d895e64b0
commit
c57659fe47
19 changed files with 3248 additions and 3032 deletions
|
@ -24,7 +24,7 @@
|
|||
"scripts": {
|
||||
"start": "react-scripts start",
|
||||
"build": "react-scripts build",
|
||||
"test": "react-scripts test",
|
||||
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!three/.*)/\"",
|
||||
"eject": "react-scripts eject",
|
||||
"dump": "ts-node asset-dump/dump/index.ts"
|
||||
},
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import React from 'react';
|
||||
import { render } from '@testing-library/react';
|
||||
import App from './App';
|
||||
|
||||
test('renders learn react link', () => {
|
||||
const { getByText } = render(<App />);
|
||||
const linkElement = getByText(/learn react/i);
|
||||
expect(linkElement).toBeInTheDocument();
|
||||
});
|
|
@ -74,9 +74,9 @@ const KeyPressHandler = () => {
|
|||
const now = Date.now();
|
||||
|
||||
if (
|
||||
keyPress &&
|
||||
now > timeSinceLastKeyPress.current + inputCooldown &&
|
||||
inputCooldown !== -1
|
||||
keyPress
|
||||
// now > timeSinceLastKeyPress.current + inputCooldown &&
|
||||
// inputCooldown !== -1
|
||||
) {
|
||||
if (scene === "main") {
|
||||
lainIdleCounter.current = now;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import React, { useState } from "react";
|
||||
import React, { memo, useState } from "react";
|
||||
import loadingSpritesheet from "../static/sprite/loading_spritesheet.png";
|
||||
import lifeInstinct from "../static/sprite/life_instinct_function_os.png";
|
||||
import { useFrame, useLoader } from "react-three-fiber";
|
||||
import * as THREE from "three";
|
||||
import { PlainAnimator } from "three-plain-animator/lib/plain-animator";
|
||||
|
||||
const Loading = () => {
|
||||
const Loading = memo(() => {
|
||||
const loadingTex: any = useLoader(THREE.TextureLoader, loadingSpritesheet);
|
||||
const lifeInstinctTex = useLoader(THREE.TextureLoader, lifeInstinct);
|
||||
|
||||
|
@ -32,6 +32,6 @@ const Loading = () => {
|
|||
</sprite>
|
||||
</>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export default Loading;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React from "react";
|
||||
import React, { memo } from "react";
|
||||
import statusContainer from "../static/sprite/status_container.png";
|
||||
import loadSuccessfulImg from "../static/sprite/load_successful.png";
|
||||
import loadFailImg from "../static/sprite/load_fail.png";
|
||||
|
@ -8,7 +8,7 @@ import { useLoader } from "react-three-fiber";
|
|||
import * as THREE from "three";
|
||||
import { useStore } from "../store";
|
||||
|
||||
const Status = () => {
|
||||
const Status = memo(() => {
|
||||
const loadSuccessful = useStore((state) => state.loadSuccessful);
|
||||
const saveSuccessful = useStore((state) => state.saveSuccessful);
|
||||
|
||||
|
@ -62,6 +62,6 @@ const Status = () => {
|
|||
</sprite>
|
||||
</group>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
export default Status;
|
||||
|
|
|
@ -502,13 +502,11 @@ export const changeSsknComponent = (calculatedState: {
|
|||
|
||||
export const upgradeSskn = (calculatedState: {
|
||||
gameProgress: GameProgress;
|
||||
ssknLvl: number;
|
||||
}) => ({
|
||||
state: [
|
||||
{
|
||||
mutation: {
|
||||
gameProgress: calculatedState.gameProgress,
|
||||
ssknLvl: calculatedState.ssknLvl,
|
||||
ssknLoading: true,
|
||||
inputCooldown: -1,
|
||||
},
|
||||
|
|
|
@ -47,15 +47,14 @@ const handleMainSceneKeyPress = (
|
|||
activeNode,
|
||||
level,
|
||||
keyPress,
|
||||
ssknLvl,
|
||||
showingAbout,
|
||||
promptVisible,
|
||||
activePromptComponent,
|
||||
gateLvl,
|
||||
siteSaveState,
|
||||
wordNotFound,
|
||||
} = mainSceneContext;
|
||||
|
||||
console.log(activeNode.matrixIndices);
|
||||
if (promptVisible) {
|
||||
switch (keyPress) {
|
||||
case "LEFT":
|
||||
|
@ -103,9 +102,8 @@ const handleMainSceneKeyPress = (
|
|||
case "RIGHT": {
|
||||
const direction = keyPress.toLowerCase();
|
||||
const nodeData = findNode(
|
||||
activeNode.id,
|
||||
activeNode,
|
||||
direction,
|
||||
activeNode.matrixIndices!,
|
||||
level,
|
||||
activeSite,
|
||||
gameProgress,
|
||||
|
@ -144,9 +142,8 @@ const handleMainSceneKeyPress = (
|
|||
const direction = keyPress.toLowerCase();
|
||||
|
||||
const nodeData = findNode(
|
||||
activeNode.id,
|
||||
activeNode,
|
||||
direction,
|
||||
activeNode.matrixIndices!,
|
||||
level,
|
||||
activeSite,
|
||||
gameProgress,
|
||||
|
@ -185,7 +182,7 @@ const handleMainSceneKeyPress = (
|
|||
)
|
||||
return;
|
||||
|
||||
if (activeNode.upgrade_requirement > ssknLvl) {
|
||||
if (activeNode.upgrade_requirement > gameProgress.sskn_level) {
|
||||
const rejectEvents = [knockNodeAndFall, knockNode, explodeNode];
|
||||
return rejectEvents[Math.floor(Math.random() * 3)];
|
||||
}
|
||||
|
@ -236,11 +233,12 @@ const handleMainSceneKeyPress = (
|
|||
|
||||
const direction = selectedLevel > level ? "up" : "down";
|
||||
|
||||
// todo implement this row idx without mutating activenode
|
||||
const rowIdx = direction === "up" ? 2 : 0;
|
||||
|
||||
const nodeData = findNode(
|
||||
activeNode.id,
|
||||
activeNode,
|
||||
direction,
|
||||
{ ...activeNode.matrixIndices!, rowIdx: rowIdx },
|
||||
selectedLevel,
|
||||
activeSite,
|
||||
gameProgress,
|
||||
|
@ -294,7 +292,10 @@ const handleMainSceneKeyPress = (
|
|||
case "load":
|
||||
return displayPrompt;
|
||||
case "change":
|
||||
if (activePauseComponent === "change" && gateLvl > 4)
|
||||
if (
|
||||
activePauseComponent === "change" &&
|
||||
gameProgress.gate_level > 4
|
||||
)
|
||||
return showPermissionDenied;
|
||||
else return displayPrompt;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { findNodeFromWord } from "../../helpers/media-helpers";
|
||||
import { MediaSceneContext } from "../../store";
|
||||
import { MediaSceneContext, RightMediaComponent } from "../../store";
|
||||
import {
|
||||
changeLeftMediaComponent,
|
||||
changeMediaSide,
|
||||
|
@ -10,6 +10,7 @@ import {
|
|||
wordNotFound,
|
||||
} from "../eventTemplates";
|
||||
import { GameEvent } from "../handleEvent";
|
||||
import { isNodeVisible } from "../../helpers/node-helpers";
|
||||
|
||||
const handleMediaSceneKeyPress = (
|
||||
mediaSceneContext: MediaSceneContext
|
||||
|
@ -100,32 +101,37 @@ const handleMediaSceneKeyPress = (
|
|||
activeMediaComponent: lastActiveMediaComponents.left,
|
||||
lastActiveMediaComponents: {
|
||||
...lastActiveMediaComponents,
|
||||
right: activeMediaComponent as
|
||||
| "fstWord"
|
||||
| "sndWord"
|
||||
| "thirdWord",
|
||||
right: activeMediaComponent as RightMediaComponent,
|
||||
},
|
||||
currentMediaSide: "left",
|
||||
});
|
||||
|
||||
case "CIRCLE":
|
||||
const data = findNodeFromWord(
|
||||
activeMediaComponent,
|
||||
activeNode,
|
||||
activeSite,
|
||||
gameProgress
|
||||
);
|
||||
const wordIdx = (() => {
|
||||
switch (activeMediaComponent as RightMediaComponent) {
|
||||
case "fstWord":
|
||||
return 1;
|
||||
case "sndWord":
|
||||
return 2;
|
||||
case "thirdWord":
|
||||
return 3;
|
||||
}
|
||||
})();
|
||||
|
||||
const nodeName = activeNode.node_name;
|
||||
const wordToFind = activeNode.words[wordIdx];
|
||||
|
||||
const data = findNodeFromWord(wordToFind, nodeName, activeSite);
|
||||
|
||||
if (data) {
|
||||
const { node, level, siteRotY } = { ...data };
|
||||
|
||||
if (!isNodeVisible(node, gameProgress)) return wordNotFound;
|
||||
|
||||
return selectWord({
|
||||
activeNode: node,
|
||||
activeLevel: level,
|
||||
siteRot: [0, siteRotY, 0],
|
||||
});
|
||||
} else {
|
||||
return wordNotFound;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -10,7 +10,6 @@ const handleSsknSceneKeyPress = (
|
|||
activeSsknComponent,
|
||||
activeNode,
|
||||
gameProgress,
|
||||
ssknLvl,
|
||||
} = ssknSceneContext;
|
||||
|
||||
switch (keyPress) {
|
||||
|
@ -28,13 +27,10 @@ const handleSsknSceneKeyPress = (
|
|||
is_viewed: 1,
|
||||
is_visible: 0,
|
||||
},
|
||||
sskn_level: gameProgress.sskn_level + 1,
|
||||
};
|
||||
const newSsknLvl = ssknLvl + 1;
|
||||
|
||||
return upgradeSskn({
|
||||
gameProgress: newGameProgress,
|
||||
ssknLvl: newSsknLvl,
|
||||
});
|
||||
return upgradeSskn({ gameProgress: newGameProgress });
|
||||
case "cancel":
|
||||
return exitSskn;
|
||||
}
|
||||
|
|
|
@ -1,29 +1,14 @@
|
|||
import site_a from "../resources/site_a.json";
|
||||
import site_b from "../resources/site_b.json";
|
||||
import node_matrices from "../resources/node_matrices.json";
|
||||
import { NodeData, SiteData } from "../components/MainScene/Site/Site";
|
||||
import { isNodeVisible } from "./node-helpers";
|
||||
import { ActiveSite, RightMediaComponent } from "../store";
|
||||
import { SiteData } from "../components/MainScene/Site/Site";
|
||||
import { ActiveSite } from "../store";
|
||||
|
||||
export const findNodeFromWord = (
|
||||
wordLabel: RightMediaComponent,
|
||||
activeNode: NodeData,
|
||||
site: ActiveSite,
|
||||
gameProgress: any
|
||||
wordToFind: string,
|
||||
nodeName: string,
|
||||
site: ActiveSite
|
||||
) => {
|
||||
const labelToIdx = (() => {
|
||||
switch (wordLabel) {
|
||||
case "fstWord":
|
||||
return 1;
|
||||
case "sndWord":
|
||||
return 2;
|
||||
case "thirdWord":
|
||||
return 3;
|
||||
}
|
||||
})();
|
||||
|
||||
const wordToFind = activeNode.words[labelToIdx!];
|
||||
|
||||
const siteData: SiteData = site === "a" ? site_a : site_b;
|
||||
|
||||
const nodesWithSameWords = Object.values(siteData)
|
||||
|
@ -36,13 +21,9 @@ export const findNodeFromWord = (
|
|||
|
||||
const chosenNode =
|
||||
nodesWithSameWords[
|
||||
nodesWithSameWords.findIndex(
|
||||
(node) => node.node_name === activeNode.node_name
|
||||
) + 1
|
||||
nodesWithSameWords.findIndex((node) => node.node_name === nodeName) + 1
|
||||
] ?? nodesWithSameWords[0];
|
||||
|
||||
if (!isNodeVisible(chosenNode, gameProgress)) return;
|
||||
|
||||
const pos = chosenNode.id.substr(2);
|
||||
|
||||
const matrixIndices = Object.entries(node_matrices).flatMap((matrixData) =>
|
||||
|
|
|
@ -4,7 +4,7 @@ import site_b from "../resources/site_b.json";
|
|||
import node_huds from "../resources/node_huds.json";
|
||||
import unlocked_nodes from "../resources/initial_progress.json";
|
||||
import node_matrices from "../resources/node_matrices.json";
|
||||
import { GameProgress } from "../store";
|
||||
import { ActiveSite, GameProgress } from "../store";
|
||||
|
||||
export const generateInactiveNodes = (
|
||||
visibleNodes: SiteData,
|
||||
|
@ -58,24 +58,33 @@ export const getNodeHud = (nodeMatrixIndices: {
|
|||
];
|
||||
};
|
||||
|
||||
//visible = (global_final_viewcount > 0) && (req_final_viewcount <= global_final_viewcount + 1)
|
||||
export const isNodeVisible = (
|
||||
node: NodeData,
|
||||
gameProgress: typeof unlocked_nodes
|
||||
) => {
|
||||
return node
|
||||
? (node.unlocked_by === "" ||
|
||||
gameProgress[node.unlocked_by as keyof typeof gameProgress]
|
||||
.is_viewed) &&
|
||||
gameProgress[node.node_name as keyof typeof gameProgress].is_visible
|
||||
? Boolean(
|
||||
(node.unlocked_by === "" ||
|
||||
gameProgress.nodes[
|
||||
node.unlocked_by as keyof typeof gameProgress.nodes
|
||||
].is_viewed) &&
|
||||
gameProgress.nodes[node.node_name as keyof typeof gameProgress.nodes]
|
||||
.is_visible &&
|
||||
(node.required_final_video_viewcount > 0
|
||||
? gameProgress.final_video_viewcount > 0
|
||||
? node.required_final_video_viewcount <=
|
||||
gameProgress.final_video_viewcount + 1
|
||||
: false
|
||||
: true)
|
||||
)
|
||||
: false;
|
||||
};
|
||||
|
||||
export const getVisibleNodesMatrix = (
|
||||
matrixIdx: number,
|
||||
activeLevel: number,
|
||||
activeSite: string,
|
||||
gameProgress: any
|
||||
activeSite: ActiveSite,
|
||||
gameProgress: GameProgress
|
||||
) => {
|
||||
const formattedLevel = activeLevel.toString().padStart(2, "0");
|
||||
const currentMatrix =
|
||||
|
@ -163,18 +172,10 @@ const move = (direction: string, [matrix, level]: [number, number]) => {
|
|||
};
|
||||
|
||||
export const findNode = (
|
||||
nodeId: string,
|
||||
|
||||
activeNode: NodeData,
|
||||
direction: string,
|
||||
|
||||
{
|
||||
matrixIdx,
|
||||
rowIdx,
|
||||
colIdx,
|
||||
}: { matrixIdx: number; rowIdx: number; colIdx: number },
|
||||
|
||||
level: number,
|
||||
activeSite: string,
|
||||
activeSite: ActiveSite,
|
||||
gameProgress: GameProgress,
|
||||
shouldSearchNext: boolean
|
||||
) => {
|
||||
|
@ -190,10 +191,14 @@ export const findNode = (
|
|||
down: [nextPos_down, ([, c]: [number, number]) => nextPos_down([-1, c])],
|
||||
};
|
||||
|
||||
const initialMatrixIdx = matrixIdx;
|
||||
|
||||
if (activeNode.matrixIndices) {
|
||||
const nextPos = funcs[direction];
|
||||
|
||||
const nodeId = activeNode.id;
|
||||
let { matrixIdx, colIdx, rowIdx } = { ...activeNode.matrixIndices };
|
||||
|
||||
const initialMatrixIdx = matrixIdx;
|
||||
|
||||
for (let i = 0; i < (shouldSearchNext ? 2 : 1); i++) {
|
||||
const nodes = getVisibleNodesMatrix(
|
||||
matrixIdx,
|
||||
|
@ -235,6 +240,7 @@ export const findNode = (
|
|||
didMove: true,
|
||||
};
|
||||
}
|
||||
}
|
||||
};
|
||||
export const filterInvisibleNodes = (
|
||||
siteData: SiteData,
|
||||
|
@ -248,8 +254,9 @@ export const filterInvisibleNodes = (
|
|||
visibleNodes[level[0]][node[0]] = {
|
||||
...node[1],
|
||||
is_viewed:
|
||||
gameProgress[node[1].node_name as keyof typeof gameProgress]
|
||||
.is_viewed,
|
||||
gameProgress.nodes[
|
||||
node[1].node_name as keyof typeof gameProgress.nodes
|
||||
].is_viewed,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
{
|
||||
"sskn_level": 0,
|
||||
"gate_level": 0,
|
||||
"final_video_viewcount": 0,
|
||||
"nodes": {
|
||||
"Cou001": {
|
||||
"is_viewed": 0,
|
||||
"is_visible": 1
|
||||
|
@ -2863,4 +2867,5 @@
|
|||
"is_viewed": 0,
|
||||
"is_visible": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import GateMiddleObject from "../components/GateScene/GateMiddleObject";
|
|||
import { useStore } from "../store";
|
||||
|
||||
const GateScene = () => {
|
||||
const gateLvl = useStore((state) => state.gateLvl);
|
||||
const gateLvl = useStore((state) => state.gameProgress.gate_level);
|
||||
const incrementGateLvl = useStore((state) => state.incrementGateLvl);
|
||||
const [introAnim, setIntroAnim] = useState(true);
|
||||
|
||||
|
|
36
src/store.ts
36
src/store.ts
|
@ -1,22 +1,11 @@
|
|||
import create from "zustand";
|
||||
import { combine } from "zustand/middleware";
|
||||
import * as THREE from "three";
|
||||
import { AudioAnalyser } from "three";
|
||||
import game_progress from "./resources/initial_progress.json";
|
||||
import { NodeData } from "./components/MainScene/Site/Site";
|
||||
import { getNodeById } from "./helpers/node-helpers";
|
||||
import site_a from "./resources/site_a.json";
|
||||
import { AudioAnalyser } from "three";
|
||||
import MainScene from "./scenes/MainScene";
|
||||
import MediaScene from "./scenes/MediaScene";
|
||||
import IdleMediaScene from "./scenes/IdleMediaScene";
|
||||
import GateScene from "./scenes/GateScene";
|
||||
import BootScene from "./scenes/BootScene";
|
||||
import SsknScene from "./scenes/SsknScene";
|
||||
import PolytanScene from "./scenes/PolytanScene";
|
||||
import TaKScene from "./scenes/TaKScene";
|
||||
import ChangeDiscScene from "./scenes/ChangeDiscScene";
|
||||
import EndScene from "./scenes/EndScene";
|
||||
import React from "react";
|
||||
|
||||
export type GameProgress = typeof game_progress;
|
||||
|
||||
|
@ -142,14 +131,10 @@ type State = {
|
|||
// sskn scene
|
||||
activeSsknComponent: SsknComponent;
|
||||
ssknLoading: boolean;
|
||||
ssknLvl: number;
|
||||
|
||||
// polytan scene
|
||||
polytanUnlockedParts: PolytanBodyParts;
|
||||
|
||||
// gate scene
|
||||
gateLvl: number;
|
||||
|
||||
// player name
|
||||
playerName: string;
|
||||
|
||||
|
@ -254,7 +239,6 @@ export const useStore = create(
|
|||
// sskn scene
|
||||
activeSsknComponent: "ok",
|
||||
ssknLoading: false,
|
||||
ssknLvl: 0,
|
||||
|
||||
// polytan scene
|
||||
polytanUnlockedParts: {
|
||||
|
@ -266,9 +250,6 @@ export const useStore = create(
|
|||
rightLeg: false,
|
||||
},
|
||||
|
||||
// gate scene
|
||||
gateLvl: 0,
|
||||
|
||||
// player name
|
||||
playerName: "アイウエオ",
|
||||
|
||||
|
@ -357,8 +338,13 @@ export const useStore = create(
|
|||
|
||||
setInputCooldown: (to: number) => set(() => ({ inputCooldown: to })),
|
||||
|
||||
incrementGateLvl: () => set((state) => ({ gateLvl: state.gateLvl + 1 })),
|
||||
incrementSsknLvl: () => set((state) => ({ ssknLvl: state.ssknLvl + 1 })),
|
||||
incrementGateLvl: () =>
|
||||
set((state) => ({
|
||||
gameProgress: {
|
||||
...state.gameProgress,
|
||||
gate_level: state.gameProgress.gate_level + 1,
|
||||
},
|
||||
})),
|
||||
})
|
||||
)
|
||||
);
|
||||
|
@ -379,13 +365,11 @@ const getPromptContext = () => {
|
|||
|
||||
export interface MainSceneContext extends PromptContext {
|
||||
keyPress: string;
|
||||
ssknLvl: number;
|
||||
activeNode: NodeData;
|
||||
showingAbout: boolean;
|
||||
level: number;
|
||||
activePauseComponent: PauseComponent;
|
||||
gameProgress: GameProgress;
|
||||
gateLvl: number;
|
||||
subscene: string;
|
||||
siteRotY: number;
|
||||
activeSite: ActiveSite;
|
||||
|
@ -408,9 +392,7 @@ export const getMainSceneContext = (keyPress: string): MainSceneContext => {
|
|||
siteRotY: state.siteRot[1],
|
||||
activeNode: state.activeNode,
|
||||
level: parseInt(state.activeLevel),
|
||||
ssknLvl: state.ssknLvl,
|
||||
showingAbout: state.showingAbout,
|
||||
gateLvl: state.gateLvl,
|
||||
siteSaveState: state.siteSaveState,
|
||||
wordNotFound: state.wordNotFound,
|
||||
};
|
||||
|
@ -421,7 +403,6 @@ export type SsknSceneContext = {
|
|||
activeSsknComponent: SsknComponent;
|
||||
activeNode: NodeData;
|
||||
gameProgress: GameProgress;
|
||||
ssknLvl: number;
|
||||
};
|
||||
|
||||
export const getSsknSceneContext = (keyPress: string): SsknSceneContext => {
|
||||
|
@ -431,7 +412,6 @@ export const getSsknSceneContext = (keyPress: string): SsknSceneContext => {
|
|||
activeSsknComponent: state.activeSsknComponent,
|
||||
activeNode: state.activeNode,
|
||||
gameProgress: state.gameProgress,
|
||||
ssknLvl: state.ssknLvl,
|
||||
};
|
||||
};
|
||||
|
||||
|
|
37
src/tests/helpers/media-helpers.test.ts
Normal file
37
src/tests/helpers/media-helpers.test.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import { findNodeFromWord } from "../../helpers/media-helpers";
|
||||
|
||||
it("Finds the next node with the same word", () => {
|
||||
expect(findNodeFromWord("father", "Cou041", "b").node.node_name).toEqual(
|
||||
"Lda151"
|
||||
);
|
||||
expect(findNodeFromWord("father", "Lda151", "b").node.node_name).toEqual(
|
||||
"Lda155"
|
||||
);
|
||||
expect(findNodeFromWord("father", "Lda155", "b").node.node_name).toEqual(
|
||||
"Lda164"
|
||||
);
|
||||
expect(findNodeFromWord("father", "Lda182", "b").node.node_name).toEqual(
|
||||
"Lda200"
|
||||
);
|
||||
expect(findNodeFromWord("father", "Lda229", "b").node.node_name).toEqual(
|
||||
"Cou041"
|
||||
);
|
||||
expect(findNodeFromWord("father", "Cou041", "b").node.node_name).toEqual(
|
||||
"Lda151"
|
||||
);
|
||||
expect(findNodeFromWord("chaos", "Lda154", "b").node.node_name).toEqual(
|
||||
"Tda056"
|
||||
);
|
||||
expect(findNodeFromWord("chaos", "Tda056", "b").node.node_name).toEqual(
|
||||
"Tda059"
|
||||
);
|
||||
expect(findNodeFromWord("prompt", "Lda154", "b").node.node_name).toEqual(
|
||||
"Tda072"
|
||||
);
|
||||
expect(findNodeFromWord("abuse", "Dc1012", "a").node.node_name).toEqual(
|
||||
"Lda005"
|
||||
);
|
||||
expect(findNodeFromWord("abuse", "Lda005", "a").node.node_name).toEqual(
|
||||
"Dc1012"
|
||||
);
|
||||
});
|
29
src/tests/helpers/name-selection-helpers.test.ts
Normal file
29
src/tests/helpers/name-selection-helpers.test.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import handleNameSelection from "../../helpers/name-selection-helpers";
|
||||
|
||||
it("Handles the logic for japanese characters", () => {
|
||||
// cant be first character check
|
||||
expect(handleNameSelection("", "ン")).toEqual(undefined);
|
||||
// if its not first, then fine
|
||||
expect(handleNameSelection("キ", "ン")).toEqual("キン");
|
||||
//「ー」 cannot be added to 「ッ」 and 「ン」or itself
|
||||
expect(handleNameSelection("キッ", "ー")).toEqual(undefined);
|
||||
expect(handleNameSelection("キン", "ー")).toEqual(undefined);
|
||||
expect(handleNameSelection("キー", "ー")).toEqual(undefined);
|
||||
// characters that can be followed by the lowercase characters
|
||||
expect(handleNameSelection("キ", "ャ")).toEqual("キャ");
|
||||
// cant be followed by lowercase character
|
||||
expect(handleNameSelection("ー", "ャ")).toEqual(undefined);
|
||||
// for 「ッ」, it can added to any character except itself
|
||||
expect(handleNameSelection("ャ", "ッ")).toEqual("ャッ");
|
||||
// cant be added
|
||||
expect(handleNameSelection("ッ", "ッ")).toEqual(undefined);
|
||||
// dakuten
|
||||
expect(handleNameSelection("カ", "゛")).toEqual("ガ");
|
||||
// cant be appended
|
||||
expect(handleNameSelection("ガ", "゛")).toEqual(undefined);
|
||||
// handakuten
|
||||
expect(handleNameSelection("ハ", "゜")).toEqual("パ");
|
||||
// cant be appended
|
||||
expect(handleNameSelection("キ", "゜")).toEqual(undefined);
|
||||
expect(handleNameSelection("パ", "゜")).toEqual(undefined);
|
||||
});
|
158
src/tests/helpers/node-finder.test.ts
Normal file
158
src/tests/helpers/node-finder.test.ts
Normal file
|
@ -0,0 +1,158 @@
|
|||
import { findNode, unknownNodeTemplate } from "../../helpers/node-helpers";
|
||||
import site_a from "../../resources/site_a.json";
|
||||
import gameProgress from "../../resources/initial_progress.json";
|
||||
|
||||
/*
|
||||
visual representation of the data we're working with
|
||||
|
||||
[null, "0517", null, null],
|
||||
[null, null, "0510", "0513"],
|
||||
["0506", null, null, null],
|
||||
|
|
||||
[null, null, null, "0422"], ["0422", "0417", null, null], [null, "0416", "0417", "0420"],
|
||||
[null, null, null, "0414"], - ["0414", null, null, "0413"], - ["0413", null, null, null],
|
||||
[null, null, null, null], [null, null, null, "0405"], ["0405", null, null, null],
|
||||
|
|
||||
[null, null, null, null] [null, null, null, null], [null, null, null, null],
|
||||
[null, null, null, null], [null, null, null, null], [null, null, null, null],
|
||||
[null, null, null, null], [null, null, null, null], [null, null, null, null],
|
||||
|
||||
*/
|
||||
|
||||
const middleMatrixIdx = 7;
|
||||
const leftMatrixIdx = 8;
|
||||
|
||||
it("Finds which node to go to", () => {
|
||||
// from unknown to left unknown
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...unknownNodeTemplate,
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 2, colIdx: 3 },
|
||||
},
|
||||
"left",
|
||||
3,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "unknown",
|
||||
matrixIndices: { rowIdx: 2, colIdx: 3, matrixIdx: leftMatrixIdx },
|
||||
didMove: true,
|
||||
});
|
||||
|
||||
// from 0405 down
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0405"],
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 2, colIdx: 3 },
|
||||
},
|
||||
"down",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "unknown",
|
||||
matrixIndices: { rowIdx: 2, colIdx: 3, matrixIdx: middleMatrixIdx },
|
||||
didMove: true,
|
||||
});
|
||||
|
||||
// from 0422 (from left matrix) right
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0422"],
|
||||
matrixIndices: { matrixIdx: 8, rowIdx: 0, colIdx: 3 },
|
||||
},
|
||||
"right",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "0413",
|
||||
matrixIndices: { rowIdx: 1, colIdx: 3, matrixIdx: 7 },
|
||||
didMove: true,
|
||||
});
|
||||
|
||||
// from 0422 left
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0422"],
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 0, colIdx: 0 },
|
||||
},
|
||||
"left",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "0422",
|
||||
matrixIndices: { rowIdx: 0, colIdx: 3, matrixIdx: 8 },
|
||||
didMove: true,
|
||||
});
|
||||
|
||||
// from 0422 up
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0422"],
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 0, colIdx: 0 },
|
||||
},
|
||||
"up",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "0506",
|
||||
matrixIndices: { rowIdx: 2, colIdx: 0, matrixIdx: 7 },
|
||||
didMove: true,
|
||||
});
|
||||
|
||||
// from 0422 right
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0422"],
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 0, colIdx: 0 },
|
||||
},
|
||||
"right",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "0417",
|
||||
matrixIndices: { rowIdx: 0, colIdx: 1, matrixIdx: 7 },
|
||||
didMove: false,
|
||||
});
|
||||
|
||||
// from 0414 up
|
||||
expect(
|
||||
findNode(
|
||||
{
|
||||
...site_a["04"]["0414"],
|
||||
matrixIndices: { matrixIdx: middleMatrixIdx, rowIdx: 1, colIdx: 0 },
|
||||
},
|
||||
"up",
|
||||
4,
|
||||
"a",
|
||||
gameProgress,
|
||||
true
|
||||
)
|
||||
).toEqual({
|
||||
node: "0422",
|
||||
matrixIndices: { rowIdx: 0, colIdx: 0, matrixIdx: 7 },
|
||||
didMove: false,
|
||||
});
|
||||
});
|
29
src/tests/helpers/node-helpers.test.ts
Normal file
29
src/tests/helpers/node-helpers.test.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
import { getNodeById, isNodeVisible } from "../../helpers/node-helpers";
|
||||
import site_a from "../../resources/site_a.json";
|
||||
import gameProgress from "../../resources/initial_progress.json";
|
||||
|
||||
it("Finds the node by it's id", () => {
|
||||
expect(getNodeById("0422", "a").node_name).toEqual("Tda028");
|
||||
expect(getNodeById("0000", "a").node_name).toEqual("Env001");
|
||||
expect(getNodeById("0616", "a").node_name).toEqual("Cou015");
|
||||
expect(getNodeById("0100", "b").node_name).toEqual("Sskn04#");
|
||||
expect(getNodeById("0101", "b").node_name).toEqual("Dc1025");
|
||||
});
|
||||
|
||||
const oneViewCount = { ...gameProgress, final_video_viewcount: 1 };
|
||||
const twoViewCount = { ...gameProgress, final_video_viewcount: 2 };
|
||||
const threeViewCount = { ...gameProgress, final_video_viewcount: 3 };
|
||||
const fourViewCount = { ...gameProgress, final_video_viewcount: 4 };
|
||||
|
||||
it("Checks if the node is visible", () => {
|
||||
expect(isNodeVisible(site_a["04"]["0422"], gameProgress)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["04"]["0413"], gameProgress)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["04"]["0406"], gameProgress)).toEqual(false);
|
||||
expect(isNodeVisible(site_a["04"]["0410"], gameProgress)).toEqual(false);
|
||||
expect(isNodeVisible(site_a["04"]["0406"], oneViewCount)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["06"]["0612"], gameProgress)).toEqual(false);
|
||||
expect(isNodeVisible(site_a["06"]["0612"], oneViewCount)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["06"]["0612"], twoViewCount)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["08"]["0801"], fourViewCount)).toEqual(true);
|
||||
expect(isNodeVisible(site_a["08"]["0801"], threeViewCount)).toEqual(false);
|
||||
});
|
|
@ -1,2 +0,0 @@
|
|||
import { findNodeFromWord } from "../helpers/media-helpers";
|
||||
|
Loading…
Reference in a new issue