mirror of
https://github.com/ad044/lainTSX.git
synced 2024-10-22 23:19:06 +00:00
basic orb changing works
This commit is contained in:
parent
80d816d576
commit
cddbc7ce62
8 changed files with 245 additions and 159 deletions
|
@ -1,14 +1,18 @@
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
import { useBlueOrbStore } from "../../store";
|
import { useBlueOrbStore } from "../../store";
|
||||||
import game_action_mappings from "../../resources/game_action_mappings.json";
|
|
||||||
import { StateManagerProps } from "./EventManager";
|
import { StateManagerProps } from "./EventManager";
|
||||||
|
|
||||||
type SetActiveBlueOrb = (value: string) => void;
|
type UpdateActiveBlueOrb = (
|
||||||
|
newActiveBlueOrbId: string,
|
||||||
|
newBlueOrbColIdx: number,
|
||||||
|
newBlueOrbRowIdx: number
|
||||||
|
) => void;
|
||||||
|
|
||||||
type SetIsActiveBlueOrbInteractedWith = (value: boolean) => void;
|
type SetIsActiveBlueOrbInteractedWith = (value: boolean) => void;
|
||||||
|
|
||||||
type BlueOrbDispatchData = {
|
type BlueOrbDispatchData = {
|
||||||
action: SetActiveBlueOrb | SetIsActiveBlueOrbInteractedWith;
|
action: any;
|
||||||
value: string | boolean;
|
value: any;
|
||||||
actionDelay: number;
|
actionDelay: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -22,9 +26,10 @@ type BlueOrbDispatcher = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const BlueOrbManager = (props: StateManagerProps) => {
|
const BlueOrbManager = (props: StateManagerProps) => {
|
||||||
const setActiveBlueOrb: SetActiveBlueOrb = useBlueOrbStore(
|
const setActiveBlueOrb = useBlueOrbStore((state) => state.setActiveBlueOrbId);
|
||||||
(state) => state.setActiveBlueOrbId
|
const setBlueOrbRowIdx = useBlueOrbStore((state) => state.setBlueOrbRowIdx);
|
||||||
);
|
const setBlueOrbColIdx = useBlueOrbStore((state) => state.setBlueOrbColIdx);
|
||||||
|
|
||||||
const setIsActiveBlueOrbInteractedWith: SetIsActiveBlueOrbInteractedWith = useBlueOrbStore(
|
const setIsActiveBlueOrbInteractedWith: SetIsActiveBlueOrbInteractedWith = useBlueOrbStore(
|
||||||
(state) => state.setIsActiveBlueOrbInteractedWith
|
(state) => state.setIsActiveBlueOrbInteractedWith
|
||||||
);
|
);
|
||||||
|
@ -69,32 +74,50 @@ const BlueOrbManager = (props: StateManagerProps) => {
|
||||||
setIsActiveBlueOrbInteractedWith,
|
setIsActiveBlueOrbInteractedWith,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
const updateActiveBlueOrb = useCallback(
|
||||||
|
(
|
||||||
|
newActiveBlueOrbId: string,
|
||||||
|
newBlueOrbColIdx: number,
|
||||||
|
newBlueOrbRowIdx: number
|
||||||
|
) => {
|
||||||
|
setActiveBlueOrb(newActiveBlueOrbId);
|
||||||
|
setBlueOrbColIdx(newBlueOrbColIdx);
|
||||||
|
setBlueOrbRowIdx(newBlueOrbRowIdx);
|
||||||
|
},
|
||||||
|
[setActiveBlueOrb, setBlueOrbColIdx, setBlueOrbRowIdx]
|
||||||
|
);
|
||||||
|
|
||||||
const dispatchObject = useCallback(
|
const dispatchObject = useCallback(
|
||||||
(event: string, targetBlueOrbId: string) => {
|
(
|
||||||
|
event: string,
|
||||||
|
newActiveBlueOrbId: string,
|
||||||
|
newBlueOrbColIdx: number,
|
||||||
|
newBlueOrbRowIdx: number
|
||||||
|
) => {
|
||||||
const dispatcherObjects: BlueOrbDispatcher = {
|
const dispatcherObjects: BlueOrbDispatcher = {
|
||||||
move_up: {
|
move_up: {
|
||||||
action: setActiveBlueOrb,
|
action: updateActiveBlueOrb,
|
||||||
value: targetBlueOrbId,
|
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
|
||||||
actionDelay: 3903.704,
|
actionDelay: 3903.704,
|
||||||
},
|
},
|
||||||
move_down: {
|
move_down: {
|
||||||
action: setActiveBlueOrb,
|
action: updateActiveBlueOrb,
|
||||||
value: targetBlueOrbId,
|
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
|
||||||
actionDelay: 3903.704,
|
actionDelay: 3903.704,
|
||||||
},
|
},
|
||||||
move_left: {
|
move_left: {
|
||||||
action: setActiveBlueOrb,
|
action: updateActiveBlueOrb,
|
||||||
value: targetBlueOrbId,
|
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
|
||||||
actionDelay: 3903.704,
|
actionDelay: 3903.704,
|
||||||
},
|
},
|
||||||
move_right: {
|
move_right: {
|
||||||
action: setActiveBlueOrb,
|
action: updateActiveBlueOrb,
|
||||||
value: targetBlueOrbId,
|
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
|
||||||
actionDelay: 3903.704,
|
actionDelay: 3903.704,
|
||||||
},
|
},
|
||||||
change_blue_orb: {
|
change_blue_orb: {
|
||||||
action: setActiveBlueOrb,
|
action: updateActiveBlueOrb,
|
||||||
value: targetBlueOrbId,
|
value: [newActiveBlueOrbId, newBlueOrbColIdx, newBlueOrbRowIdx],
|
||||||
actionDelay: 0,
|
actionDelay: 0,
|
||||||
},
|
},
|
||||||
select_blue_orb: {
|
select_blue_orb: {
|
||||||
|
@ -106,27 +129,29 @@ const BlueOrbManager = (props: StateManagerProps) => {
|
||||||
|
|
||||||
return dispatcherObjects[event as keyof typeof dispatcherObjects];
|
return dispatcherObjects[event as keyof typeof dispatcherObjects];
|
||||||
},
|
},
|
||||||
[animateActiveBlueOrbThrow, setActiveBlueOrb]
|
[animateActiveBlueOrbThrow, updateActiveBlueOrb]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.eventState) {
|
if (props.eventState) {
|
||||||
const eventObject: any =
|
const eventAction = props.eventState.event;
|
||||||
game_action_mappings[
|
const newActiveBlueOrbId = props.eventState.newActiveBlueOrbId;
|
||||||
props.eventState as keyof typeof game_action_mappings
|
const newBlueOrbRowIdx = props.eventState.newBlueOrbRowIdx;
|
||||||
];
|
const newBlueOrbColIdx = props.eventState.newBlueOrbColIdx;
|
||||||
|
|
||||||
if (eventObject) {
|
const dispatchedObject = dispatchObject(
|
||||||
const eventAction = eventObject.action;
|
eventAction,
|
||||||
const targetBlueOrbId = eventObject.target_blue_orb_id;
|
newActiveBlueOrbId,
|
||||||
|
newBlueOrbColIdx,
|
||||||
|
newBlueOrbRowIdx
|
||||||
|
);
|
||||||
|
|
||||||
const dispatchedObject = dispatchObject(eventAction, targetBlueOrbId);
|
console.log(dispatchedObject)
|
||||||
|
|
||||||
if (dispatchedObject) {
|
if (dispatchedObject) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
dispatchedObject.action(dispatchedObject.value as never);
|
dispatchedObject.action.apply(null, dispatchedObject.value);
|
||||||
}, dispatchedObject.actionDelay);
|
}, dispatchedObject.actionDelay);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [props.eventState, setActiveBlueOrb, dispatchObject]);
|
}, [props.eventState, setActiveBlueOrb, dispatchObject]);
|
||||||
|
|
|
@ -20,6 +20,7 @@ import YellowTextManager from "./YellowTextManager";
|
||||||
import MediaImageManager from "./MediaImageManager";
|
import MediaImageManager from "./MediaImageManager";
|
||||||
import computeAction from "../../core/computeAction";
|
import computeAction from "../../core/computeAction";
|
||||||
import available_blue_orbs_on_projection from "../../resources/available_blue_orbs_on_projection.json";
|
import available_blue_orbs_on_projection from "../../resources/available_blue_orbs_on_projection.json";
|
||||||
|
import LevelManager from "./LevelManager";
|
||||||
|
|
||||||
const getKeyCodeAssociation = (keyCode: number): string => {
|
const getKeyCodeAssociation = (keyCode: number): string => {
|
||||||
const keyCodeAssocs = {
|
const keyCodeAssocs = {
|
||||||
|
@ -32,8 +33,16 @@ const getKeyCodeAssociation = (keyCode: number): string => {
|
||||||
return keyCodeAssocs[keyCode as keyof typeof keyCodeAssocs];
|
return keyCodeAssocs[keyCode as keyof typeof keyCodeAssocs];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type EventState = {
|
||||||
|
event: string;
|
||||||
|
newBlueOrbColIdx: number;
|
||||||
|
newBlueOrbRowIdx: number;
|
||||||
|
newLevel: string;
|
||||||
|
newActiveBlueOrbId: string;
|
||||||
|
newSiteRotIdx: string;
|
||||||
|
};
|
||||||
export type StateManagerProps = {
|
export type StateManagerProps = {
|
||||||
eventState: string;
|
eventState: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GameContext = {
|
export type GameContext = {
|
||||||
|
@ -46,36 +55,17 @@ export type GameContext = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const EventManager = () => {
|
const EventManager = () => {
|
||||||
const activeBlueOrb = useBlueOrbStore((state) => state.activeBlueOrbId);
|
|
||||||
const blueOrbRowIdx = useBlueOrbStore((state) => state.blueOrbRowIdx);
|
const blueOrbRowIdx = useBlueOrbStore((state) => state.blueOrbRowIdx);
|
||||||
const blueOrbColIdx = useBlueOrbStore((state) => state.blueOrbColIdx);
|
const blueOrbColIdx = useBlueOrbStore((state) => state.blueOrbColIdx);
|
||||||
|
|
||||||
const siteRotIdx = useSiteStore((state) => state.siteRotIdx);
|
const siteRotIdx = useSiteStore((state) => state.siteRotIdx);
|
||||||
const currentLevel = useLevelStore((state) => state.currentLevel);
|
const currentLevel = useLevelStore((state) => state.currentLevel);
|
||||||
|
|
||||||
const availableBlueOrbsForSelection = available_blue_orbs_on_projection[
|
const [eventState, setEventState] = useState<any>();
|
||||||
siteRotIdx as keyof typeof available_blue_orbs_on_projection
|
|
||||||
].map((posIdxArr) => posIdxArr.map((posIdx) => currentLevel + posIdx));
|
|
||||||
|
|
||||||
const selectedBlueOrb =
|
|
||||||
availableBlueOrbsForSelection[blueOrbRowIdx][blueOrbColIdx];
|
|
||||||
|
|
||||||
const [eventState, setEventState] = useState<string>();
|
|
||||||
const activeMediaComponent = useMediaStore(
|
|
||||||
(state) => state.activeMediaComponent
|
|
||||||
);
|
|
||||||
const currentScene = useSceneStore((state) => state.currentScene);
|
const currentScene = useSceneStore((state) => state.currentScene);
|
||||||
|
|
||||||
const [inputCooldown, setInputCooldown] = useState(false);
|
const [inputCooldown, setInputCooldown] = useState(false);
|
||||||
|
|
||||||
const sceneEventKey = useMemo(() => {
|
|
||||||
const keys = {
|
|
||||||
main: activeBlueOrb,
|
|
||||||
media: activeMediaComponent,
|
|
||||||
};
|
|
||||||
return keys[currentScene as keyof typeof keys];
|
|
||||||
}, [activeBlueOrb, activeMediaComponent, currentScene]);
|
|
||||||
|
|
||||||
const gameContext: GameContext = useMemo(
|
const gameContext: GameContext = useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
scene: currentScene,
|
scene: currentScene,
|
||||||
|
@ -96,12 +86,11 @@ 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);
|
console.log(event)
|
||||||
const eventId = `${sceneEventKey}_${keyPress}`;
|
setEventState(event);
|
||||||
setEventState(eventId);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[gameContext, inputCooldown, sceneEventKey]
|
[gameContext, inputCooldown]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -120,12 +109,13 @@ const EventManager = () => {
|
||||||
<SiteManager eventState={eventState!} />
|
<SiteManager eventState={eventState!} />
|
||||||
<LainManager eventState={eventState!} />
|
<LainManager eventState={eventState!} />
|
||||||
<MiddleRingManager eventState={eventState!} />
|
<MiddleRingManager eventState={eventState!} />
|
||||||
<MediaComponentManager eventState={eventState!} />
|
{/*<MediaComponentManager eventState={eventState!} />*/}
|
||||||
<MediaWordManager eventState={eventState!} />
|
{/*<MediaWordManager eventState={eventState!} />*/}
|
||||||
<MediaElementManager eventState={eventState!} />
|
{/*<MediaElementManager eventState={eventState!} />*/}
|
||||||
<SceneManager eventState={eventState!} />
|
<SceneManager eventState={eventState!} />
|
||||||
<YellowTextManager eventState={eventState!} />
|
<YellowTextManager eventState={eventState!} />
|
||||||
<MediaImageManager eventState={eventState!} />
|
{/*<MediaImageManager eventState={eventState!} />*/}
|
||||||
|
<LevelManager eventState={eventState!} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { useCallback, useEffect } from "react";
|
import { useCallback, useEffect } from "react";
|
||||||
import { useLainStore } from "../../store";
|
import { useLainStore } from "../../store";
|
||||||
import game_action_mappings from "../../resources/game_action_mappings.json";
|
|
||||||
import { StateManagerProps } from "./EventManager";
|
import { StateManagerProps } from "./EventManager";
|
||||||
|
|
||||||
const LainManager = (props: StateManagerProps) => {
|
const LainManager = (props: StateManagerProps) => {
|
||||||
|
@ -43,22 +42,15 @@ const LainManager = (props: StateManagerProps) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.eventState) {
|
if (props.eventState) {
|
||||||
const eventObject =
|
const eventAction = props.eventState.event;
|
||||||
game_action_mappings[
|
const dispatchedObject = dispatchObject(eventAction);
|
||||||
props.eventState as keyof typeof game_action_mappings
|
|
||||||
];
|
|
||||||
|
|
||||||
if (eventObject) {
|
if (dispatchedObject) {
|
||||||
const eventAction = eventObject.action;
|
dispatchedObject.action(dispatchedObject.value);
|
||||||
const dispatchedObject = dispatchObject(eventAction);
|
|
||||||
|
|
||||||
if (dispatchedObject) {
|
setTimeout(() => {
|
||||||
dispatchedObject.action(dispatchedObject.value);
|
setLainMoveState("standing");
|
||||||
|
}, dispatchedObject.duration);
|
||||||
setTimeout(() => {
|
|
||||||
setLainMoveState("standing");
|
|
||||||
}, dispatchedObject.duration);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [props.eventState, setLainMoveState, dispatchObject]);
|
}, [props.eventState, setLainMoveState, dispatchObject]);
|
||||||
|
|
41
src/components/StateManagers/LevelManager.tsx
Normal file
41
src/components/StateManagers/LevelManager.tsx
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
import { useCallback, useEffect } from "react";
|
||||||
|
import { StateManagerProps } from "./EventManager";
|
||||||
|
import { useLevelStore } from "../../store";
|
||||||
|
|
||||||
|
const LevelManager = (props: StateManagerProps) => {
|
||||||
|
const setCurrentLevel = useLevelStore((state) => state.setCurrentLevel);
|
||||||
|
|
||||||
|
const dispatchObject = useCallback(
|
||||||
|
(event: string, newLevel: string) => {
|
||||||
|
const dispatcherObjects = {
|
||||||
|
move_up: {
|
||||||
|
action: setCurrentLevel,
|
||||||
|
value: newLevel,
|
||||||
|
},
|
||||||
|
move_down: {
|
||||||
|
action: setCurrentLevel,
|
||||||
|
value: newLevel,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return dispatcherObjects[event as keyof typeof dispatcherObjects];
|
||||||
|
},
|
||||||
|
[setCurrentLevel]
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (props.eventState) {
|
||||||
|
const eventAction = props.eventState.event;
|
||||||
|
const newLevel = props.eventState.newLevel;
|
||||||
|
const dispatchedObject = dispatchObject(eventAction, newLevel);
|
||||||
|
|
||||||
|
if (dispatchedObject) {
|
||||||
|
dispatchedObject.action(dispatchedObject.value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [props.eventState, dispatchObject]);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LevelManager;
|
|
@ -195,20 +195,13 @@ const MiddleRingManager = (props: any) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.eventState) {
|
if (props.eventState) {
|
||||||
const eventObject =
|
const eventAction = props.eventState.event;
|
||||||
game_action_mappings[
|
|
||||||
props.eventState as keyof typeof game_action_mappings
|
|
||||||
];
|
|
||||||
|
|
||||||
if (eventObject) {
|
const dispatchedObject =
|
||||||
const eventAction = eventObject.action;
|
dispatcherObjects[eventAction as keyof typeof dispatcherObjects];
|
||||||
|
|
||||||
const dispatchedObject =
|
if (dispatchedObject) {
|
||||||
dispatcherObjects[eventAction as keyof typeof dispatcherObjects];
|
dispatchedObject.action();
|
||||||
|
|
||||||
if (dispatchedObject) {
|
|
||||||
dispatchedObject.action();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
|
|
|
@ -1,58 +1,62 @@
|
||||||
import { useEffect, useMemo } from "react";
|
import { useCallback, useEffect, useMemo } from "react";
|
||||||
import { useSiteStore } from "../../store";
|
import { useSiteStore } from "../../store";
|
||||||
import game_action_mappings from "../../resources/game_action_mappings.json";
|
|
||||||
import { StateManagerProps } from "./EventManager";
|
import { StateManagerProps } from "./EventManager";
|
||||||
|
|
||||||
const SiteManager = (props: StateManagerProps) => {
|
const SiteManager = (props: StateManagerProps) => {
|
||||||
const incrementSiteRotY = useSiteStore((state) => state.incrementSiteRotY);
|
const addToSiteRotY = useSiteStore((state) => state.addToSiteRotY);
|
||||||
const incrementSitePosY = useSiteStore((state) => state.incrementSitePosY);
|
const addToSitePosY = useSiteStore((state) => state.addToSitePosY);
|
||||||
|
const setSiteRotIdx = useSiteStore((state) => state.setSiteRotIdx);
|
||||||
const setIsSiteYChanging = useSiteStore((state) => state.setIsSiteChanging);
|
const setIsSiteYChanging = useSiteStore((state) => state.setIsSiteChanging);
|
||||||
|
|
||||||
const dispatcherObjects = useMemo(
|
const rotateSite = useCallback(
|
||||||
() => ({
|
(value: number, newSiteRotIdx: string) => {
|
||||||
move_up: { action: incrementSitePosY, value: -1.5, actionDelay: 1300 },
|
addToSiteRotY(value);
|
||||||
move_down: { action: incrementSitePosY, value: 1.5, actionDelay: 1300 },
|
setSiteRotIdx(newSiteRotIdx);
|
||||||
move_left: {
|
},
|
||||||
action: incrementSiteRotY,
|
[addToSiteRotY, setSiteRotIdx]
|
||||||
value: Math.PI / 4,
|
);
|
||||||
actionDelay: 1100,
|
|
||||||
},
|
const dispatchObject = useCallback(
|
||||||
move_right: {
|
(event: string, newSiteRotIdx: string) => {
|
||||||
action: incrementSiteRotY,
|
const dispatcherObjects = {
|
||||||
value: -Math.PI / 4,
|
move_up: { action: addToSitePosY, value: [-1.5], actionDelay: 1300 },
|
||||||
actionDelay: 1100,
|
move_down: { action: addToSitePosY, value: [1.5], actionDelay: 1300 },
|
||||||
},
|
move_left: {
|
||||||
}),
|
action: rotateSite,
|
||||||
[incrementSitePosY, incrementSiteRotY]
|
value: [Math.PI / 4, newSiteRotIdx],
|
||||||
|
actionDelay: 1100,
|
||||||
|
},
|
||||||
|
move_right: {
|
||||||
|
action: rotateSite,
|
||||||
|
value: [-Math.PI / 4, newSiteRotIdx],
|
||||||
|
actionDelay: 1100,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return dispatcherObjects[event as keyof typeof dispatcherObjects];
|
||||||
|
},
|
||||||
|
[addToSitePosY, rotateSite]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (props.eventState) {
|
if (props.eventState) {
|
||||||
const eventObject =
|
const eventAction = props.eventState.event;
|
||||||
game_action_mappings[
|
const newSiteRotIdx = props.eventState.newSiteRotIdx;
|
||||||
props.eventState as keyof typeof game_action_mappings
|
|
||||||
];
|
|
||||||
|
|
||||||
if (eventObject) {
|
const dispatchedObject = dispatchObject(eventAction, newSiteRotIdx);
|
||||||
const eventAction = eventObject.action;
|
if (dispatchedObject) {
|
||||||
|
setIsSiteYChanging(true);
|
||||||
|
|
||||||
const dispatchedObject =
|
setTimeout(() => {
|
||||||
dispatcherObjects[eventAction as keyof typeof dispatcherObjects];
|
(dispatchedObject.action as any).apply(null, dispatchedObject.value);
|
||||||
|
}, dispatchedObject.actionDelay);
|
||||||
|
|
||||||
if (dispatchedObject) {
|
setTimeout(() => {
|
||||||
setIsSiteYChanging(true);
|
setIsSiteYChanging(false);
|
||||||
|
}, 3000);
|
||||||
setTimeout(() => {
|
|
||||||
dispatchedObject.action(dispatchedObject.value);
|
|
||||||
}, dispatchedObject.actionDelay);
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
setIsSiteYChanging(false);
|
|
||||||
}, 3000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [dispatcherObjects, props.eventState, setIsSiteYChanging]);
|
}, [dispatchObject, props.eventState, setIsSiteYChanging]);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { GameContext } from "../components/StateManagers/EventManager";
|
import { GameContext } from "../components/StateManagers/EventManager";
|
||||||
|
import available_blue_orbs_on_projection from "../resources/available_blue_orbs_on_projection.json";
|
||||||
|
|
||||||
const computeAction = (gameContext: GameContext) => {
|
const computeAction = (gameContext: GameContext) => {
|
||||||
let event;
|
let event;
|
||||||
|
@ -6,25 +7,44 @@ const computeAction = (gameContext: GameContext) => {
|
||||||
let newBlueOrbRowIdx;
|
let newBlueOrbRowIdx;
|
||||||
let newLevel;
|
let newLevel;
|
||||||
let newSiteRotIdx;
|
let newSiteRotIdx;
|
||||||
|
let newActiveBlueOrbId;
|
||||||
|
|
||||||
switch (gameContext.keyPress) {
|
switch (gameContext.keyPress) {
|
||||||
case "left":
|
case "left":
|
||||||
newBlueOrbRowIdx = gameContext.blueOrbRowIdx - 1;
|
newBlueOrbColIdx = gameContext.blueOrbColIdx - 1;
|
||||||
if (newBlueOrbRowIdx < 0) {
|
if (newBlueOrbColIdx < 0) {
|
||||||
return { event: "move_left" };
|
event = "move_left";
|
||||||
|
newSiteRotIdx = parseInt(gameContext.siteRotIdx) + 1;
|
||||||
|
if (newSiteRotIdx > 8) newSiteRotIdx = "1";
|
||||||
|
console.log(newSiteRotIdx)
|
||||||
|
newBlueOrbColIdx = 0;
|
||||||
|
newBlueOrbRowIdx = gameContext.blueOrbRowIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
} else {
|
} else {
|
||||||
return { event: "change_blue_orb_left" };
|
event = "change_blue_orb";
|
||||||
|
newBlueOrbRowIdx = gameContext.blueOrbRowIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case "down":
|
case "down":
|
||||||
newBlueOrbColIdx = gameContext.blueOrbColIdx + 1;
|
newBlueOrbRowIdx = gameContext.blueOrbRowIdx + 1;
|
||||||
if (newBlueOrbColIdx > 2) {
|
if (newBlueOrbRowIdx > 2) {
|
||||||
event = "move_down";
|
event = "move_down";
|
||||||
|
|
||||||
newLevel = (parseInt(gameContext.currentLevel) - 1)
|
newLevel = (parseInt(gameContext.currentLevel) - 1)
|
||||||
.toString()
|
.toString()
|
||||||
.padStart(2, "0");
|
.padStart(2, "0");
|
||||||
|
|
||||||
|
newBlueOrbColIdx = gameContext.blueOrbColIdx;
|
||||||
|
newBlueOrbRowIdx = 0;
|
||||||
|
|
||||||
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
} else {
|
} else {
|
||||||
event = "change_blue_orb";
|
event = "change_blue_orb";
|
||||||
|
newBlueOrbColIdx = gameContext.blueOrbColIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "up":
|
case "up":
|
||||||
|
@ -42,15 +62,40 @@ const computeAction = (gameContext: GameContext) => {
|
||||||
newSiteRotIdx = gameContext.siteRotIdx;
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
} else {
|
} else {
|
||||||
event = "change_blue_orb";
|
event = "change_blue_orb";
|
||||||
|
newBlueOrbColIdx = gameContext.blueOrbColIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "right":
|
||||||
|
newBlueOrbColIdx = gameContext.blueOrbColIdx + 1;
|
||||||
|
if (newBlueOrbColIdx > 3) {
|
||||||
|
event = "move_right";
|
||||||
|
newSiteRotIdx = (parseInt(gameContext.siteRotIdx) - 1).toString();
|
||||||
|
newBlueOrbColIdx = 0;
|
||||||
|
newBlueOrbRowIdx = gameContext.blueOrbRowIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
|
} else {
|
||||||
|
event = "change_blue_orb";
|
||||||
|
newBlueOrbRowIdx = gameContext.blueOrbRowIdx;
|
||||||
|
newLevel = gameContext.currentLevel;
|
||||||
|
newSiteRotIdx = gameContext.siteRotIdx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newActiveBlueOrbId =
|
||||||
|
newLevel +
|
||||||
|
available_blue_orbs_on_projection[
|
||||||
|
newSiteRotIdx as keyof typeof available_blue_orbs_on_projection
|
||||||
|
][newBlueOrbRowIdx as number][newBlueOrbColIdx as number];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
event: event,
|
event: event,
|
||||||
newBlueOrbColIdx: newBlueOrbColIdx,
|
newBlueOrbColIdx: newBlueOrbColIdx,
|
||||||
newBlueOrbRowIdx: newBlueOrbRowIdx,
|
newBlueOrbRowIdx: newBlueOrbRowIdx,
|
||||||
newSiteRotIdx: newSiteRotIdx,
|
newSiteRotIdx: newSiteRotIdx,
|
||||||
newLevel: newLevel,
|
newLevel: newLevel,
|
||||||
|
newActiveBlueOrbId: newActiveBlueOrbId,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
46
src/store.ts
46
src/store.ts
|
@ -69,8 +69,8 @@ type SiteState = {
|
||||||
siteRotY: number;
|
siteRotY: number;
|
||||||
sitePosY: number;
|
sitePosY: number;
|
||||||
isSiteChangingY: boolean;
|
isSiteChangingY: boolean;
|
||||||
incrementSiteRotY: (by: number) => void;
|
addToSiteRotY: (by: number) => void;
|
||||||
incrementSitePosY: (by: number) => void;
|
addToSitePosY: (by: number) => void;
|
||||||
setSiteRotY: (to: number) => void;
|
setSiteRotY: (to: number) => void;
|
||||||
setSitePosY: (to: number) => void;
|
setSitePosY: (to: number) => void;
|
||||||
setIsSiteChanging: (to: boolean) => void;
|
setIsSiteChanging: (to: boolean) => void;
|
||||||
|
@ -193,25 +193,23 @@ export const useHudStore = create<HUDState>((set) => ({
|
||||||
toggleHud: () => set((state) => ({ hudActive: Number(!state.hudActive) })),
|
toggleHud: () => set((state) => ({ hudActive: Number(!state.hudActive) })),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
export const useBlueOrbStore = create<BlueOrbState>((set) => {
|
export const useBlueOrbStore = create<BlueOrbState>((set) => ({
|
||||||
return {
|
activeBlueOrbId: "0422",
|
||||||
activeBlueOrbId: "0422",
|
isActiveBlueOrbInteractedWith: false,
|
||||||
isActiveBlueOrbInteractedWith: false,
|
activeBlueOrbPosX: 0,
|
||||||
activeBlueOrbPosX: 0,
|
activeBlueOrbPosZ: 0,
|
||||||
activeBlueOrbPosZ: 0,
|
activeBlueOrbRotZ: 0,
|
||||||
activeBlueOrbRotZ: 0,
|
setActiveBlueOrbPosX: (to) => set(() => ({ activeBlueOrbPosX: to })),
|
||||||
setActiveBlueOrbPosX: (to) => set(() => ({ activeBlueOrbPosX: to })),
|
setActiveBlueOrbPosZ: (to) => set(() => ({ activeBlueOrbPosZ: to })),
|
||||||
setActiveBlueOrbPosZ: (to) => set(() => ({ activeBlueOrbPosZ: to })),
|
setActiveBlueOrbRotZ: (to) => set(() => ({ activeBlueOrbRotZ: to })),
|
||||||
setActiveBlueOrbRotZ: (to) => set(() => ({ activeBlueOrbRotZ: to })),
|
setActiveBlueOrbId: (to) => set(() => ({ activeBlueOrbId: to })),
|
||||||
setActiveBlueOrbId: (to) => set(() => ({ activeBlueOrbId: to })),
|
setIsActiveBlueOrbInteractedWith: (to) =>
|
||||||
setIsActiveBlueOrbInteractedWith: (to) =>
|
set(() => ({ isActiveBlueOrbInteractedWith: to })),
|
||||||
set(() => ({ isActiveBlueOrbInteractedWith: to })),
|
blueOrbRowIdx: 0,
|
||||||
blueOrbRowIdx: 0,
|
setBlueOrbRowIdx: (to) => set(() => ({ blueOrbRowIdx: to })),
|
||||||
setBlueOrbRowIdx: (to) => set(() => ({ blueOrbRowIdx: to })),
|
blueOrbColIdx: 0,
|
||||||
blueOrbColIdx: 0,
|
setBlueOrbColIdx: (to) => set(() => ({ blueOrbColIdx: to })),
|
||||||
setBlueOrbColIdx: (to) => set(() => ({ blueOrbColIdx: to })),
|
}));
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
export const useLainStore = create<LainState>((set) => ({
|
export const useLainStore = create<LainState>((set) => ({
|
||||||
lainMoveState: "standing",
|
lainMoveState: "standing",
|
||||||
|
@ -253,10 +251,8 @@ export const useSiteStore = create<SiteState>((set) => ({
|
||||||
sitePosY: 0,
|
sitePosY: 0,
|
||||||
siteRotY: 0,
|
siteRotY: 0,
|
||||||
isSiteChangingY: false,
|
isSiteChangingY: false,
|
||||||
incrementSitePosY: (by) =>
|
addToSitePosY: (by) => set((state) => ({ sitePosY: state.sitePosY + by })),
|
||||||
set((state) => ({ sitePosY: state.sitePosY + by })),
|
addToSiteRotY: (by) => set((state) => ({ siteRotY: state.siteRotY + by })),
|
||||||
incrementSiteRotY: (by) =>
|
|
||||||
set((state) => ({ siteRotY: state.siteRotY + by })),
|
|
||||||
setSitePosY: (to) => set(() => ({ sitePosY: to })),
|
setSitePosY: (to) => set(() => ({ sitePosY: to })),
|
||||||
setSiteRotY: (to) => set(() => ({ siteRotY: to })),
|
setSiteRotY: (to) => set(() => ({ siteRotY: to })),
|
||||||
setIsSiteChanging: (to) => set(() => ({ isSiteChangingY: to })),
|
setIsSiteChanging: (to) => set(() => ({ isSiteChangingY: to })),
|
||||||
|
|
Loading…
Reference in a new issue