diff options
author | Joris Guyonvarch | 2015-03-21 21:11:10 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-21 21:11:10 +0100 |
commit | 466d5dfdf398ba8c8665c841e04dafea7c288b95 (patch) | |
tree | c1b000be76541d248a0b84d0a3109661867d434c /src/Update | |
parent | be2663265cc7205ff690a2fbf3346913c812085d (diff) |
Adding a progress bar to the timer time
Diffstat (limited to 'src/Update')
-rw-r--r-- | src/Update/Update.elm | 2 | ||||
-rw-r--r-- | src/Update/UpdateTimer.elm | 34 |
2 files changed, 29 insertions, 7 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm index f96a128..fabe0e8 100644 --- a/src/Update/Update.elm +++ b/src/Update/Update.elm @@ -62,7 +62,7 @@ update action model = DeltaTime delta -> { model | currentTime <- model.currentTime + delta - , timers <- substractTimersTime delta model.timers + , timers <- Dict.map (\id timer -> updateTimer (SubstractTime delta) timer) model.timers } UpdateTimer id action -> let maybeTimerEdition = filterMaybe (\timerEdition -> timerEdition.id == id) model.timerEdition diff --git a/src/Update/UpdateTimer.elm b/src/Update/UpdateTimer.elm index e45a3c2..2e0d9af 100644 --- a/src/Update/UpdateTimer.elm +++ b/src/Update/UpdateTimer.elm @@ -14,6 +14,7 @@ type TimerAction = | ToggleRunning | Stop | SetTime Time + | SubstractTime Time updateTimer : TimerAction -> Timer -> Timer updateTimer action timer = @@ -21,12 +22,19 @@ updateTimer action timer = Pause -> { timer | state <- Idle } ToggleRunning -> - { timer - | state <- - if timer.currentTime > 0 && timer.state == Idle - then Running - else Idle - } + if timer.state == Ringing + then + { timer + | currentTime <- initTime timer.initialTime + , state <- Running + } + else + { timer + | state <- + if timer.currentTime > 0 && timer.state == Idle + then Running + else Idle + } Stop -> { timer | currentTime <- initTime timer.initialTime @@ -38,3 +46,17 @@ updateTimer action timer = | initialTime <- time , currentTime <- augmentedTime } + SubstractTime time -> + if timer.state == Running + then + let newTime = timer.currentTime - time + in if newTime <= 0.0 + then + { timer + | currentTime <- 0.0 + , state <- Ringing + } + else + { timer | currentTime <- newTime } + else + timer |