word select algo works i think

This commit is contained in:
ad044 2021-02-03 01:00:29 +04:00
parent 7a10c7cfe0
commit 1e8a8e6aab
4 changed files with 19 additions and 19 deletions

View file

@ -95,7 +95,9 @@ const KeyPressHandler = () => {
const { contextProvider, handler, setters } = { ...sceneFns }; const { contextProvider, handler, setters } = { ...sceneFns };
const ctx = { ...contextProvider(), keyPress: keyPress }; const ctx = { ...contextProvider(), keyPress: keyPress };
const event = handler(ctx); const event = handler(ctx);
setters.forEach((fn) => fn(event)); if (event) {
setters.forEach((fn) => fn(event));
}
} }
} }
} }

View file

@ -5,6 +5,7 @@ const siteManager = (eventState: any) => {
const setRotX = useStore.getState().setSiteRotX; const setRotX = useStore.getState().setSiteRotX;
const dispatchAction = (eventState: any) => { const dispatchAction = (eventState: any) => {
console.log(eventState.siteRotY);
switch (eventState.event) { switch (eventState.event) {
case "site_left": case "site_left":
case "site_right": case "site_right":

View file

@ -114,7 +114,7 @@ export const useStore = create(
combine( combine(
{ {
// scene data // scene data
currentScene: "main", currentScene: "media",
// game progress // game progress
gameProgress: game_progress, gameProgress: game_progress,
@ -466,6 +466,6 @@ export const getMediaSceneContext = () => {
rightSideComponentIdx: state.mediaComponentMatrixIndices.rightSideIdx, rightSideComponentIdx: state.mediaComponentMatrixIndices.rightSideIdx,
wordPosStateIdx: state.mediaWordPosStateIdx, wordPosStateIdx: state.mediaWordPosStateIdx,
activeNode: state.activeNode, activeNode: state.activeNode,
site: state.activeSite, activeSite: state.activeSite,
}; };
}; };

View file

@ -5,13 +5,11 @@ import {
NodeDataType, NodeDataType,
SiteType, SiteType,
} from "../components/MainScene/SyncedComponents/Site"; } from "../components/MainScene/SyncedComponents/Site";
import { NodeLib } from "three/examples/jsm/nodes/core/NodeLib";
import { isNodeVisible } from "./node-utils";
export const findNodeFromWord = ( export const findNodeFromWord = (
wordLabel: string, wordLabel: string,
activeNode: NodeDataType, activeNode: NodeDataType,
site: string site: "a" | "b"
) => { ) => {
const labelToIdx = (() => { const labelToIdx = (() => {
switch (wordLabel) { switch (wordLabel) {
@ -46,30 +44,29 @@ export const findNodeFromWord = (
//todo check if visible //todo check if visible
const pos = chosenNode.id.substr(2); const pos = chosenNode.id.substr(2);
const matIdx = Object.entries(node_matrices).flatMap((matrixData) => const matrixIndices = Object.entries(node_matrices).flatMap((matrixData) =>
matrixData[1].filter((row) => row[0] === pos).length > 0 matrixData[1].flatMap((row, idx) =>
? matrixData[0] row[0] === pos ? { matrixIdx: matrixData[0], rowIdx: idx, colIdx: 0 } : []
: [] )
)[0]; )[0];
const rotValues = { const rotValues = {
"1": 6 * (-Math.PI / 4), "1": 2 * (Math.PI / 4),
"2": 5 * (-Math.PI / 4), "2": 3 * (Math.PI / 4),
"3": 4 * (-Math.PI / 4), "3": 4 * (Math.PI / 4),
"4": 3 * (-Math.PI / 4), "4": 5 * (Math.PI / 4),
"5": 2 * (-Math.PI / 4), "5": 6 * (Math.PI / 4),
"6": -Math.PI / 4, "6": 7 * (Math.PI / 4),
"7": 0, "7": 0,
"8": Math.PI / 4, "8": Math.PI / 4,
}; };
console.log(chosenNode);
return { return {
node: { node: {
...chosenNode, ...chosenNode,
matrixIndices: { colIdx: 0, matrixIdx: matIdx, rowIdx: 0 }, matrixIndices: matrixIndices,
}, },
siteRotY: rotValues[matIdx as keyof typeof rotValues], siteRotY: rotValues[matrixIndices.matrixIdx as keyof typeof rotValues],
level: chosenNode.id.substr(0, 2), level: chosenNode.id.substr(0, 2),
}; };
}; };