Add: TimeUtil, RealtimeStageTimer (incompleted)
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
function RealtimeStageTimer(timeLimitMS) {
|
||||
this.timeLimit = timeLimitMS;
|
||||
|
||||
this.startTime = 0;
|
||||
this.elapsedTime = 0;
|
||||
this.isPaused = true;
|
||||
|
||||
this.onTimeUpdate = null;
|
||||
|
||||
this.timerEvent = null;
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.setTimeUpdateEvent = function(eventMethod) {
|
||||
this.onTimeUpdate = eventMethod;
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.start = function() {
|
||||
this.isPaused = false;
|
||||
this.startTime = game.time.totalElapsedSeconds();
|
||||
|
||||
this.elapsedTimer = game.time.create(false);
|
||||
this.timerEvent = this.elapsedTimer.loop(10, this.updateTimer, this);
|
||||
this.elapsedTimer.start();
|
||||
|
||||
this.sendElapsedTime();
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.pause = function() {
|
||||
this.isPaused = true;
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.resume = function() {
|
||||
this.isPaused = false;
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.stop = function() {
|
||||
var recordTime = game.time.totalElapsedSeconds() - this.startTime;
|
||||
this.removeTimer();
|
||||
|
||||
return recordTime;
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.updateTimer = function() {
|
||||
if(this.isPaused == true)
|
||||
return;
|
||||
|
||||
this.elapsedTime = game.time.totalElapsedSeconds() - this.startTime;
|
||||
this.sendElapsedTime();
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.sendElapsedTime = function() {
|
||||
if(this.onTimeUpdate === null)
|
||||
return;
|
||||
|
||||
var timeLeft = this.timeLimit - this.elapsedTime;
|
||||
this.onTimeUpdate(timeLeft);
|
||||
}
|
||||
|
||||
RealtimeStageTimer.prototype.removeTimer = function() {
|
||||
game.time.events.remove(this.timerEvent);
|
||||
if(this.timerEvent)
|
||||
this.timerEvent = null;
|
||||
|
||||
this.elapsedTimer.stop();
|
||||
this.elapsedTimer = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RealtimeStageTimer.FONT_HEIGHT_PX = 70;
|
||||
|
||||
RealtimeStageTimer.DEFAULT_TEXT_FONT = {
|
||||
font: "38px Arial",
|
||||
align: "center",
|
||||
boundsAlignH: "center", // left, center. right
|
||||
boundsAlignV: "middle", // top, middle, bottom
|
||||
fill: "#fff"
|
||||
};
|
||||
@@ -16,7 +16,7 @@ RecordUtil.getRecordValueText = function(record, appID) {
|
||||
}
|
||||
|
||||
RecordUtil.getRecordUnit = function(appID) {
|
||||
if(appID == 104 || appID == 105) // dodge
|
||||
if(appID == 104 || appID == 105) // 104 : dodge, 105 : one to fifty
|
||||
return " 초";
|
||||
else if(appID == 52 || appID == 53) // word flyingsaucer
|
||||
return " 점";
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
function TimeUtil() {
|
||||
}
|
||||
|
||||
|
||||
TimeUtil.getFullHourFromMS = function(timeMS) {
|
||||
return Math.floor(timeMS / TimeUtil.HOUR_MS);
|
||||
}
|
||||
|
||||
TimeUtil.getHourFromMS = function(timeMS) {
|
||||
return TimeUtil.getFullHourFromMS(timeMS) % 24;
|
||||
}
|
||||
|
||||
TimeUtil.getTwoDigitHourFromMS = function(timeMS) {
|
||||
var twoDigitHour = TimeUtil.getHourFromMS(timeMS);
|
||||
return StringUtil.getNumberStartWithZero(twoDigitHour, 2);
|
||||
}
|
||||
|
||||
|
||||
TimeUtil.getFullMinuteFromMS = function(timeMS) {
|
||||
return Math.floor(timeMS / TimeUtil.MINUTE_MS);
|
||||
}
|
||||
|
||||
TimeUtil.getMinuteFromMS = function(timeMS) {
|
||||
return TimeUtil.getFullMinuteFromMS(timeMS) % 60;
|
||||
}
|
||||
|
||||
TimeUtil.getTwoDigitMinuteFromMS = function(timeMS) {
|
||||
var twoDigitMinute = TimeUtil.getMinuteFromMS(timeMS);
|
||||
return StringUtil.getNumberStartWithZero(twoDigitMinute, 2);
|
||||
}
|
||||
|
||||
|
||||
TimeUtil.getFullSecondFromMS = function(timeMS) {
|
||||
return Math.floor(timeMS / TimeUtil.SECOND_MS);
|
||||
}
|
||||
|
||||
TimeUtil.getSecondFromMS = function(timeMS) {
|
||||
return TimeUtil.getFullSecondFromMS(timeMS) % 60;
|
||||
}
|
||||
|
||||
TimeUtil.getTwoDigitSecondFromMS = function(timeMS) {
|
||||
var twoDigitSecond = TimeUtil.getSecondFromMS(timeMS);
|
||||
return StringUtil.getNumberStartWithZero(twoDigitSecond, 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
TimeUtil.getYYYYMMDD = function(date) {
|
||||
// return date.toISOString().slice(0,10);
|
||||
return TimeUtil.getFullYear(date) + "-"
|
||||
+ TimeUtil.getFullMonth(date) + "-"
|
||||
+ TimeUtil.getFullDate(date);
|
||||
}
|
||||
|
||||
TimeUtil.getHHMMSS = function(date) {
|
||||
return TimeUtil.getFullHours(date) + ":"
|
||||
+ TimeUtil.getFullMinutes(date) + ":"
|
||||
+ TimeUtil.getFullSeconds(date);
|
||||
}
|
||||
|
||||
TimeUtil.printMonthDay = function(date) {
|
||||
// var dateTime = new Date(date);
|
||||
var a = date.split(" ");
|
||||
var d = a[0].split("-");
|
||||
var t = "0:0:0".split(":");
|
||||
if(a.count > 0)
|
||||
var t = a[1].split(":");
|
||||
var dateTime = new Date(d[0],(d[1]-1),d[2],t[0],t[1],t[2]);
|
||||
return TimeUtil.getFullMonth(dateTime) + "월 " + TimeUtil.getFullDate(dateTime) + "일";
|
||||
}
|
||||
|
||||
|
||||
TimeUtil.SECOND_MS = 1000;
|
||||
TimeUtil.MINUTE_MS = TimeUtil.SECOND_MS * 60;
|
||||
TimeUtil.HOUR_MS = TimeUtil.MINUTE_MS * 60;
|
||||
TimeUtil.DAY_MS = TimeUtil.HOUR_MS * 24;
|
||||
@@ -46,6 +46,18 @@ TypingExamination.prototype.create = function() {
|
||||
|
||||
this.averageTypingSpeedText = new AverageTypingSpeed();
|
||||
|
||||
this.textTimer = this.makeDefaultText(960, 30);
|
||||
this.textTimer.anchor.set(1, 0.5);
|
||||
this.textTimer.fontSize = 30;
|
||||
|
||||
this.stageTimer = new RealtimeStageTimer(Phaser.Timer.SECOND * 300);
|
||||
this.stageTimer.setTimeUpdateEvent(
|
||||
(function(timeLeftMS) {
|
||||
this.textTimer.text = "남은 시간 : " + Math.floor(timeLeftMS);
|
||||
}).bind(this)
|
||||
);
|
||||
this.stageTimer.start();
|
||||
/*
|
||||
this.stageTimer = new StageTimer(
|
||||
TypingExamination.GAME_TIME_SEC,
|
||||
(function() {
|
||||
@@ -53,6 +65,7 @@ TypingExamination.prototype.create = function() {
|
||||
this.timeOver();
|
||||
}).bind(this)
|
||||
);
|
||||
*/
|
||||
|
||||
|
||||
// bottom ui
|
||||
@@ -209,9 +222,9 @@ TypingExamination.prototype.makeTextContents = function() {
|
||||
this.inputTextContent.canvasInput.placeHolder("");
|
||||
// inputTextContent.canvasInput._onkeydown = this.checkInputText;
|
||||
this.inputTextContent.canvasInput._onkeyup = (function() {
|
||||
this.checkTypingContents(event);
|
||||
this.onKeyUp(event);
|
||||
// warning
|
||||
// : checkTypingContents is called onkeyup and onkeydown
|
||||
// : onKeyUp is called onkeyup and onkeydown
|
||||
}).bind(this);
|
||||
|
||||
this.loadExaminationContent();
|
||||
@@ -265,7 +278,7 @@ TypingExamination.prototype.startGame = function() {
|
||||
this.showTypingExaminationContents();
|
||||
this.showPlayingWordNumber();
|
||||
|
||||
this.stageTimer.start();
|
||||
// this.stageTimer.start();
|
||||
}
|
||||
|
||||
TypingExamination.prototype.timeOver = function() {
|
||||
@@ -277,7 +290,7 @@ TypingExamination.prototype.gameOver = function() {
|
||||
var missionClearText = new MissionClearText();
|
||||
this.stopAndGoResult();
|
||||
|
||||
this.stageTimer.pause();
|
||||
// this.stageTimer.pause();
|
||||
}
|
||||
|
||||
TypingExamination.prototype.stopAndGoResult = function() {
|
||||
@@ -393,6 +406,7 @@ TypingExamination.prototype.completeLoadingWriting = function() {
|
||||
this.typingExaminationContents = typingTextMan.getContents();
|
||||
// console.log(this.typingExaminationContents.length);
|
||||
// console.log(this.typingExaminationContents[this.typingExaminationContents.length - 1]);
|
||||
|
||||
var lastSentence = this.typingExaminationContents[this.typingExaminationContents.length - 1];
|
||||
if(lastSentence[lastSentence.length - 1] !== TypingExamination.ENTER_INDICATOR)
|
||||
this.typingExaminationContents[this.typingExaminationContents.length - 1] += TypingExamination.ENTER_INDICATOR;
|
||||
@@ -427,7 +441,6 @@ TypingExamination.prototype.showTypingExaminationContents = function() {
|
||||
} else {
|
||||
// console.log(this.typingExaminationContents[doneIndex] + "/");
|
||||
this.textTypingContentsDone[i].text = this.typingExaminationContents[doneIndex];
|
||||
// this.textDoneLineNumber[i].text = NumberUtil.getRecordText(Math.floor(this.typingRecordForLines[doneIndex]));
|
||||
|
||||
var lineNumber = this.typingContentLength - doneIndex;
|
||||
this.textDoneLineNumber[i].text = NumberUtil.numberWithCommas(lineNumber) + " ";
|
||||
@@ -463,14 +476,18 @@ TypingExamination.prototype.resetTypingContent = function() {
|
||||
this.inputTextContent.canvasInput.value('');
|
||||
}
|
||||
|
||||
TypingExamination.prototype.checkTypingContents = function(event) {
|
||||
TypingExamination.prototype.onKeyUp = function(event) {
|
||||
if(this.isGameOver)
|
||||
return;
|
||||
|
||||
if(this.isTyping == false) {
|
||||
// console.log(event);
|
||||
this.setTimeTypingStart();
|
||||
}
|
||||
|
||||
//not trimmed contents
|
||||
var notTrimmedInputContent = this.inputTextContent.canvasInput.value();
|
||||
var notTrimmedTypingContent = this.typingExaminationContents[this.typingIndex];
|
||||
this.showTypingContentHighlight(notTrimmedInputContent, notTrimmedTypingContent);
|
||||
|
||||
// trimmed contents
|
||||
// var inputContent = inputText.replace(/ /g, TypingExamination.SPACE_INDICATOR);
|
||||
@@ -479,64 +496,65 @@ TypingExamination.prototype.checkTypingContents = function(event) {
|
||||
var trimmedTypingContent = this.typingExaminationContents[this.typingIndex].trim();
|
||||
trimmedTypingContent = trimmedTypingContent.replace(TypingExamination.ENTER_INDICATOR, "");
|
||||
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER ||
|
||||
event.keyCode == Phaser.Keyboard.SPACEBAR) {
|
||||
// console.log("### enter ###");
|
||||
// console.log("this.typingIndex : " + this.typingIndex);
|
||||
// console.log("trimmedInputContent : [" + trimmedInputContent + "], length : " + trimmedInputContent.length);
|
||||
// console.log("trimmedTypingContent : [" + trimmedTypingContent + "], length : " + trimmedTypingContent.length);
|
||||
this.highlightTypingContent(notTrimmedInputContent, notTrimmedTypingContent);
|
||||
|
||||
if(trimmedInputContent === trimmedTypingContent) {
|
||||
// console.log("input completed");
|
||||
this.calculateTypingRecord(notTrimmedTypingContent);
|
||||
|
||||
// console.log("this.typingIndex : " + this.typingIndex);
|
||||
// console.log("this.trimmedTypingContentLength : " + this.trimmedTypingContentLength);
|
||||
if(this.typingIndex == this.typingContentLength - 1) {
|
||||
this.isGameOver = true;
|
||||
this.gameOver();
|
||||
return;
|
||||
}
|
||||
|
||||
this.playNextContent();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.isTyping == false) {
|
||||
// console.log(event);
|
||||
this.setTimeTypingStart();
|
||||
}
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER)
|
||||
this.onKeyEnter(trimmedInputContent, trimmedTypingContent, notTrimmedTypingContent);
|
||||
|
||||
if(event.keyCode == Phaser.Keyboard.SPACEBAR)
|
||||
this.onKeyEnter(trimmedInputContent, trimmedTypingContent, notTrimmedTypingContent);
|
||||
}
|
||||
|
||||
TypingExamination.prototype.showTypingContentHighlight = function(inputContent, typingContent) {
|
||||
// console.log(inputContent + "=");
|
||||
TypingExamination.prototype.onKeyEnter = function(trimmedInputContent, trimmedTypingContent, notTrimmedTypingContent) {
|
||||
// console.log("### enter ###");
|
||||
// console.log("this.typingIndex : " + this.typingIndex);
|
||||
// console.log("trimmedInputContent : [" + trimmedInputContent + "], length : " + trimmedInputContent.length);
|
||||
// console.log("trimmedTypingContent : [" + trimmedTypingContent + "], length : " + trimmedTypingContent.length);
|
||||
|
||||
if(trimmedInputContent === trimmedTypingContent) {
|
||||
// console.log("input completed");
|
||||
this.calculateTypingRecord(notTrimmedTypingContent);
|
||||
|
||||
// console.log("this.typingIndex : " + this.typingIndex);
|
||||
// console.log("this.trimmedTypingContentLength : " + this.trimmedTypingContentLength);
|
||||
if(this.typingIndex == this.typingContentLength - 1) {
|
||||
this.isGameOver = true;
|
||||
this.gameOver();
|
||||
return;
|
||||
}
|
||||
|
||||
this.playNextContent();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TypingExamination.prototype.highlightTypingContent = function(notTrimmedInputContent, notTrimmedTypingContent) {
|
||||
// console.log(notTrimmedInputContent + "=");
|
||||
// console.log(typingContent + "=");
|
||||
|
||||
if(typingContent == null)
|
||||
if(notTrimmedTypingContent == null)
|
||||
return;
|
||||
|
||||
// var replaceSpaceIndicatorInputContent = inputContent.replace(/ /g, TypingExamination.SPACE_INDICATOR);
|
||||
var typingContentLength = typingContent.length;
|
||||
// var replaceSpaceIndicatorInputContent = notTrimmedInputContent.replace(/ /g, TypingExamination.SPACE_INDICATOR);
|
||||
var typingContentLength = notTrimmedTypingContent.length;
|
||||
for(var i = 0; i < typingContentLength; i++) {
|
||||
var typingChar = typingContent.charAt(i);
|
||||
var inputChar = inputContent.charAt(i);
|
||||
var typingChar = notTrimmedTypingContent.charAt(i);
|
||||
var inputChar = notTrimmedInputContent.charAt(i);
|
||||
// console.log("typingChar : " + typingChar);
|
||||
// console.log("inputChar : " + inputChar);
|
||||
|
||||
// when typingChar is the last letter
|
||||
if(isNaN(inputChar)) {
|
||||
// console.log("NaN : " + i);
|
||||
this.setCorrectText(typingContent.substring(0, i + 1));
|
||||
this.setCorrectText(notTrimmedTypingContent.substring(0, i + 1));
|
||||
}
|
||||
|
||||
if(typingChar != inputChar) {
|
||||
// console.log("inputContent.charAt(" + i + ") : " + inputContent.charCodeAt(i).toString(16) + ", " + inputChar);
|
||||
// console.log("typingContent.charAt(" + i + ") : " + typingContent.charCodeAt(i).toString(16) + ", " + typingChar);
|
||||
if(typingChar !== inputChar) {
|
||||
// console.log("notTrimmedInputContent.charAt(" + i + ") : " + notTrimmedInputContent.charCodeAt(i).toString(16) + ", " + inputChar);
|
||||
// console.log("notTrimmedTypingContent.charAt(" + i + ") : " + notTrimmedTypingContent.charCodeAt(i).toString(16) + ", " + typingChar);
|
||||
|
||||
this.textNextLetterIndicator.text = typingContent.substring(0, i + 1);
|
||||
this.setCorrectText(typingContent.substring(0, i));
|
||||
this.textNextLetterIndicator.text = notTrimmedTypingContent.substring(0, i + 1);
|
||||
this.setCorrectText(notTrimmedTypingContent.substring(0, i));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user