2020-11-26 16:53:13 +00:00
|
|
|
const handleAuthorizeUserEvent = (gameContext: any) => {
|
|
|
|
const keyPress = gameContext.keyPress;
|
|
|
|
|
|
|
|
const bgLettersPos = gameContext.bgLettersPos;
|
|
|
|
const activeLetterTexOffset = gameContext.activeLetterTexOffset;
|
|
|
|
const matrixIdx = gameContext.matrixIdx;
|
|
|
|
|
|
|
|
const currentSubscene = "authorize_user";
|
|
|
|
|
|
|
|
switch (keyPress) {
|
2020-11-30 16:44:57 +00:00
|
|
|
case "LEFT":
|
2020-11-26 16:53:13 +00:00
|
|
|
const utmostLeftIndices = [0, 13, 26, 39, 52];
|
|
|
|
if (utmostLeftIndices.includes(matrixIdx)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return {
|
2020-11-30 16:44:57 +00:00
|
|
|
event: `${currentSubscene}_left`,
|
2020-11-26 16:53:13 +00:00
|
|
|
newBgLettersPos: { x: bgLettersPos.x + 0.3, y: bgLettersPos.y },
|
|
|
|
newActiveLetterTexOffset: {
|
|
|
|
x: activeLetterTexOffset.x - 0.0775,
|
|
|
|
y: activeLetterTexOffset.y,
|
|
|
|
},
|
|
|
|
newAuthorizeUserMatrixIdx: matrixIdx - 1,
|
|
|
|
};
|
|
|
|
}
|
2020-11-30 16:44:57 +00:00
|
|
|
case "RIGHT":
|
2020-11-26 16:53:13 +00:00
|
|
|
const utmostRightIndices = [12, 25, 38, 51, 64];
|
|
|
|
if (utmostRightIndices.includes(matrixIdx)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return {
|
2020-11-30 16:44:57 +00:00
|
|
|
event: `${currentSubscene}_right`,
|
2020-11-26 16:53:13 +00:00
|
|
|
newBgLettersPos: { x: bgLettersPos.x - 0.3, y: bgLettersPos.y },
|
|
|
|
newActiveLetterTexOffset: {
|
|
|
|
x: activeLetterTexOffset.x + 0.0775,
|
|
|
|
y: activeLetterTexOffset.y,
|
|
|
|
},
|
|
|
|
newAuthorizeUserMatrixIdx: matrixIdx + 1,
|
|
|
|
};
|
|
|
|
}
|
2020-11-30 16:44:57 +00:00
|
|
|
case "DOWN":
|
2020-11-26 16:53:13 +00:00
|
|
|
const utmostLowIndices = Array.from(new Array(13), (x, i) => i + 52);
|
|
|
|
if (utmostLowIndices.includes(matrixIdx)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return {
|
2020-11-30 16:44:57 +00:00
|
|
|
event: `${currentSubscene}_down`,
|
2020-11-26 16:53:13 +00:00
|
|
|
newBgLettersPos: { x: bgLettersPos.x, y: bgLettersPos.y + 0.25 },
|
|
|
|
newActiveLetterTexOffset: {
|
|
|
|
x: activeLetterTexOffset.x,
|
|
|
|
y: activeLetterTexOffset.y - 0.2,
|
|
|
|
},
|
|
|
|
newAuthorizeUserMatrixIdx: matrixIdx + 13,
|
|
|
|
};
|
|
|
|
}
|
2020-11-30 16:44:57 +00:00
|
|
|
case "UP":
|
2020-11-26 16:53:13 +00:00
|
|
|
const utmostHighIndices = Array.from(new Array(13), (x, i) => i);
|
|
|
|
if (utmostHighIndices.includes(matrixIdx)) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
return {
|
2020-11-30 16:44:57 +00:00
|
|
|
event: `${currentSubscene}_up`,
|
2020-11-26 16:53:13 +00:00
|
|
|
newBgLettersPos: { x: bgLettersPos.x, y: bgLettersPos.y - 0.25 },
|
|
|
|
newActiveLetterTexOffset: {
|
|
|
|
x: activeLetterTexOffset.x,
|
|
|
|
y: activeLetterTexOffset.y + 0.2,
|
|
|
|
},
|
|
|
|
newAuthorizeUserMatrixIdx: matrixIdx - 13,
|
|
|
|
};
|
|
|
|
}
|
2020-11-30 16:44:57 +00:00
|
|
|
case "X": {
|
2020-11-26 16:53:13 +00:00
|
|
|
return { event: "authorize_user_back" };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default handleAuthorizeUserEvent;
|