implementing new node table/visibility checker

This commit is contained in:
ad044 2020-12-20 01:01:46 +04:00
parent 8220e3ca2a
commit 02f0823a24
10 changed files with 7643 additions and 3866 deletions

View file

@ -4,9 +4,10 @@ import node_positions from "../../resources/node_positions.json";
import site_a from "../../resources/site_a.json";
import { useNodeStore, useLevelStore, useSiteStore } from "../../store";
import { a, useSpring } from "@react-spring/three";
import { isNodeVisible } from "../../core/nodeSelector";
const ActiveLevelNodes = () => {
const unlockedNodes = useNodeStore((state) => state.unlockedNodes);
const gameProgress = useNodeStore((state) => state.gameProgress);
const activeNodeState = useNodeStore((state) => state.activeNodeState);
const activeLevel = useLevelStore((state) => state.activeLevel);
@ -32,18 +33,7 @@ const ActiveLevelNodes = () => {
rotation-x={siteState.siteRotX}
>
{Object.entries(activeLevelNodes).map((node: [string, any]) => {
const unlockedBy = node[1].unlocked_by;
let unlocked;
if (unlockedBy === "-1") unlocked = true;
else
unlocked =
unlockedNodes[unlockedBy as keyof typeof unlockedNodes].unlocked;
if (
unlocked &&
(node[1].is_hidden === "0" || node[1].is_hidden === "3")
) {
if (isNodeVisible(node[0], gameProgress)) {
return (
<Node
sprite={node[1].node_name}

View file

@ -8,17 +8,20 @@ import { useLevelStore, useNodeStore, useSiteStore } from "../../store";
import PurpleRing from "./PurpleRing";
import GrayRing from "./GrayRing";
import CyanCrystal from "./CyanCrystal";
import { isNodeVisible } from "../../core/nodeSelector";
export type NodeDataType = {
image_table_indices: { 1: string; 2: string; 3: string };
is_hidden: string;
triggers_final_video: number;
required_final_video_viewcount: number;
media_file: string;
node_name: string;
site: string;
type: string;
type: number;
title: string;
unlocked_by: string;
upgrade_requirement: string;
upgrade_requirement: number;
protocol_lines: { 1: string; 2: string; 3: string; 4: string };
words: { 1: string; 2: string; 3: string };
};
@ -31,7 +34,7 @@ export type SiteType = {
};
const Site = memo(() => {
const unlockedNodes = useNodeStore((state) => state.unlockedNodes);
const gameProgress = useNodeStore((state) => state.gameProgress);
const activeLevel = useLevelStore((state) => state.activeLevel);
const visibleNodes = useMemo(() => {
@ -75,18 +78,7 @@ const Site = memo(() => {
</group>
))}
{Object.entries(visibleNodes).map((node: [string, any]) => {
const unlockedBy = node[1].unlocked_by;
let unlocked;
if (unlockedBy === "-1") unlocked = true;
else
unlocked =
unlockedNodes[unlockedBy as keyof typeof unlockedNodes].unlocked;
if (
unlocked &&
(node[1].is_hidden === "0" || node[1].is_hidden === "3")
) {
if (isNodeVisible(node[0], gameProgress)) {
return (
<Node
sprite={node[1].node_name}

View file

@ -38,8 +38,6 @@ const Images = () => {
Object.entries(images).forEach((img) => {
import("../../static/media_images/a/" + img[1] + ".png").then(
(imageSrc: { default: string }) => {
// images are unordered by default so we insert them into the arr
// according to their last char
imgArr.splice(parseInt(img[0]), 0, imageSrc);
if (imgArr.length === 3) {
setSceneImages(imgArr);

View file

@ -69,7 +69,7 @@ const EventManager = () => {
pauseMatrixIdx,
])
);
const unlockedNodes = useNodeStore((state) => state.unlockedNodes);
const gameProgress = useNodeStore((state) => state.gameProgress);
// media scene
const mediaComponentMatrixIndices = useMediaStore(
@ -153,7 +153,7 @@ const EventManager = () => {
selectedLevel: selectedLevel,
pauseMatrixIdx: pauseMatrixIdx,
activePauseComponent: activePauseComponent,
unlockedNodes: unlockedNodes,
gameProgress: gameProgress,
});
break;
case "media":
@ -205,7 +205,7 @@ const EventManager = () => {
rightSideComponentIdx,
selectedLevel,
siteTransformState,
unlockedNodes,
gameProgress,
wordPosStateIdx,
]
);

View file

@ -10,7 +10,7 @@ const handleMainSceneEvent = (gameContext: any) => {
const selectedLevel = gameContext.selectedLevel;
const pauseMatrixIdx = gameContext.pauseMatrixIdx;
const activePauseComponent = gameContext.activePauseComponent;
const unlockedNodes = gameContext.unlockedNodes;
const gameProgress = gameContext.gameProgress;
const activeNodeId = gameContext.activeNodeId;
let nodeMatrixIndices = gameContext.nodeMatrixIndices;
@ -40,7 +40,7 @@ const handleMainSceneEvent = (gameContext: any) => {
level: level,
siteRotY: siteRotY,
sitePosY: sitePosY,
unlockedNodes: unlockedNodes,
gameProgress: gameProgress,
});
if (selectedNodeData) {
@ -133,7 +133,7 @@ const handleMainSceneEvent = (gameContext: any) => {
level: selectedLevel,
siteRotY: siteRotY,
sitePosY: sitePosY,
unlockedNodes: unlockedNodes,
gameProgress: gameProgress,
});
if (level === selectedLevel) break;

View file

@ -1,7 +1,7 @@
import node_matrices from "../resources/node_matrices.json";
import site_a from "../resources/site_a.json";
import { SiteType } from "../components/MainScene/Site";
import unlocked_nodes from "../resources/unlocked_nodes.json";
import unlocked_nodes from "../resources/initial_progress.json";
import level_y_values from "../resources/level_y_values.json";
type NodeSelectorContext = {
@ -11,7 +11,7 @@ type NodeSelectorContext = {
level: number;
siteRotY: number;
sitePosY: number;
unlockedNodes: typeof unlocked_nodes;
gameProgress: typeof unlocked_nodes;
};
const hudAssocs = {
@ -54,24 +54,24 @@ export const getNodeHudId = (nodeMatrixIndices: {
`${nodeMatrixIndices.rowIdx}${nodeMatrixIndices.colIdx}` as keyof typeof hudAssocs
];
const isNodeVisible = (
nodeId: string,
unlockedNodes: typeof unlocked_nodes
) => {
export const isNodeVisible = (nodeId: string, gameProgress: typeof unlocked_nodes) => {
console.log(nodeId)
const nodeLevel = nodeId.substr(0, 2);
const nodeData = (site_a as SiteType)[nodeLevel][nodeId];
if (nodeData) {
const unlockedBy = nodeData.unlocked_by;
let unlocked;
if (unlockedBy === "-1") unlocked = true;
if (unlockedBy === "") unlocked = true;
else
unlocked =
unlockedNodes[unlockedBy as keyof typeof unlockedNodes].unlocked;
gameProgress[unlockedBy as keyof typeof gameProgress].is_viewed;
// visible = (global_final_viewcount > 0) && (req_final_viewcount <= global_final_viewcount + 1)
// ishidden checker needs tweaking, this is temp
return (
unlocked && (nodeData.is_hidden === "0" || nodeData.is_hidden === "3")
unlocked &&
gameProgress[nodeData.node_name as keyof typeof gameProgress].is_visible
);
} else {
return false;
@ -89,7 +89,7 @@ const tryRow = (row: number, triedRows: number[]) => {
};
const findNodeAfterLevelSelection = (
unlockedNodes: typeof unlocked_nodes,
gameProgress: typeof unlocked_nodes,
targetLevel: number,
nodeMatrixIndices: { matrixIdx: number; rowIdx: number; colIdx: number }
) => {
@ -101,7 +101,7 @@ const findNodeAfterLevelSelection = (
let newNodeId = getNodeId(targetLevel, newMatIndices);
while (!isNodeVisible(newNodeId, unlockedNodes)) {
while (!isNodeVisible(newNodeId, gameProgress)) {
if (triedCols.length < 4) {
triedCols.push(newMatIndices.colIdx);
const colToTry = tryCol(newMatIndices.colIdx, triedCols);
@ -138,7 +138,7 @@ const findNodeAfterLevelSelection = (
const findNodeVertical = (
direction: string,
unlockedNodes: typeof unlocked_nodes,
gameProgress: typeof unlocked_nodes,
level: number,
nodeMatrixIndices: { matrixIdx: number; rowIdx: number; colIdx: number }
) => {
@ -158,7 +158,7 @@ const findNodeVertical = (
newNodeId = getNodeId(newLevel, newMatIndices);
while (!isNodeVisible(newNodeId, unlockedNodes)) {
while (!isNodeVisible(newNodeId, gameProgress)) {
if (triedCols.length < 4) {
triedCols.push(newMatIndices.colIdx);
const colToTry = tryCol(newMatIndices.colIdx, triedCols);
@ -194,7 +194,7 @@ const findNodeVertical = (
newNodeId = getNodeId(newLevel, newMatIndices);
while (!isNodeVisible(newNodeId, unlockedNodes)) {
while (!isNodeVisible(newNodeId, gameProgress)) {
if (triedCols.length < 4) {
triedCols.push(newMatIndices.colIdx);
const colToTry = tryCol(newMatIndices.colIdx, triedCols);
@ -230,7 +230,7 @@ const findNodeVertical = (
const findNodeHorizontal = (
direction: string,
unlockedNodes: typeof unlocked_nodes,
gameProgress: typeof unlocked_nodes,
level: number,
activeId: string,
nodeMatrixIndices: { matrixIdx: number; rowIdx: number; colIdx: number }
@ -254,7 +254,7 @@ const findNodeHorizontal = (
newNodeId = getNodeId(level, newMatIndices);
while (!isNodeVisible(newNodeId, unlockedNodes)) {
while (!isNodeVisible(newNodeId, gameProgress)) {
if (triedRows.length < 3) {
triedRows.push(newMatIndices.rowIdx);
const rowToTry = tryRow(newMatIndices.rowIdx, triedRows);
@ -300,7 +300,7 @@ const findNodeHorizontal = (
newNodeId = getNodeId(level, newMatIndices);
while (!isNodeVisible(newNodeId, unlockedNodes)) {
while (!isNodeVisible(newNodeId, gameProgress)) {
if (triedRows.length < 3) {
triedRows.push(newMatIndices.rowIdx);
const rowToTry = tryRow(newMatIndices.rowIdx, triedRows);
@ -359,7 +359,7 @@ const nodeSelector = (context: NodeSelectorContext) => {
move = context.action === "site_left" ? "left" : "right";
newNodeData = findNodeHorizontal(
move,
context.unlockedNodes,
context.gameProgress,
context.level,
context.activeId,
context.nodeMatrixIndices
@ -387,7 +387,7 @@ const nodeSelector = (context: NodeSelectorContext) => {
newNodeData = findNodeVertical(
move,
context.unlockedNodes,
context.gameProgress,
context.level,
context.nodeMatrixIndices
);
@ -410,7 +410,7 @@ const nodeSelector = (context: NodeSelectorContext) => {
break;
case "select_level":
newNodeData = findNodeAfterLevelSelection(
context.unlockedNodes,
context.gameProgress,
context.level,
context.nodeMatrixIndices
);

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,7 +2,7 @@ import create from "zustand";
import { combine } from "zustand/middleware";
import * as THREE from "three";
import authorize_user_letters from "./resources/authorize_user_letters.json";
import unlocked_nodes from "./resources/unlocked_nodes.json";
import game_progress from "./resources/initial_progress.json";
type PauseState = {
exitAnimation: boolean;
@ -40,7 +40,7 @@ type NodeState = {
interactedWith: boolean;
};
nodeMatrixIndices: { matrixIdx: number; rowIdx: number; colIdx: number };
unlockedNodes: typeof unlocked_nodes;
gameProgress: typeof game_progress;
};
type LainState = {
@ -237,7 +237,7 @@ export const useNodeStore = create(
interactedWith: false,
},
nodeMatrixIndices: { matrixIdx: 7, rowIdx: 0, colIdx: 0 },
unlockedNodes: unlocked_nodes,
gameProgress: game_progress,
} as NodeState,
(set) => ({
setActiveNodeState: (to: number | boolean | string, at: string) =>