lainTSX/src/core/mediaSceneEventHandler.ts

58 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-11-25 15:14:23 +00:00
const handleMediaSceneEvent = (gameContext: any) => {
2020-11-01 15:40:46 +00:00
const keyPress = gameContext.keyPress;
const activeMediaComponent = gameContext.activeMediaComponent;
2020-11-25 15:14:23 +00:00
let newWordPosStateIdx = gameContext.wordPosStateIdx;
let newRightSideComponentIdx = gameContext.rightSideComponentIdx;
const rightSideComponents = ["fstWord", "sndWord", "thirdWord"];
if (rightSideComponents.includes(activeMediaComponent)) {
switch (keyPress) {
case "DOWN":
2020-11-25 15:14:23 +00:00
newWordPosStateIdx++;
if (newWordPosStateIdx > 6) {
newWordPosStateIdx = 1;
}
newRightSideComponentIdx++;
if (newRightSideComponentIdx > 2) {
newRightSideComponentIdx = 0;
}
2020-12-07 16:23:57 +00:00
return {
event: `${activeMediaComponent}_down`,
newWordPosStateIdx: newWordPosStateIdx,
newRightSideComponentIdx: newRightSideComponentIdx,
};
case "UP":
2020-11-25 15:14:23 +00:00
newWordPosStateIdx--;
if (newWordPosStateIdx < 1) {
newWordPosStateIdx = 6;
}
newRightSideComponentIdx--;
if (newRightSideComponentIdx < 0) {
newRightSideComponentIdx = 2;
}
2020-12-07 16:23:57 +00:00
return {
event: `${activeMediaComponent}_up`,
newWordPosStateIdx: newWordPosStateIdx,
newRightSideComponentIdx: newRightSideComponentIdx,
};
case "RIGHT":
case "LEFT":
return { event: `${activeMediaComponent}_${keyPress.toLowerCase()}` };
case "CIRCLE":
return { event: `${activeMediaComponent}_select` };
}
} else {
switch (keyPress) {
case "UP":
case "DOWN":
case "RIGHT":
case "LEFT":
return { event: `${activeMediaComponent}_${keyPress.toLowerCase()}` };
case "CIRCLE":
return { event: `${activeMediaComponent}_select` };
2020-11-25 15:14:23 +00:00
}
}
2020-11-01 15:40:46 +00:00
};
export default handleMediaSceneEvent;