From 5bd5f0809e720856a7527e57c2bf2be144b41b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Mon, 10 Dec 2018 23:05:51 +0900 Subject: [PATCH] Fix: startTime, resetTime --- src/game/license_timer/timer.js | 166 ++++++++++++++++++++++---------- 1 file changed, 115 insertions(+), 51 deletions(-) diff --git a/src/game/license_timer/timer.js b/src/game/license_timer/timer.js index f16b364..9d67a00 100644 --- a/src/game/license_timer/timer.js +++ b/src/game/license_timer/timer.js @@ -6,9 +6,6 @@ function Timer() { bar.beginFill(0x202020); bar.drawRect(0, 60, GAME_SCREEN_SIZE.x, 240); - // Timer - this.timerCenterX = game.world.centerX + Timer.Timer_CENTER_OFFSET_X; - this.timerCenterY = 183; this.makeTimer(); this.makeTimerButtons(); @@ -16,20 +13,46 @@ function Timer() { this.resetButton = this.makeResetButton(); this.pauseButton = this.makePauseButton(); this.showButton(this.pauseButton, false); - // this.showButton(this.pauseButton, true); this.playButton = this.makePlayButton(); - - this.startTimer(); + this.loadDataFromServer(); } Timer.prototype.initVariables = function() { + this.isTimerGoingOn = false; + + this.timeStart = 0 + this.timeLeft = 0; + this.timerEvent = null; + this.prevTime = null; + this.timerCenterX = game.world.centerX + Timer.Timer_CENTER_OFFSET_X; + this.timerCenterY = 183; + + this.hour10ButtonPosX = this.timerCenterX - 285 - 90; + this.hour1ButtonPosX = this.timerCenterX - 195 - 90; + + this.minute10ButtonPosX = this.timerCenterX - 45 - 90; + this.minute1ButtonPosX = this.timerCenterX + 45 - 90; + + this.timePlusButtonPosY = this.timerCenterY - 82; + this.timeMinusButtonPosY = this.timerCenterY + 75; +} + +Timer.prototype.loadDataFromServer = function() { + this.timeStart = Timer.TIME_DEFAULT_SEC; this.timeLeft = Timer.TIME_DEFAULT_SEC; - this.timerEvent = null; + this.updateTimeText(); + + // if( there is saved time record) { + // this.isTimerGoingOn = false; + // this.setTimerTextColor(0xffffff); + // } + + this.setTimerTextColor(0xc04040); } Timer.prototype.makeTimer = function() { @@ -41,43 +64,34 @@ Timer.prototype.makeTimer = function() { } Timer.prototype.makeTimerButtons = function() { - var hour10PosX = this.timerCenterX - 285 - 90; - var hour1PosX = this.timerCenterX - 195 - 90; - - var minute10PosX = this.timerCenterX - 45 - 90; - var minute1PosX = this.timerCenterX + 45 - 90; - - var plusPosY = this.timerCenterY - 82; - var minusPosY = this.timerCenterY + 75; - // hour button - this.hourPlus10Button = this.makeTimePlusButton(hour10PosX, plusPosY, "▲", + this.hourPlus10Button = this.makeTimePlusButton(this.hour10ButtonPosX, this.timePlusButtonPosY, "▲", (function() { this.timePlus(10, Timer.TYPE_HOUR); }).bind(this) ); // this.hourPlus10Button.setInputEnabled(false); - this.hourMinus10Button = this.makeTimeMinusButton(hour10PosX, minusPosY, "▼", + this.hourMinus10Button = this.makeTimeMinusButton(this.hour10ButtonPosX, this.timeMinusButtonPosY, "▼", (function() { this.timeMinus(10, Timer.TYPE_HOUR); }).bind(this) ); - this.hourPlus1Button = this.makeTimePlusButton(hour1PosX, plusPosY, "▲", + this.hourPlus1Button = this.makeTimePlusButton(this.hour1ButtonPosX, this.timePlusButtonPosY, "▲", (function() { this.timePlus(1, Timer.TYPE_HOUR); }).bind(this) ); - this.hourMinus1Button = this.makeTimeMinusButton(hour1PosX, minusPosY, "▼", + this.hourMinus1Button = this.makeTimeMinusButton(this.hour1ButtonPosX, this.timeMinusButtonPosY, "▼", (function() { this.timeMinus(1, Timer.TYPE_HOUR); }).bind(this) ); // minute button - this.minutePlus10Button = this.makeTimePlusButton(minute10PosX, plusPosY, "▲", + this.minutePlus10Button = this.makeTimePlusButton(this.minute10ButtonPosX, this.timePlusButtonPosY, "▲", (function() { this.timePlus(10, Timer.TYPE_MINUTE); }).bind(this) ); - this.minuteMinus10Button = this.makeTimeMinusButton(minute10PosX, minusPosY, "▼", + this.minuteMinus10Button = this.makeTimeMinusButton(this.minute10ButtonPosX, this.timeMinusButtonPosY, "▼", (function() { this.timeMinus(10, Timer.TYPE_MINUTE); }).bind(this) ); - this.minutePlus1Button = this.makeTimePlusButton(minute1PosX, plusPosY, "▲", + this.minutePlus1Button = this.makeTimePlusButton(this.minute1ButtonPosX, this.timePlusButtonPosY, "▲", (function() { this.timePlus(1, Timer.TYPE_MINUTE); }).bind(this) ); - this.minuteMinus1Button = this.makeTimeMinusButton(minute1PosX, minusPosY, "▼", + this.minuteMinus1Button = this.makeTimeMinusButton(this.minute1ButtonPosX, this.timeMinusButtonPosY, "▼", (function() { this.timeMinus(1, Timer.TYPE_MINUTE); }).bind(this) ); } @@ -114,7 +128,7 @@ Timer.prototype.makeResetButton = function() { return new RoundRectButton( setting, null, "C", - (function() { console.log("리셋"); }).bind(this) + (function() { this.resetTimer(); }).bind(this) ); } @@ -151,13 +165,13 @@ Timer.prototype.makePlayButton = function() { return new RoundRectButton( setting, null, "▶", - (function() { console.log("플레이"); }).bind(this) + (function() { this.startTimer(); }).bind(this) ); } Timer.prototype.makePauseButton = function() { var setting = new RoundRectButtonSetting(0, 0, 0, 0); - setting.x = game.world.width - 200; + setting.x = game.world.width - 100; setting.y = this.timerCenterY; setting.width = 120; setting.height = 120; @@ -189,7 +203,7 @@ Timer.prototype.makePauseButton = function() { return new RoundRectButton( setting, null, "∥", - (function() { console.log("일시 정지"); }).bind(this) + (function() { this.pauseTimer(); }).bind(this) ); } @@ -202,22 +216,74 @@ Timer.prototype.showButton = function(button, flag) { button.move(backupPosX, -200); } +Timer.prototype.hideTimerButtons = function() { + this.hourPlus10Button.move(-200, -200); + this.hourPlus1Button.move(-200, -200); + this.hourMinus10Button.move(-200, -200); + this.hourMinus1Button.move(-200, -200); + + this.minutePlus10Button.move(-200, -200); + this.minutePlus1Button.move(-200, -200); + this.minuteMinus10Button.move(-200, -200); + this.minuteMinus1Button.move(-200, -200); +} + +Timer.prototype.showTimerButtons = function() { + this.hourPlus10Button.move(this.hour10ButtonPosX, this.timePlusButtonPosY); + this.hourMinus10Button.move(this.hour10ButtonPosX, this.timeMinusButtonPosY); + this.hourPlus1Button.move(this.hour1ButtonPosX, this.timePlusButtonPosY); + this.hourMinus1Button.move(this.hour1ButtonPosX, this.timeMinusButtonPosY); + + this.minutePlus10Button.move(this.minute10ButtonPosX, this.timePlusButtonPosY); + this.minuteMinus10Button.move(this.minute10ButtonPosX, this.timeMinusButtonPosY); + this.minutePlus1Button.move(this.minute1ButtonPosX, this.timePlusButtonPosY); + this.minuteMinus1Button.move(this.minute1ButtonPosX, this.timeMinusButtonPosY); +} + +Timer.prototype.setTimerTextColor = function(color) { + this.timeHourText.tint = color; + this.timeHourMinuteSeperator.tint = color; + this.timeMinuteText.tint = color; + this.timeMinuteSecondSeperator.tint = color; + this.timeSecondText.tint = color; +} + Timer.prototype.startTimer = function() { + this.isTimerGoingOn = true; + this.setTimerTextColor(0x40c0c0); this.updateTimeText(); ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS); this.prevTime = this.getNowTime(); - this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this); + + this.showButton(this.playButton, false); + this.showButton(this.pauseButton, true); + this.hideTimerButtons(); } Timer.prototype.pauseTimer = function() { + this.setTimerTextColor(0xa0a0a0); this.updateTimeText(); CancelNotifyTimeOver(); game.time.events.remove(this.timerEvent); + + this.showButton(this.playButton, true); + this.showButton(this.pauseButton, false); + this.showTimerButtons(); +} + +Timer.prototype.resetTimer = function() { + this.timeLeft = this.timeStart; + this.pauseTimer(); + + this.isTimerGoingOn = false; + this.setTimerTextColor(0xc04040); + + // this.loadDataFromServer(); } Timer.prototype.tickTimeLeft = function() { @@ -235,8 +301,10 @@ Timer.prototype.tickTimeLeft = function() { this.updateTimeText(); - if(this.timeLeft < 0) + if(this.timeLeft < 0) { + this.setTimerTextColor(0xff0000); this.timeOver(); + } } Timer.prototype.timeOver = function() { @@ -368,13 +436,15 @@ Timer.prototype.timePlus = function(timePlusSecond, type) { break; } - console.log(timeAmount); + // console.log(timeAmount); this.timeLeft += 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; - this.updateTimeText(); + + if(!this.isTimerGoingOn) + this.sendStartTimeToServer(this.timeLeft); this.sendTimeLeftToServer(); } @@ -392,12 +462,14 @@ Timer.prototype.timeMinus = function(timeMinusSecond, type) { break; } - console.log(timeAmount); + // console.log(timeAmount); this.timeLeft -= timeAmount; if(this.timeLeft < 0) this.timeLeft = 0; - this.updateTimeText(); + + if(!this.isTimerGoingOn) + this.sendStartTimeToServer(this.timeLeft); this.sendTimeLeftToServer(); } @@ -409,23 +481,6 @@ Timer.prototype.setTime =function(sec) { this.updateTimeText(); } -Timer.prototype.timeUp = function(sec) { - // console.log("time up : " + sec); - - this.timeLeft += sec; - this.updateTimeText(); - // this.sendTimeLeftToServer(); -} - -Timer.prototype.timeDown = function(sec) { - // console.log("time down : " + sec); - - this.timeLeft -= sec; - if(this.timeLeft < 0) - this.timeLeft = 0; - this.updateTimeText(); - // this.sendTimeLeftToServer(); -} Timer.prototype.updateTimeText = function() { var secondsForHour = Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE; @@ -466,6 +521,15 @@ Timer.prototype.getTimeWithTimeFormat = function(timeValue, type) { } } + + +Timer.prototype.sendStartTimeToServer = function(time) { + this.timeStart = time; + + // send to server + console.log(this.timeStart); +} + Timer.prototype.sendTimeLeftToServer = function() { return;