|
|
|
@@ -1,6 +1,8 @@
|
|
|
|
|
function Timer() {
|
|
|
|
|
this.initVariables();
|
|
|
|
|
|
|
|
|
|
this.dbConnectManager = new DBConnectManager();
|
|
|
|
|
|
|
|
|
|
// bar
|
|
|
|
|
var bar = game.add.graphics();
|
|
|
|
|
bar.beginFill(0x202020);
|
|
|
|
@@ -24,8 +26,8 @@ Timer.prototype.initVariables = function() {
|
|
|
|
|
this.isTimerGoingOn = false;
|
|
|
|
|
this.isTimeOver = false;
|
|
|
|
|
|
|
|
|
|
this.timeStart = 0
|
|
|
|
|
this.timeLeft = 0;
|
|
|
|
|
this.startTime = 0
|
|
|
|
|
this.leftTime = 0;
|
|
|
|
|
this.timerEvent = null;
|
|
|
|
|
|
|
|
|
|
this.prevTime = null;
|
|
|
|
@@ -44,16 +46,36 @@ Timer.prototype.initVariables = function() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.loadDataFromServer = function() {
|
|
|
|
|
this.timeStart = Timer.TIME_DEFAULT_SEC;
|
|
|
|
|
this.timeLeft = Timer.TIME_DEFAULT_SEC;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
this.dbConnectManager.requestLicenseTimeData(
|
|
|
|
|
sessionStorageManager.getMaestroID(),
|
|
|
|
|
sessionStorageManager.getPlayerID(),
|
|
|
|
|
Timer.TIME_DEFAULT_SEC,
|
|
|
|
|
(function(replyJson) {
|
|
|
|
|
console.log(replyJson);
|
|
|
|
|
|
|
|
|
|
// if( there is saved time record) {
|
|
|
|
|
// this.isTimerGoingOn = false;
|
|
|
|
|
// this.setTimerTextColor(0xffffff);
|
|
|
|
|
// }
|
|
|
|
|
// else
|
|
|
|
|
this.setTimerTextColor(Timer.TEXT_COLOR_CYAN);
|
|
|
|
|
if(replyJson.leftTime == null || replyJson.leftTime == 0) {
|
|
|
|
|
this.startTime = replyJson.startTime;
|
|
|
|
|
this.leftTime = replyJson.timeStart;
|
|
|
|
|
this.resetTimer();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this.setTimerTextColor(Timer.TEXT_COLOR_CYAN);
|
|
|
|
|
// this.updateTimeText();
|
|
|
|
|
this.startTime = replyJson.startTime;
|
|
|
|
|
this.leftTime = replyJson.leftTime;
|
|
|
|
|
this.pauseTimer();
|
|
|
|
|
}).bind(this),
|
|
|
|
|
|
|
|
|
|
(function(replyJson) {
|
|
|
|
|
console.log(replyJson);
|
|
|
|
|
|
|
|
|
|
this.startTime = Timer.TIME_DEFAULT_SEC;
|
|
|
|
|
this.leftTime = this.startTime;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.makeTimer = function() {
|
|
|
|
@@ -129,7 +151,10 @@ Timer.prototype.makeResetButton = function() {
|
|
|
|
|
return new RoundRectButton(
|
|
|
|
|
setting,
|
|
|
|
|
null, "C",
|
|
|
|
|
(function() { this.resetTimer(); }).bind(this)
|
|
|
|
|
(function() {
|
|
|
|
|
this.resetTimer();
|
|
|
|
|
this.resetLeftTimeToServer();
|
|
|
|
|
}).bind(this)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -205,7 +230,10 @@ Timer.prototype.makePauseButton = function() {
|
|
|
|
|
return new RoundRectButton(
|
|
|
|
|
setting,
|
|
|
|
|
null, "∥",
|
|
|
|
|
(function() { this.pauseTimer(); }).bind(this)
|
|
|
|
|
(function() {
|
|
|
|
|
this.updateLeftTimeToServer();
|
|
|
|
|
this.pauseTimer();
|
|
|
|
|
}).bind(this)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -252,16 +280,16 @@ Timer.prototype.setTimerTextColor = function(color) {
|
|
|
|
|
|
|
|
|
|
Timer.prototype.startTimer = function() {
|
|
|
|
|
this.isTimerGoingOn = true;
|
|
|
|
|
if(this.timeLeft < 0)
|
|
|
|
|
if(this.leftTime < 0)
|
|
|
|
|
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
|
|
|
|
|
else
|
|
|
|
|
this.setTimerTextColor(Timer.TEXT_COLOR_YELLOW);
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
|
|
|
|
|
ShowNotifyTimeOver(this.leftTime * Timer.TIME_MILLISECONDS);
|
|
|
|
|
|
|
|
|
|
this.prevTime = this.getNowTime();
|
|
|
|
|
this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this);
|
|
|
|
|
this.timerEvent = game.time.events.loop(1000, this.tickLeftTime, this);
|
|
|
|
|
|
|
|
|
|
this.showButton(this.playButton, false);
|
|
|
|
|
this.showButton(this.pauseButton, true);
|
|
|
|
@@ -281,12 +309,14 @@ Timer.prototype.pauseTimer = function() {
|
|
|
|
|
this.showButton(this.playButton, true);
|
|
|
|
|
this.showButton(this.pauseButton, false);
|
|
|
|
|
this.showTimerButtons();
|
|
|
|
|
|
|
|
|
|
// this.updateLeftTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.resetTimer = function() {
|
|
|
|
|
this.isTimeOver = false;
|
|
|
|
|
|
|
|
|
|
this.timeLeft = this.timeStart;
|
|
|
|
|
this.leftTime = this.startTime;
|
|
|
|
|
this.pauseTimer();
|
|
|
|
|
|
|
|
|
|
this.isTimerGoingOn = false;
|
|
|
|
@@ -295,37 +325,32 @@ Timer.prototype.resetTimer = function() {
|
|
|
|
|
// this.loadDataFromServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.tickTimeLeft = function() {
|
|
|
|
|
this.timeLeft--;
|
|
|
|
|
Timer.prototype.tickLeftTime = function() {
|
|
|
|
|
this.leftTime--;
|
|
|
|
|
|
|
|
|
|
var outFocusedTime = this.getOutFocusedTime();
|
|
|
|
|
if(outFocusedTime > 2) {
|
|
|
|
|
this.timeLeft -= outFocusedTime - 1;
|
|
|
|
|
this.leftTime -= outFocusedTime - 1;
|
|
|
|
|
|
|
|
|
|
if(this.timeLeft > 0) {
|
|
|
|
|
if(this.leftTime > 0) {
|
|
|
|
|
CancelNotifyTimeOver();
|
|
|
|
|
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
|
|
|
|
|
ShowNotifyTimeOver(this.leftTime * Timer.TIME_MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
if(!this.isTimeOver && this.timeLeft < 0)
|
|
|
|
|
if(!this.isTimeOver && this.leftTime < 0)
|
|
|
|
|
this.timeOver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.timeOver = function() {
|
|
|
|
|
this.isTimeOver = true;
|
|
|
|
|
|
|
|
|
|
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
|
|
|
|
|
|
|
|
|
|
console.log("time over");
|
|
|
|
|
|
|
|
|
|
// xhr = new XMLHttpRequest();
|
|
|
|
|
// xhr.open('POST', 'delete_last_timestamp.php', true);
|
|
|
|
|
// xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
|
// var param = 'UserID=' + playerUserID;
|
|
|
|
|
// xhr.send(param);
|
|
|
|
|
this.isTimeOver = true;
|
|
|
|
|
this.setTimerTextColor(Timer.TEXT_COLOR_RED);
|
|
|
|
|
|
|
|
|
|
this.resetLeftTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.getNowTime = function() {
|
|
|
|
@@ -443,15 +468,18 @@ Timer.prototype.timePlus = function(timePlusSecond, type) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log(timeAmount);
|
|
|
|
|
this.timeLeft += timeAmount;
|
|
|
|
|
this.leftTime += timeAmount;
|
|
|
|
|
var maxTime = 99 * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE * Timer.TIME_SECONDS_FOR_MINUTE;
|
|
|
|
|
if(this.timeLeft > maxTime)
|
|
|
|
|
this.timeLeft = maxTime;
|
|
|
|
|
if(this.leftTime > maxTime)
|
|
|
|
|
this.leftTime = maxTime;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
if(!this.isTimerGoingOn)
|
|
|
|
|
this.sendStartTimeToServer(this.timeLeft);
|
|
|
|
|
this.sendTimeLeftToServer();
|
|
|
|
|
if(!this.isTimerGoingOn) {
|
|
|
|
|
this.startTime = this.leftTime;
|
|
|
|
|
this.updateStartTimeToServer();
|
|
|
|
|
} else {
|
|
|
|
|
this.updateLeftTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.timeMinus = function(timeMinusSecond, type) {
|
|
|
|
@@ -467,37 +495,45 @@ Timer.prototype.timeMinus = function(timeMinusSecond, type) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// console.log(timeAmount);
|
|
|
|
|
this.timeLeft -= timeAmount;
|
|
|
|
|
if(this.timeLeft < 0)
|
|
|
|
|
this.timeLeft = 0;
|
|
|
|
|
this.leftTime -= timeAmount;
|
|
|
|
|
if(this.leftTime < 0)
|
|
|
|
|
this.leftTime = 0;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
if(!this.isTimerGoingOn)
|
|
|
|
|
this.sendStartTimeToServer(this.timeLeft);
|
|
|
|
|
this.sendTimeLeftToServer();
|
|
|
|
|
if(!this.isTimerGoingOn) {
|
|
|
|
|
this.startTime = this.leftTime;
|
|
|
|
|
this.updateStartTimeToServer();
|
|
|
|
|
} else {
|
|
|
|
|
this.updateLeftTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer.prototype.setTime =function(sec) {
|
|
|
|
|
// console.log("time up : " + min);
|
|
|
|
|
|
|
|
|
|
this.timeLeft += sec;
|
|
|
|
|
Timer.prototype.setTime =function(timeSecond) {
|
|
|
|
|
this.leftTime = timeSecond;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
|
|
|
|
|
if(!this.isTimerGoingOn) {
|
|
|
|
|
this.startTime = this.leftTime;
|
|
|
|
|
this.updateStartTimeToServer();
|
|
|
|
|
} else {
|
|
|
|
|
this.updateLeftTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer.prototype.updateTimeText = function() {
|
|
|
|
|
var secondsForHour = Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE;
|
|
|
|
|
|
|
|
|
|
var timeLeftHour = parseInt(this.timeLeft / secondsForHour);
|
|
|
|
|
var timeLeftMinute = parseInt((this.timeLeft % secondsForHour) / Timer.TIME_SECONDS_FOR_MINUTE);
|
|
|
|
|
var timeLeftSecond = this.timeLeft % Timer.TIME_SECONDS_FOR_MINUTE;
|
|
|
|
|
var leftTimeHour = parseInt(this.leftTime / secondsForHour);
|
|
|
|
|
var leftTimeMinute = parseInt((this.leftTime % secondsForHour) / Timer.TIME_SECONDS_FOR_MINUTE);
|
|
|
|
|
var leftTimeSecond = this.leftTime % Timer.TIME_SECONDS_FOR_MINUTE;
|
|
|
|
|
|
|
|
|
|
this.timeHourText.text = this.getTimeWithTimeFormat(timeLeftHour, Timer.TYPE_HOUR);
|
|
|
|
|
// console.log(this.timeLeft);
|
|
|
|
|
this.timeHourText.text = this.getTimeWithTimeFormat(leftTimeHour, Timer.TYPE_HOUR);
|
|
|
|
|
// console.log(this.leftTime);
|
|
|
|
|
// console.log(this.timeHourText.text);
|
|
|
|
|
this.timeMinuteText.text = this.getTimeWithTimeFormat(timeLeftMinute, Timer.TYPE_MINUTE);
|
|
|
|
|
this.timeSecondText.text = this.getTimeWithTimeFormat(timeLeftSecond, Timer.TYPE_SECOND);
|
|
|
|
|
this.timeMinuteText.text = this.getTimeWithTimeFormat(leftTimeMinute, Timer.TYPE_MINUTE);
|
|
|
|
|
this.timeSecondText.text = this.getTimeWithTimeFormat(leftTimeSecond, Timer.TYPE_SECOND);
|
|
|
|
|
// this.updateTimeVariables();
|
|
|
|
|
// this.timerText.text = this.getTimeWithTimeFormat();
|
|
|
|
|
}
|
|
|
|
@@ -518,7 +554,7 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) {
|
|
|
|
|
return this.getTwoDigitNumber(timeValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.timeLeft < 0) {
|
|
|
|
|
if(this.leftTime < 0) {
|
|
|
|
|
return "-" + this.getTwoDigitNumber(timeValue);
|
|
|
|
|
} else {
|
|
|
|
|
return this.getTwoDigitNumber(timeValue);
|
|
|
|
@@ -526,25 +562,55 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timer.prototype.setStartTime = function(time) {
|
|
|
|
|
this.startTime = time;
|
|
|
|
|
|
|
|
|
|
Timer.prototype.sendStartTimeToServer = function(time) {
|
|
|
|
|
this.timeStart = time;
|
|
|
|
|
if(!this.isTimerGoingOn) {
|
|
|
|
|
this.leftTime = this.startTime;
|
|
|
|
|
this.updateTimeText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// send to server
|
|
|
|
|
console.log("send to server : " + this.timeStart);
|
|
|
|
|
this.updateStartTimeToServer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.sendTimeLeftToServer = function() {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// console.log(this.timeLeft);
|
|
|
|
|
// console.log(playerUserID);
|
|
|
|
|
|
|
|
|
|
xhr = new XMLHttpRequest();
|
|
|
|
|
xhr.open('POST', 'make_last_timestamp.php', true);
|
|
|
|
|
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
|
|
|
|
var param = 'UserID=' + playerUserID + '&Time=' + this.timeLeft;
|
|
|
|
|
xhr.send(param);
|
|
|
|
|
|
|
|
|
|
Timer.prototype.updateStartTimeToServer = function() {
|
|
|
|
|
// send to server
|
|
|
|
|
console.log("send start time to server : " + this.startTime);
|
|
|
|
|
|
|
|
|
|
this.dbConnectManager.updateLicenseStartTime(
|
|
|
|
|
sessionStorageManager.getMaestroID(),
|
|
|
|
|
sessionStorageManager.getPlayerID(),
|
|
|
|
|
this.startTime,
|
|
|
|
|
(function(replyJson) { console.log(replyJson); }).bind(this),
|
|
|
|
|
(function(replyJson) { console.log(replyJson); })
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Timer.prototype.resetLeftTimeToServer = function() {
|
|
|
|
|
console.log("send left time to server : " + this.leftTime);
|
|
|
|
|
|
|
|
|
|
this.dbConnectManager.updateLicenseLeftTime(
|
|
|
|
|
sessionStorageManager.getMaestroID(),
|
|
|
|
|
sessionStorageManager.getPlayerID(),
|
|
|
|
|
0,
|
|
|
|
|
(function(replyJson) { console.log(replyJson); }).bind(this),
|
|
|
|
|
(function(replyJson) { console.log(replyJson); })
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
Timer.prototype.updateLeftTimeToServer = function() {
|
|
|
|
|
console.log("send left time to server : " + this.leftTime);
|
|
|
|
|
|
|
|
|
|
this.dbConnectManager.updateLicenseLeftTime(
|
|
|
|
|
sessionStorageManager.getMaestroID(),
|
|
|
|
|
sessionStorageManager.getPlayerID(),
|
|
|
|
|
this.leftTime,
|
|
|
|
|
(function(replyJson) { console.log(replyJson); }).bind(this),
|
|
|
|
|
(function(replyJson) { console.log(replyJson); })
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|