bug fixes and tweaks

This commit is contained in:
ad044 2020-11-02 23:25:12 +04:00
parent e0cc665c63
commit 83fc6e1e53
8 changed files with 116 additions and 46 deletions

View file

@ -13,7 +13,6 @@ type SetIsActiveBlueOrbInteractedWith = (value: boolean) => void;
type BlueOrbDispatchData = { type BlueOrbDispatchData = {
action: any; action: any;
value: any; value: any;
actionDelay: number;
}; };
type BlueOrbDispatcher = { type BlueOrbDispatcher = {
@ -76,13 +75,17 @@ const BlueOrbManager = (props: StateManagerProps) => {
const updateActiveBlueOrb = useCallback( const updateActiveBlueOrb = useCallback(
( (
delay: number,
newActiveBlueOrbId: string, newActiveBlueOrbId: string,
newBlueOrbColIdx: number, newBlueOrbColIdx: number,
newBlueOrbRowIdx: number newBlueOrbRowIdx: number
) => { ) => {
setActiveBlueOrb("");
setTimeout(() => {
setActiveBlueOrb(newActiveBlueOrbId); setActiveBlueOrb(newActiveBlueOrbId);
setBlueOrbColIdx(newBlueOrbColIdx); setBlueOrbColIdx(newBlueOrbColIdx);
setBlueOrbRowIdx(newBlueOrbRowIdx); setBlueOrbRowIdx(newBlueOrbRowIdx);
}, delay);
}, },
[setActiveBlueOrb, setBlueOrbColIdx, setBlueOrbRowIdx] [setActiveBlueOrb, setBlueOrbColIdx, setBlueOrbRowIdx]
); );
@ -97,33 +100,47 @@ const BlueOrbManager = (props: StateManagerProps) => {
const dispatcherObjects: BlueOrbDispatcher = { const dispatcherObjects: BlueOrbDispatcher = {
move_up: { move_up: {
action: updateActiveBlueOrb, action: updateActiveBlueOrb,
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx], value: [
actionDelay: 3903.704, 3903.704,
newActiveBlueOrbId,
newBlueOrbColIdx,
newBlueOrbRowIdx,
],
}, },
move_down: { move_down: {
action: updateActiveBlueOrb, action: updateActiveBlueOrb,
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx], value: [
actionDelay: 3903.704, 3903.704,
newActiveBlueOrbId,
newBlueOrbColIdx,
newBlueOrbRowIdx,
],
}, },
move_left: { move_left: {
action: updateActiveBlueOrb, action: updateActiveBlueOrb,
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx], value: [
actionDelay: 3903.704, 3903.704,
newActiveBlueOrbId,
newBlueOrbColIdx,
newBlueOrbRowIdx,
],
}, },
move_right: { move_right: {
action: updateActiveBlueOrb, action: updateActiveBlueOrb,
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx], value: [
actionDelay: 3903.704, 3903.704,
newActiveBlueOrbId,
newBlueOrbColIdx,
newBlueOrbRowIdx,
],
}, },
change_blue_orb: { change_blue_orb: {
action: updateActiveBlueOrb, action: updateActiveBlueOrb,
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx], value: [0, newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
actionDelay: 0,
}, },
throw_blue_orb: { throw_blue_orb: {
action: animateActiveBlueOrbThrow, action: animateActiveBlueOrbThrow,
value: [true], value: [0, true],
actionDelay: 0,
}, },
}; };
@ -146,12 +163,8 @@ const BlueOrbManager = (props: StateManagerProps) => {
newBlueOrbRowIdx newBlueOrbRowIdx
); );
console.log(dispatchedObject)
if (dispatchedObject) { if (dispatchedObject) {
setTimeout(() => {
dispatchedObject.action.apply(null, dispatchedObject.value); dispatchedObject.action.apply(null, dispatchedObject.value);
}, dispatchedObject.actionDelay);
} }
} }
}, [props.eventState, setActiveBlueOrb, dispatchObject]); }, [props.eventState, setActiveBlueOrb, dispatchObject]);

View file

@ -101,7 +101,6 @@ const EventManager = () => {
if (keyPress && !inputCooldown) { if (keyPress && !inputCooldown) {
gameContext.keyPress = keyPress; gameContext.keyPress = keyPress;
const event = computeAction(gameContext); const event = computeAction(gameContext);
console.log(event);
setEventState(event); setEventState(event);
} }
}, },

View file

@ -1,5 +1,5 @@
import { useCallback, useEffect } from "react"; import { MutableRefObject, useCallback, useEffect, useRef } from "react";
import { useTextRendererStore } from "../../store"; import { useBlueOrbStore, useTextRendererStore } from "../../store";
import site_a from "../../resources/site_a.json"; import site_a from "../../resources/site_a.json";
import { StateManagerProps } from "./EventManager"; import { StateManagerProps } from "./EventManager";
import blue_orb_huds from "../../resources/blue_orb_huds.json"; import blue_orb_huds from "../../resources/blue_orb_huds.json";
@ -16,8 +16,19 @@ const GreenTextManager = (props: StateManagerProps) => {
(state) => state.toggleGreenText (state) => state.toggleGreenText
); );
const blueOrbDataRef: MutableRefObject<
{ activeBlueOrbId: string } | undefined
> = useRef();
const activeBlueOrbId = useBlueOrbStore((state) => state.activeBlueOrbId);
blueOrbDataRef.current = {
activeBlueOrbId: activeBlueOrbId,
};
const toggleAndSetGreenText = useCallback( const toggleAndSetGreenText = useCallback(
(newActiveBlueOrbId: string, newActiveHudId: string, delay: number) => { (newActiveBlueOrbId: string, newActiveHudId: string, delay: number) => {
console.log('s')
const targetGreenText = const targetGreenText =
site_a[newActiveBlueOrbId as keyof typeof site_a].title; site_a[newActiveBlueOrbId as keyof typeof site_a].title;
@ -39,6 +50,17 @@ const GreenTextManager = (props: StateManagerProps) => {
[setGreenText, setGreenTextPosX, setGreenTextPosY, toggleGreenText] [setGreenText, setGreenTextPosX, setGreenTextPosY, toggleGreenText]
); );
const initializeGreenTextForMediaScene = useCallback(() => {
setTimeout(() => {
setGreenText(
site_a[blueOrbDataRef.current!.activeBlueOrbId as keyof typeof site_a]
.node_name
);
setGreenTextPosX({ initial: 0.0, final: 0.009 });
setGreenTextPosY(0.675);
}, 3950);
}, [setGreenText, setGreenTextPosX, setGreenTextPosY]);
const dispatchObject = useCallback( const dispatchObject = useCallback(
(event: string, newActiveBlueOrbId: string, newActiveHudId: string) => { (event: string, newActiveBlueOrbId: string, newActiveHudId: string) => {
const dispatcherObjects = { const dispatcherObjects = {
@ -62,11 +84,15 @@ const GreenTextManager = (props: StateManagerProps) => {
action: toggleAndSetGreenText, action: toggleAndSetGreenText,
value: [newActiveBlueOrbId, newActiveHudId, 500], value: [newActiveBlueOrbId, newActiveHudId, 500],
}, },
throw_blue_orb: {
action: initializeGreenTextForMediaScene,
value: [],
},
}; };
return dispatcherObjects[event as keyof typeof dispatcherObjects]; return dispatcherObjects[event as keyof typeof dispatcherObjects];
}, },
[toggleAndSetGreenText] [initializeGreenTextForMediaScene, toggleAndSetGreenText]
); );
useEffect(() => { useEffect(() => {

View file

@ -4,23 +4,39 @@ import { useLevelStore } from "../../store";
const LevelManager = (props: StateManagerProps) => { const LevelManager = (props: StateManagerProps) => {
const setCurrentLevel = useLevelStore((state) => state.setCurrentLevel); const setCurrentLevel = useLevelStore((state) => state.setCurrentLevel);
const setActiveLevels = useLevelStore((state) => state.setActiveLevels);
const updateLevel = useCallback(
(newLevel: string) => {
setCurrentLevel(newLevel);
setTimeout(() => {
setActiveLevels([
(parseInt(newLevel) - 2).toString().padStart(2, "0"),
(parseInt(newLevel) - 1).toString().padStart(2, "0"),
parseInt(newLevel).toString().padStart(2, "0"),
(parseInt(newLevel) + 1).toString().padStart(2, "0"),
(parseInt(newLevel) + 2).toString().padStart(2, "0"),
]);
}, 1500);
},
[setActiveLevels, setCurrentLevel]
);
const dispatchObject = useCallback( const dispatchObject = useCallback(
(event: string, newLevel: string) => { (event: string, newLevel: string) => {
const dispatcherObjects = { const dispatcherObjects = {
move_up: { move_up: {
action: setCurrentLevel, action: updateLevel,
value: newLevel, value: newLevel,
}, },
move_down: { move_down: {
action: setCurrentLevel, action: updateLevel,
value: newLevel, value: newLevel,
}, },
}; };
return dispatcherObjects[event as keyof typeof dispatcherObjects]; return dispatcherObjects[event as keyof typeof dispatcherObjects];
}, },
[setCurrentLevel] [updateLevel]
); );
useEffect(() => { useEffect(() => {

View file

@ -14,6 +14,7 @@ const MediaImageManager = (props: StateManagerProps) => {
site_a[newActiveBlueOrbId as keyof typeof site_a].node_name; site_a[newActiveBlueOrbId as keyof typeof site_a].node_name;
const images = image_table[node_name as keyof typeof image_table]; const images = image_table[node_name as keyof typeof image_table];
console.log(newActiveBlueOrbId);
Object.values(images).forEach((img) => { Object.values(images).forEach((img) => {
switch (img.substr(img.length - 1)) { switch (img.substr(img.length - 1)) {
case "0": case "0":
@ -61,9 +62,11 @@ const MediaImageManager = (props: StateManagerProps) => {
useEffect(() => { useEffect(() => {
if (props.eventState) { if (props.eventState) {
const eventAction = props.eventState.action; const eventAction = props.eventState.event;
const newActiveBlueOrbId = props.eventState.newActiveBlueOrbId; const newActiveBlueOrbId = props.eventState.newActiveBlueOrbId;
console.log(eventAction);
console.log(newActiveBlueOrbId);
const dispatchedObject = dispatchObject(eventAction, newActiveBlueOrbId); const dispatchedObject = dispatchObject(eventAction, newActiveBlueOrbId);
if (dispatchedObject) { if (dispatchedObject) {

View file

@ -9,8 +9,10 @@ import {
type AnimateYellowTextWithMove = ( type AnimateYellowTextWithMove = (
yellowLetterPosYOffset: number, yellowLetterPosYOffset: number,
yellowLetterPosXOffset: number,
newActiveHudId: string, newActiveHudId: string,
newActiveBlueOrbId: string newActiveBlueOrbId: string,
delay: number
) => void; ) => void;
type AnimateYellowTextWithoutMove = ( type AnimateYellowTextWithoutMove = (
@ -62,8 +64,11 @@ const YellowTextManager = (props: any) => {
(state) => state.setYellowTextOffsetXCoeff (state) => state.setYellowTextOffsetXCoeff
); );
const incrementYellowTextPosY = useTextRendererStore( const addToYellowTextPosY = useTextRendererStore(
(state) => state.incrementYellowTextPosY (state) => state.addToYellowTextPosY
);
const addToYellowTextPosX = useTextRendererStore(
(state) => state.addToYellowTextPosX
); );
const setYellowTextPosY = useTextRendererStore( const setYellowTextPosY = useTextRendererStore(
(state) => state.setYellowTextPosY (state) => state.setYellowTextPosY
@ -74,15 +79,18 @@ const YellowTextManager = (props: any) => {
const animateYellowTextWithMove: AnimateYellowTextWithMove = useCallback( const animateYellowTextWithMove: AnimateYellowTextWithMove = useCallback(
( (
yellowLetterPosXOffset: number,
yellowLetterPosYOffset: number, yellowLetterPosYOffset: number,
newActiveHudId: string, newActiveHudId: string,
newActiveBlueOrbId: string newActiveBlueOrbId: string,
delay: number
) => { ) => {
// animate the letters to match that of site's // animate the letters to match that of site's
// to create an illusion of not moving // to create an illusion of not moving
setTimeout(() => { setTimeout(() => {
incrementYellowTextPosY(yellowLetterPosYOffset); addToYellowTextPosY(yellowLetterPosYOffset);
}, 1300); addToYellowTextPosX(yellowLetterPosXOffset);
}, delay);
setTimeout(() => { setTimeout(() => {
// make current hud big text shrink // make current hud big text shrink
@ -91,6 +99,7 @@ const YellowTextManager = (props: any) => {
setTimeout(() => { setTimeout(() => {
// animate it to new pos x/y // animate it to new pos x/y
console.log(newActiveHudId);
setYellowTextPosX( setYellowTextPosX(
blue_orb_huds[newActiveHudId as keyof typeof blue_orb_huds] blue_orb_huds[newActiveHudId as keyof typeof blue_orb_huds]
.big_text[0] .big_text[0]
@ -111,7 +120,8 @@ const YellowTextManager = (props: any) => {
}, 3900); }, 3900);
}, },
[ [
incrementYellowTextPosY, addToYellowTextPosX,
addToYellowTextPosY,
setYellowText, setYellowText,
setYellowTextOffsetXCoeff, setYellowTextOffsetXCoeff,
setYellowTextPosX, setYellowTextPosX,
@ -222,19 +232,19 @@ const YellowTextManager = (props: any) => {
const dispatcherObjects: YellowTextDispatcher = { const dispatcherObjects: YellowTextDispatcher = {
move_up: { move_up: {
action: animateYellowTextWithMove, action: animateYellowTextWithMove,
value: [-1.5, newActiveHudId, newActiveBlueOrbId], value: [0, -1.5, newActiveHudId, newActiveBlueOrbId, 1300],
}, },
move_down: { move_down: {
action: animateYellowTextWithMove, action: animateYellowTextWithMove,
value: [1.5, newActiveHudId, newActiveBlueOrbId], value: [0, 1.5, newActiveHudId, newActiveBlueOrbId, 1300],
}, },
move_left: { move_left: {
action: animateYellowTextWithMove, action: animateYellowTextWithMove,
value: [newActiveHudId, newActiveBlueOrbId], value: [Math.PI / 4, 0, newActiveHudId, newActiveBlueOrbId, 1100],
}, },
move_right: { move_right: {
action: animateYellowTextWithMove, action: animateYellowTextWithMove,
value: [newActiveHudId, newActiveBlueOrbId], value: [-Math.PI / 4, 0, newActiveHudId, newActiveBlueOrbId, 1100],
}, },
change_blue_orb: { change_blue_orb: {
action: animateYellowTextWithoutMove, action: animateYellowTextWithoutMove,

View file

@ -71,7 +71,7 @@ const handleMainSceneEvent = (gameContext: GameContext) => {
if (newBlueOrbColIdx > 3) { if (newBlueOrbColIdx > 3) {
event = "move_right"; event = "move_right";
newSiteRotIdx = (parseInt(gameContext.siteRotIdx) - 1).toString(); newSiteRotIdx = (parseInt(gameContext.siteRotIdx) - 1).toString();
newBlueOrbColIdx = 0; newBlueOrbColIdx = 3;
} else { } else {
event = "change_blue_orb"; event = "change_blue_orb";
} }

View file

@ -134,7 +134,8 @@ type TextRendererState = {
yellowTextPosX: number; yellowTextPosX: number;
yellowTextOffsetXCoeff: number; yellowTextOffsetXCoeff: number;
setYellowText: (to: string) => void; setYellowText: (to: string) => void;
incrementYellowTextPosY: (by: number) => void; addToYellowTextPosY: (val: number) => void;
addToYellowTextPosX: (val: number) => void;
setYellowTextPosY: (to: number) => void; setYellowTextPosY: (to: number) => void;
setYellowTextPosX: (to: number) => void; setYellowTextPosX: (to: number) => void;
setYellowTextOffsetXCoeff: (to: number) => void; setYellowTextOffsetXCoeff: (to: number) => void;
@ -167,8 +168,10 @@ export const useTextRendererStore = create<TextRendererState>((set) => ({
yellowTextPosX: -0.35, yellowTextPosX: -0.35,
yellowTextOffsetXCoeff: 0, yellowTextOffsetXCoeff: 0,
setYellowText: (to) => set(() => ({ yellowText: to })), setYellowText: (to) => set(() => ({ yellowText: to })),
incrementYellowTextPosY: (by) => addToYellowTextPosY: (val) =>
set((state) => ({ yellowTextPosY: state.yellowTextPosY + by })), set((state) => ({ yellowTextPosY: state.yellowTextPosY + val })),
addToYellowTextPosX: (val) =>
set((state) => ({ yellowTextPosX: state.yellowTextPosX + val })),
setYellowTextPosY: (to) => set(() => ({ yellowTextPosY: to })), setYellowTextPosY: (to) => set(() => ({ yellowTextPosY: to })),
setYellowTextPosX: (to) => set(() => ({ yellowTextPosX: to })), setYellowTextPosX: (to) => set(() => ({ yellowTextPosX: to })),
setYellowTextOffsetXCoeff: (to) => setYellowTextOffsetXCoeff: (to) =>
@ -283,7 +286,7 @@ export const useMiddleRingStore = create<MiddleRingState>((set) => ({
export const useLevelStore = create<LevelState>((set) => ({ export const useLevelStore = create<LevelState>((set) => ({
currentLevel: "04", currentLevel: "04",
activeLevels: ["03", "04", "05"], activeLevels: ["02", "03", "04", "05", "06"],
setActiveLevels: (to) => set(() => ({ activeLevels: to })), setActiveLevels: (to) => set(() => ({ activeLevels: to })),
setCurrentLevel: (to) => set(() => ({ currentLevel: to })), setCurrentLevel: (to) => set(() => ({ currentLevel: to })),
})); }));
@ -379,7 +382,7 @@ export const useMediaWordStore = create<MediaWordState>((set) => ({
})); }));
export const useSceneStore = create<SceneState>((set) => ({ export const useSceneStore = create<SceneState>((set) => ({
currentScene: "media", currentScene: "main",
setScene: (to) => set(() => ({ currentScene: to })), setScene: (to) => set(() => ({ currentScene: to })),
})); }));