2021-02-02 16:31:50 +00:00
|
|
|
import { findNodeFromWord } from "../../utils/media-utils";
|
2021-02-17 16:21:27 +00:00
|
|
|
import { MediaSceneContext } from "../../store";
|
2021-02-02 16:31:50 +00:00
|
|
|
|
2021-02-17 16:21:27 +00:00
|
|
|
const handleMediaSceneKeyPress = (mediaSceneContext: MediaSceneContext) => {
|
2021-02-01 18:13:32 +00:00
|
|
|
const {
|
|
|
|
keyPress,
|
|
|
|
activeMediaComponent,
|
|
|
|
wordPosStateIdx,
|
2021-02-02 16:31:50 +00:00
|
|
|
activeNode,
|
|
|
|
activeSite,
|
2021-02-07 15:12:19 +00:00
|
|
|
gameProgress,
|
2021-02-17 16:21:27 +00:00
|
|
|
currentMediaSide,
|
|
|
|
lastActiveMediaComponents,
|
2021-02-01 18:13:32 +00:00
|
|
|
} = mediaSceneContext;
|
2020-12-21 16:56:06 +00:00
|
|
|
|
2021-02-17 16:21:27 +00:00
|
|
|
switch (currentMediaSide) {
|
|
|
|
case "left":
|
|
|
|
switch (keyPress) {
|
|
|
|
case "UP":
|
|
|
|
case "DOWN":
|
|
|
|
return {
|
|
|
|
event: `media_leftside_${keyPress.toLowerCase()}`,
|
|
|
|
};
|
|
|
|
case "RIGHT":
|
|
|
|
return {
|
|
|
|
event: "media_leftside_right",
|
|
|
|
lastActiveComponent: activeMediaComponent,
|
|
|
|
newActiveComponent: lastActiveMediaComponents.right,
|
|
|
|
};
|
|
|
|
case "CIRCLE":
|
|
|
|
switch (activeMediaComponent) {
|
|
|
|
case "play":
|
|
|
|
return {
|
|
|
|
event: "media_play_select",
|
|
|
|
node: activeNode,
|
|
|
|
};
|
|
|
|
case "exit":
|
|
|
|
return {
|
|
|
|
event: "media_play_select",
|
|
|
|
};
|
|
|
|
}
|
2020-12-21 16:56:06 +00:00
|
|
|
}
|
2021-02-17 16:21:27 +00:00
|
|
|
break;
|
|
|
|
case "right":
|
|
|
|
switch (keyPress) {
|
|
|
|
case "UP": {
|
|
|
|
const newWordPosStateIdx =
|
|
|
|
wordPosStateIdx - 1 < 1 ? 6 : wordPosStateIdx - 1;
|
|
|
|
const newComponent = (() => {
|
|
|
|
switch (activeMediaComponent) {
|
|
|
|
case "fstWord":
|
|
|
|
return "thirdWord";
|
|
|
|
case "sndWord":
|
|
|
|
return "fstWord";
|
|
|
|
case "thirdWord":
|
|
|
|
return "sndWord";
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
return {
|
|
|
|
event: "media_rightside_up",
|
|
|
|
newActiveComponent: newComponent,
|
|
|
|
wordPosStateIdx: newWordPosStateIdx,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
case "DOWN": {
|
|
|
|
const newWordPosStateIdx =
|
|
|
|
wordPosStateIdx + 1 > 6 ? 1 : wordPosStateIdx + 1;
|
|
|
|
const newComponent = (() => {
|
|
|
|
switch (activeMediaComponent) {
|
|
|
|
case "fstWord":
|
|
|
|
return "sndWord";
|
|
|
|
case "sndWord":
|
|
|
|
return "thirdWord";
|
|
|
|
case "thirdWord":
|
|
|
|
return "fstWord";
|
|
|
|
}
|
|
|
|
})();
|
2020-12-21 16:56:06 +00:00
|
|
|
|
2021-02-17 16:21:27 +00:00
|
|
|
return {
|
|
|
|
event: "media_rightside_down",
|
|
|
|
newActiveComponent: newComponent,
|
|
|
|
wordPosStateIdx: newWordPosStateIdx,
|
|
|
|
};
|
|
|
|
}
|
2020-12-21 16:56:06 +00:00
|
|
|
|
2021-02-17 16:21:27 +00:00
|
|
|
case "LEFT":
|
|
|
|
return {
|
|
|
|
event: "media_rightside_left",
|
|
|
|
lastActiveComponent: activeMediaComponent,
|
|
|
|
newActiveComponent: lastActiveMediaComponents.left,
|
|
|
|
};
|
|
|
|
|
|
|
|
case "CIRCLE":
|
2021-02-02 16:31:50 +00:00
|
|
|
const data = findNodeFromWord(
|
|
|
|
activeMediaComponent,
|
|
|
|
activeNode,
|
2021-02-07 15:12:19 +00:00
|
|
|
activeSite,
|
|
|
|
gameProgress
|
2021-02-02 16:31:50 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (data) {
|
2021-02-17 16:21:27 +00:00
|
|
|
return { event: `media_word_select`, ...data };
|
2021-02-02 16:31:50 +00:00
|
|
|
} else {
|
2021-02-07 15:12:19 +00:00
|
|
|
return { event: `word_node_not_found` };
|
2021-02-02 16:31:50 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-25 15:14:23 +00:00
|
|
|
}
|
2020-11-01 15:40:46 +00:00
|
|
|
};
|
|
|
|
|
2021-02-08 17:53:28 +00:00
|
|
|
export default handleMediaSceneKeyPress;
|