Fix: complete TimeUtil, RealtimeStageTimer
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
function RealtimeStageTimer(timeLimitMS) {
|
function RealtimeStageTimer(timeLimitSec) {
|
||||||
this.timeLimit = timeLimitMS;
|
this.timeLimit = timeLimitSec;
|
||||||
|
|
||||||
this.startTime = 0;
|
this.startTime = 0;
|
||||||
this.elapsedTime = 0;
|
this.elapsedTime = 0;
|
||||||
|
this.isStarted = false;
|
||||||
this.isPaused = true;
|
this.isPaused = true;
|
||||||
|
|
||||||
this.onTimeUpdate = null;
|
this.onTimeUpdate = null;
|
||||||
|
this.onTimeOver = null;
|
||||||
|
|
||||||
this.timerEvent = null;
|
this.timerEvent = null;
|
||||||
}
|
}
|
||||||
@@ -14,7 +16,14 @@ RealtimeStageTimer.prototype.setTimeUpdateEvent = function(eventMethod) {
|
|||||||
this.onTimeUpdate = eventMethod;
|
this.onTimeUpdate = eventMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RealtimeStageTimer.prototype.setTimeOverEvent = function(eventMethod) {
|
||||||
|
this.onTimeOver = eventMethod;
|
||||||
|
}
|
||||||
|
|
||||||
RealtimeStageTimer.prototype.start = function() {
|
RealtimeStageTimer.prototype.start = function() {
|
||||||
|
if(this.isStarted === true)
|
||||||
|
return;
|
||||||
|
|
||||||
this.isPaused = false;
|
this.isPaused = false;
|
||||||
this.startTime = game.time.totalElapsedSeconds();
|
this.startTime = game.time.totalElapsedSeconds();
|
||||||
|
|
||||||
@@ -27,13 +36,22 @@ RealtimeStageTimer.prototype.start = function() {
|
|||||||
|
|
||||||
RealtimeStageTimer.prototype.pause = function() {
|
RealtimeStageTimer.prototype.pause = function() {
|
||||||
this.isPaused = true;
|
this.isPaused = true;
|
||||||
|
|
||||||
|
this.sendElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
RealtimeStageTimer.prototype.resume = function() {
|
RealtimeStageTimer.prototype.resume = function() {
|
||||||
this.isPaused = false;
|
this.isPaused = false;
|
||||||
|
|
||||||
|
this.sendElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
RealtimeStageTimer.prototype.stop = function() {
|
RealtimeStageTimer.prototype.stop = function() {
|
||||||
|
this.isStarted = false;
|
||||||
|
this.isPaused = true;
|
||||||
|
|
||||||
|
this.sendElapsedTime();
|
||||||
|
|
||||||
var recordTime = game.time.totalElapsedSeconds() - this.startTime;
|
var recordTime = game.time.totalElapsedSeconds() - this.startTime;
|
||||||
this.removeTimer();
|
this.removeTimer();
|
||||||
|
|
||||||
@@ -45,6 +63,17 @@ RealtimeStageTimer.prototype.updateTimer = function() {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
this.elapsedTime = game.time.totalElapsedSeconds() - this.startTime;
|
this.elapsedTime = game.time.totalElapsedSeconds() - this.startTime;
|
||||||
|
|
||||||
|
var timeLeft = this.timeLimit - this.elapsedTime;
|
||||||
|
if(timeLeft < 0) {
|
||||||
|
this.stop();
|
||||||
|
|
||||||
|
if(this.onTimeOver !== null)
|
||||||
|
this.onTimeOver();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.sendElapsedTime();
|
this.sendElapsedTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,87 @@ TimeUtil.getTwoDigitSecondFromMS = function(timeMS) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.getFullHourFromSec = function(timeSec) {
|
||||||
|
return Math.floor(timeSec / TimeUtil.HOUR_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getHourFromSec = function(timeSec) {
|
||||||
|
return TimeUtil.getFullHourFromSec(timeSec) % 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getTwoDigitHourFromSec = function(timeSec) {
|
||||||
|
var twoDigitHour = TimeUtil.getHourFromSec(timeSec);
|
||||||
|
return StringUtil.getNumberStartWithZero(twoDigitHour, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.getFullMinuteFromSec = function(timeSec) {
|
||||||
|
return Math.floor(timeSec / TimeUtil.MINUTE_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getMinuteFromSec = function(timeSec) {
|
||||||
|
return TimeUtil.getFullMinuteFromSec(timeSec) % 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getTwoDigitMinuteFromSec = function(timeSec) {
|
||||||
|
var twoDigitMinute = TimeUtil.getMinuteFromSec(timeSec);
|
||||||
|
return StringUtil.getNumberStartWithZero(twoDigitMinute, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.getFullSecondFromSec = function(timeSec) {
|
||||||
|
return Math.floor(timeSec / TimeUtil.SECOND_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getSecondFromSec = function(timeSec) {
|
||||||
|
return TimeUtil.getFullSecondFromSec(timeSec) % 60;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeUtil.getTwoDigitSecondFromSec = function(timeSec) {
|
||||||
|
var twoDigitSecond = TimeUtil.getSecondFromSec(timeSec);
|
||||||
|
return StringUtil.getNumberStartWithZero(twoDigitSecond, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.printTimeFromSec = function(timeSec) {
|
||||||
|
var fullTime = "";
|
||||||
|
|
||||||
|
var twoDigitHour = TimeUtil.getTwoDigitHourFromSec(timeSec);
|
||||||
|
if(twoDigitHour !== "00")
|
||||||
|
fullTime = twoDigitHour + "시간 ";
|
||||||
|
|
||||||
|
var twoDigitMinute = TimeUtil.getTwoDigitMinuteFromSec(timeSec);
|
||||||
|
if(twoDigitMinute !== "00")
|
||||||
|
fullTime = fullTime + twoDigitMinute + "분 ";
|
||||||
|
|
||||||
|
var twoDigitSecond = TimeUtil.getTwoDigitSecondFromSec(timeSec);
|
||||||
|
fullTime = fullTime + twoDigitSecond + "초";
|
||||||
|
|
||||||
|
return fullTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.printHHMMSSFromSec = function(timeSec) {
|
||||||
|
var fullTime = "";
|
||||||
|
|
||||||
|
var twoDigitHour = TimeUtil.getTwoDigitHourFromSec(timeSec);
|
||||||
|
if(twoDigitHour !== "00")
|
||||||
|
fullTime = twoDigitHour + ":";
|
||||||
|
|
||||||
|
var twoDigitMinute = TimeUtil.getTwoDigitMinuteFromSec(timeSec);
|
||||||
|
if(twoDigitMinute !== "00")
|
||||||
|
fullTime = fullTime + twoDigitMinute + ":";
|
||||||
|
|
||||||
|
var twoDigitSecond = TimeUtil.getTwoDigitSecondFromSec(timeSec);
|
||||||
|
fullTime = fullTime + twoDigitSecond;
|
||||||
|
|
||||||
|
return fullTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TimeUtil.getYYYYMMDD = function(date) {
|
TimeUtil.getYYYYMMDD = function(date) {
|
||||||
// return date.toISOString().slice(0,10);
|
// return date.toISOString().slice(0,10);
|
||||||
@@ -75,4 +156,10 @@ TimeUtil.printMonthDay = function(date) {
|
|||||||
TimeUtil.SECOND_MS = 1000;
|
TimeUtil.SECOND_MS = 1000;
|
||||||
TimeUtil.MINUTE_MS = TimeUtil.SECOND_MS * 60;
|
TimeUtil.MINUTE_MS = TimeUtil.SECOND_MS * 60;
|
||||||
TimeUtil.HOUR_MS = TimeUtil.MINUTE_MS * 60;
|
TimeUtil.HOUR_MS = TimeUtil.MINUTE_MS * 60;
|
||||||
TimeUtil.DAY_MS = TimeUtil.HOUR_MS * 24;
|
TimeUtil.DAY_MS = TimeUtil.HOUR_MS * 24;
|
||||||
|
|
||||||
|
|
||||||
|
TimeUtil.SECOND_SEC = 1;
|
||||||
|
TimeUtil.MINUTE_SEC = TimeUtil.SECOND_SEC * 60;
|
||||||
|
TimeUtil.HOUR_SEC = TimeUtil.MINUTE_SEC * 60;
|
||||||
|
TimeUtil.DAY_SEC = TimeUtil.HOUR_SEC * 24;
|
||||||
@@ -46,26 +46,22 @@ TypingExamination.prototype.create = function() {
|
|||||||
|
|
||||||
this.averageTypingSpeedText = new AverageTypingSpeed();
|
this.averageTypingSpeedText = new AverageTypingSpeed();
|
||||||
|
|
||||||
this.textTimer = this.makeDefaultText(960, 30);
|
this.textTimer = null;
|
||||||
this.textTimer.anchor.set(1, 0.5);
|
this.realtimeStageTimer = new RealtimeStageTimer(TypingExamination.GAME_TIME_SEC);
|
||||||
this.textTimer.fontSize = 30;
|
this.realtimeStageTimer.setTimeUpdateEvent(
|
||||||
|
(function(timeLeftSec) {
|
||||||
|
if(this.textTimer === null)
|
||||||
|
return;
|
||||||
|
|
||||||
this.stageTimer = new RealtimeStageTimer(Phaser.Timer.SECOND * 300);
|
this.textTimer.text = TimeUtil.printHHMMSSFromSec(timeLeftSec);
|
||||||
this.stageTimer.setTimeUpdateEvent(
|
|
||||||
(function(timeLeftMS) {
|
|
||||||
this.textTimer.text = "남은 시간 : " + Math.floor(timeLeftMS);
|
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
this.stageTimer.start();
|
this.realtimeStageTimer.setTimeOverEvent(
|
||||||
/*
|
|
||||||
this.stageTimer = new StageTimer(
|
|
||||||
TypingExamination.GAME_TIME_SEC,
|
|
||||||
(function() {
|
(function() {
|
||||||
// this.setClickEnable(false);
|
this.textTimer.text = "타임 오버";
|
||||||
this.timeOver();
|
console.log("Time over");
|
||||||
}).bind(this)
|
}).bind(this)
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
// bottom ui
|
// bottom ui
|
||||||
@@ -82,6 +78,7 @@ TypingExamination.prototype.fontLoaded = function() {
|
|||||||
// this.animalRecordList.hide();
|
// this.animalRecordList.hide();
|
||||||
this.animalRecordList.applyLoadedFont();
|
this.animalRecordList.applyLoadedFont();
|
||||||
|
|
||||||
|
this.makeStageTimerText();
|
||||||
this.makeTextContents();
|
this.makeTextContents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,6 +93,13 @@ TypingExamination.prototype.makeDefaultText = function(x, y) {
|
|||||||
return defaultText;
|
return defaultText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TypingExamination.prototype.makeStageTimerText = function() {
|
||||||
|
this.textTimer = this.makeDefaultText(960, 30);
|
||||||
|
this.textTimer.anchor.set(1, 0.5);
|
||||||
|
this.textTimer.fontSize = 30;
|
||||||
|
this.textTimer.text = TimeUtil.printHHMMSSFromSec(TypingExamination.GAME_TIME_SEC);
|
||||||
|
}
|
||||||
|
|
||||||
TypingExamination.prototype.makeUnderlineText = function(x, y) {
|
TypingExamination.prototype.makeUnderlineText = function(x, y) {
|
||||||
var CONTENT_TEXT_WIDTH = 800;
|
var CONTENT_TEXT_WIDTH = 800;
|
||||||
var CONTENT_UNDERLINE_OFFSET_Y = 20; // 17;
|
var CONTENT_UNDERLINE_OFFSET_Y = 20; // 17;
|
||||||
@@ -278,7 +282,7 @@ TypingExamination.prototype.startGame = function() {
|
|||||||
this.showTypingExaminationContents();
|
this.showTypingExaminationContents();
|
||||||
this.showPlayingWordNumber();
|
this.showPlayingWordNumber();
|
||||||
|
|
||||||
// this.stageTimer.start();
|
this.realtimeStageTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
TypingExamination.prototype.timeOver = function() {
|
TypingExamination.prototype.timeOver = function() {
|
||||||
@@ -290,7 +294,7 @@ TypingExamination.prototype.gameOver = function() {
|
|||||||
var missionClearText = new MissionClearText();
|
var missionClearText = new MissionClearText();
|
||||||
this.stopAndGoResult();
|
this.stopAndGoResult();
|
||||||
|
|
||||||
// this.stageTimer.pause();
|
this.realtimeStageTimer.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
TypingExamination.prototype.stopAndGoResult = function() {
|
TypingExamination.prototype.stopAndGoResult = function() {
|
||||||
@@ -636,7 +640,7 @@ TypingExamination.prototype.setTimeTypingStart = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TypingExamination.GAME_TIME_SEC = 60 * 5; // 5 minutes
|
TypingExamination.GAME_TIME_SEC = TimeUtil.MINUTE_SEC * 5; // 5 minutes
|
||||||
|
|
||||||
TypingExamination.SPACE_INDICATOR = "␣"; // "ˇ"; // "ᵔ"; // "ᵕ"; // "ˣ"; // "ᵛ"; // " · ";
|
TypingExamination.SPACE_INDICATOR = "␣"; // "ˇ"; // "ᵔ"; // "ᵕ"; // "ˣ"; // "ᵛ"; // " · ";
|
||||||
TypingExamination.ENTER_INDICATOR = "⏎"; // "↵"; // "↵";
|
TypingExamination.ENTER_INDICATOR = "⏎"; // "↵"; // "↵";
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
<script src="../../game/lib/util/string_util.js"></script>
|
<script src="../../game/lib/util/string_util.js"></script>
|
||||||
<script src="../../game/lib/util/number_util.js"></script>
|
<script src="../../game/lib/util/number_util.js"></script>
|
||||||
<script src="../../game/lib/util/record_util.js"></script>
|
<script src="../../game/lib/util/record_util.js"></script>
|
||||||
|
<script src="../../game/lib/util/time_util.js"></script>
|
||||||
|
|
||||||
<script src="../../game/lib/text/input_type_text.js"></script>
|
<script src="../../game/lib/text/input_type_text.js"></script>
|
||||||
<script src="../../game/lib/text/time_over_text.js"></script>
|
<script src="../../game/lib/text/time_over_text.js"></script>
|
||||||
|
|||||||
@@ -46,6 +46,8 @@ QUnit.test( "TimeUtil", function( assert ) {
|
|||||||
assert.equal(TimeUtil.getHourFromMS(testTimeMS), 9, "getHourFromMS");
|
assert.equal(TimeUtil.getHourFromMS(testTimeMS), 9, "getHourFromMS");
|
||||||
assert.equal(TimeUtil.getTwoDigitHourFromMS(testTimeMS), "09", "getTwoDigitHourFromMS");
|
assert.equal(TimeUtil.getTwoDigitHourFromMS(testTimeMS), "09", "getTwoDigitHourFromMS");
|
||||||
|
|
||||||
|
testTimeMS = 3000;
|
||||||
|
assert.equal(TimeUtil.getTwoDigitSecondFromMS(testTimeMS), "03", "getTwoDigitHourFromMS");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user