aboutsummaryrefslogtreecommitdiff
path: root/src/Update
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update')
-rw-r--r--src/Update/Update.elm131
-rw-r--r--src/Update/UpdateEdition.elm33
-rw-r--r--src/Update/UpdateTimer.elm57
3 files changed, 0 insertions, 221 deletions
diff --git a/src/Update/Update.elm b/src/Update/Update.elm
deleted file mode 100644
index b4cf741..0000000
--- a/src/Update/Update.elm
+++ /dev/null
@@ -1,131 +0,0 @@
-module Update.Update
- ( Action(..)
- , actions
- , logUpdate
- , update
- ) where
-
-import Signal
-import Dict
-import Dict exposing (Dict)
-import Time exposing (Time)
-import Maybe
-import Keyboard exposing (KeyCode)
-import Char
-import List
-import Debug
-
-import Model.Model exposing (..)
-import Model.Timer exposing (..)
-import Model.Edition.Edition exposing (..)
-import Model.Edition.NameEdition exposing (..)
-import Model.Edition.TimeEdition exposing (..)
-import Model.Id exposing (..)
-import Model.IdGenerator exposing (..)
-
-import Update.UpdateTimer exposing (..)
-import Update.UpdateEdition exposing (..)
-
-import Utils.Maybe exposing (..)
-
-type Action =
- NoOp
- | Initialize
- | AddNewTimer
- | DeltaTime Time
- | UpdateTimer Id TimerAction
- | RemoveTimer Id
- | Edit Id Kind
- | ClickAway
- | KeyPressed KeyCode
-
-actions : Signal.Mailbox Action
-actions = Signal.mailbox NoOp
-
-logUpdate : Action -> Model -> Model
-logUpdate action model =
- case action of
- DeltaTime _ -> update action model
- _ -> update (Debug.log "action" action) model
-
-update : Action -> Model -> Model
-update action model =
- case action of
- NoOp -> model
- Initialize ->
- initialModel model.currentTime
- AddNewTimer ->
- let (id, newTimerIdGenerator) = getId model.timerIdGenerator
- in { model
- | timers <- Dict.insert id (initialTimer model.currentTime) model.timers
- , timerIdGenerator <- newTimerIdGenerator
- }
- DeltaTime delta ->
- { model
- | currentTime <- model.currentTime + delta
- , timers <- Dict.map (\id timer -> updateTimer (SubstractTime delta) timer) model.timers
- }
- UpdateTimer id timerAction ->
- let maybeEdition = filterMaybe (\edition -> edition.id == id) model.edition
- newModel =
- case maybeEdition of
- Just edition ->
- if edition.kind == Time then validEdition model else model
- Nothing ->
- model
- in { newModel | timers <- Dict.update id (Maybe.map (updateTimer timerAction)) newModel.timers }
- RemoveTimer id ->
- if numberOfTimers model > 1
- then
- { model | timers <- Dict.remove id model.timers }
- else
- model
- Edit id kind ->
- { model
- | edition <- Just (newEdition id kind)
- , timers <-
- if kind == Time
- then Dict.update id (Maybe.map (updateTimer Pause)) model.timers
- else model.timers
- }
- ClickAway ->
- { model | edition <- Nothing }
- KeyPressed keyCode ->
- if isEnterKeyCode keyCode
- then
- validEdition model
- else
- let editionAction =
- if isRemoveKeyCode keyCode
- then DeleteLast
- else AddChar keyCode
- in { model | edition <- Maybe.map (updateEdition editionAction) model.edition }
-
-validEdition : Model -> Model
-validEdition model =
- case model.edition of
- Just edition ->
- if isEmpty edition
- then
- { model
- | edition <- Nothing
- }
- else
- let timerAction =
- case edition.kind of
- Name ->
- Rename (renderNameEdition edition.chars)
- Time ->
- SetTime (toTime edition.chars)
- in { model
- | timers <- Dict.update edition.id (Maybe.map (updateTimer timerAction)) model.timers
- , edition <- Nothing
- }
- Nothing ->
- model
-
-isEnterKeyCode : KeyCode -> Bool
-isEnterKeyCode = (==) 13
-
-isRemoveKeyCode : KeyCode -> Bool
-isRemoveKeyCode = (==) 8
diff --git a/src/Update/UpdateEdition.elm b/src/Update/UpdateEdition.elm
deleted file mode 100644
index 47b0e22..0000000
--- a/src/Update/UpdateEdition.elm
+++ /dev/null
@@ -1,33 +0,0 @@
-module Update.UpdateEdition
- ( updateEdition
- , EditionAction(..)
- ) where
-
-import Char
-import Char exposing (KeyCode)
-
-import Model.Edition.Edition exposing (..)
-
-import Utils.List exposing (..)
-
-type EditionAction =
- DeleteLast
- | AddChar KeyCode
-
-updateEdition : EditionAction -> Edition -> Edition
-updateEdition action edition =
- case action of
- DeleteLast ->
- case maybeTail edition.chars of
- Just tailChars ->
- { edition | chars <- tailChars }
- Nothing ->
- edition
- AddChar keyCode ->
- case keyCodeToChar edition.kind keyCode of
- Just char ->
- if keyCode == 32 && maybeHead edition.chars == Just (Char.fromCode 32)
- then edition
- else { edition | chars <- char :: edition.chars }
- Nothing ->
- edition
diff --git a/src/Update/UpdateTimer.elm b/src/Update/UpdateTimer.elm
deleted file mode 100644
index 08b9969..0000000
--- a/src/Update/UpdateTimer.elm
+++ /dev/null
@@ -1,57 +0,0 @@
-module Update.UpdateTimer
- ( TimerAction(..)
- , updateTimer
- ) where
-
-import Time exposing (Time)
-
-import Model.Timer exposing (..)
-import Model.TimerState exposing (..)
-import Model.Id exposing (..)
-
-type TimerAction =
- Rename String
- | Pause
- | ToggleRunning
- | Stop
- | SetTime Time
- | SubstractTime Time
-
-updateTimer : TimerAction -> Timer -> Timer
-updateTimer action timer =
- case action of
- Rename name ->
- { timer | name <- Just name }
- Pause ->
- { timer | state <- Idle }
- ToggleRunning ->
- { timer
- | state <-
- if timer.currentTime > 0 && timer.state == Idle
- then Running
- else Idle
- }
- Stop ->
- { timer
- | currentTime <- timer.initialTime
- , state <- Idle
- }
- SetTime time ->
- { timer
- | initialTime <- time
- , currentTime <- time
- }
- 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