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;
|
||||
Reference in New Issue
Block a user