Files
chocomae/src/game/login/login.js
T

121 lines
3.3 KiB
JavaScript

/////////////////////////////
// Login
class Login {
preload() {
game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png');
}
create() {
self = this;
sessionStorageManager.clear();
this.game.stage.backgroundColor = '#4d4d4d';
this.textStyle = { font: "bold 32px Arial", fill: "#fff", align: "right", boundsAlignH: "right", boundsAlignV: "middle" };
let fullscreenButton = new FullscreenButton(this.game);
let textX = this.game.world.centerX - 320;
if(sessionStorageManager.maestroID === null)
this.makeMaestroNameText(textX, 200);
this.makeNameText(textX, 300);
this.makeEnterCodeText(textX, 360);
this.inputTextName.canvasInput.focus();
this.makeStartButton(game.world.centerX, game.world.centerY + 100);
this.makeInfoText(0, 540);
}
makeMaestroNameText(x, y) {
this.makeTextField(x, y, "마에스트로 계정 :");
this.inputTextMaestroName = this.makeInputTypeText(x, y, "jisangs");
}
makeNameText(x, y) {
this.makeTextField(x, y, "이름 :");
this.inputTextName = this.makeInputTypeText(x, y, "박지상");
}
makeEnterCodeText(x, y) {
this.makeTextField(x, y, "입장번호 :");
this.inputTextEnterCode = this.makeInputTypeText(x, y, "760621");
}
makeTextField(x, y, text) {
return game.add.text(x, y, text, this.textStyle)
.setTextBounds(0, 0, 200, 0)
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
.boundsAlignH = 'right';
}
makeInputTypeText(x, y, text) {
let inputText = new InputTypeText(x + 420, y);
inputText.anchor.set(0.5);
inputText.canvasInput.value('');
if(isDebugMode()) {
inputText.canvasInput.value(text);
}
inputText.canvasInput._onkeyup = function() {
if(event.keyCode == Phaser.Keyboard.ENTER) {
self.startMenu();
}
}
return inputText;
}
makeStartButton(x, y) {
let setting = new RoundRectButtonSetting(x, y, 200, 100);
setting.fontStyle.fontWeight = "bold";
let startButton = new RoundRectButton(setting, RoundRectButton.NONE_ICON, "시작", this.startMenu);
}
makeInfoText(x, y) {
var timerTextStyle = { font: "30px Arial", fill: "#faa", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
this.infoText = game.add.text(0, 0, "", timerTextStyle)
.setTextBounds(x, y, game.world.width, 200);
// .setShadow(1, 1, 'rgba(0, 0, 0, 0.5)', 2);
this.infoText.stroke = "#333";
this.infoText.strokeThickness = 3;
}
startMenu() {
let maestroName = self.inputTextMaestroName.canvasInput._value;
sessionStorageManager.playerName = self.inputTextName.canvasInput._value;
let enterCode = self.inputTextEnterCode.canvasInput._value;
let dbConnectManager = new DBConnectManager();
dbConnectManager.requestCheckUserLogin(
maestroName,
sessionStorageManager.playerName,
enterCode,
self.loginSucceeded,
self.loginFailed
);
}
loginSucceeded(jsonData) {
sessionStorageManager.maestroID = jsonData['MaestroID'];
sessionStorageManager.playerUserID = jsonData['UserID'];
sessionStorageManager.playingAppName = "menu";
location.href = '../../web/client/menu_app.html';
}
loginFailed(jsonData) {
sessionStorageManager.clear();
// show retry message
console.log('login failed, jsonData : ' + JSON.stringify(jsonData));
if(jsonData["ERROR"] !== null) {
self.infoText.text = jsonData["ERROR"];
}
}
}