diff options
author | Joris Guyonvarch | 2015-03-22 12:53:55 +0100 |
---|---|---|
committer | Joris Guyonvarch | 2015-03-22 12:53:55 +0100 |
commit | 2abb8ffa46cbe86deedb9ddcbb9b042b51285feb (patch) | |
tree | 3756c16ccdf8b61000767637db0807f3d40e12cc /src/Model | |
parent | ce4580451def7e86d0f67d2c353ac65239e17fd1 (diff) |
Editing name first draft
Diffstat (limited to 'src/Model')
-rw-r--r-- | src/Model/Edition/Edition.elm | 34 | ||||
-rw-r--r-- | src/Model/Edition/NameEdition.elm | 15 | ||||
-rw-r--r-- | src/Model/Edition/TimeEdition.elm (renamed from src/Model/TimerEdition.elm) | 29 | ||||
-rw-r--r-- | src/Model/Model.elm | 9 | ||||
-rw-r--r-- | src/Model/Timer.elm | 8 |
5 files changed, 63 insertions, 32 deletions
diff --git a/src/Model/Edition/Edition.elm b/src/Model/Edition/Edition.elm new file mode 100644 index 0000000..89a0b52 --- /dev/null +++ b/src/Model/Edition/Edition.elm @@ -0,0 +1,34 @@ +module Model.Edition.Edition + ( Edition + , Kind(..) + , newEdition + , keyCodeToChar + ) where + +import Keyboard (KeyCode) + +import Model.Id (..) +import Model.Edition.NameEdition as NameEdition +import Model.Edition.TimeEdition as TimeEdition + +type alias Edition = + { id : Id + , kind : Kind + , chars : List Char + } + +type Kind = + Name + | Time + +newEdition id kind = + { id = id + , kind = kind + , chars = [] + } + +keyCodeToChar : Kind -> KeyCode -> Maybe Char +keyCodeToChar kind = + case kind of + Name -> NameEdition.keyCodeToChar + Time -> TimeEdition.keyCodeToChar diff --git a/src/Model/Edition/NameEdition.elm b/src/Model/Edition/NameEdition.elm new file mode 100644 index 0000000..18224ea --- /dev/null +++ b/src/Model/Edition/NameEdition.elm @@ -0,0 +1,15 @@ +module Model.Edition.NameEdition + ( keyCodeToChar + , renderNameEdition + ) where + +import Char +import Keyboard (KeyCode) +import String +import List + +keyCodeToChar : KeyCode -> Maybe Char +keyCodeToChar = Just << Char.fromCode + +renderNameEdition : List Char -> String +renderNameEdition = String.fromList << List.reverse diff --git a/src/Model/TimerEdition.elm b/src/Model/Edition/TimeEdition.elm index 2ec98b7..6999b25 100644 --- a/src/Model/TimerEdition.elm +++ b/src/Model/Edition/TimeEdition.elm @@ -1,8 +1,5 @@ -module Model.TimerEdition - ( TimerEdition - , Numbers - , newTimerEdition - , keyCodeToNumberChar +module Model.Edition.TimeEdition + ( keyCodeToChar , toTime , toMinutesAndSeconds ) where @@ -13,25 +10,11 @@ import Array import String import Keyboard (KeyCode) -import Model.Id (..) - import Utils.List (..) import Utils.Maybe (..) -type alias TimerEdition = - { id : Id - , numbers : Numbers - } - -type alias Numbers = List Char - -newTimerEdition id = - { id = id - , numbers = [] - } - -keyCodeToNumberChar : KeyCode -> Maybe Char -keyCodeToNumberChar code = +keyCodeToChar : KeyCode -> Maybe Char +keyCodeToChar code = List.map (flip keyCodeToCharFromZero code) zeroKeyCodes |> List.foldl orElse Nothing @@ -46,14 +29,14 @@ keyCodeToCharFromZero zero code = |> Array.get (code - zero) else Nothing -toTime : Numbers -> Time +toTime : List Char -> Time toTime numbers = numbers |> toMinutesAndSeconds |> \(a, b) -> (stringToInt a, stringToInt b) |> \(minutes, seconds) -> (toFloat minutes) * 60 * 1000 + (toFloat seconds) * 1000 -toMinutesAndSeconds : Numbers -> (String, String) +toMinutesAndSeconds : List Char -> (String, String) toMinutesAndSeconds numbers = numbers |> List.take 4 diff --git a/src/Model/Model.elm b/src/Model/Model.elm index b929261..c45300b 100644 --- a/src/Model/Model.elm +++ b/src/Model/Model.elm @@ -10,7 +10,7 @@ import Time (Time) import List import Model.Timer (..) -import Model.TimerEdition (..) +import Model.Edition.Edition (..) import Model.Id (..) import Model.IdGenerator (..) @@ -18,17 +18,16 @@ type alias Model = { currentTime : Time , timers : Dict Id Timer , timerIdGenerator : IdGenerator - , timerEdition : Maybe TimerEdition + , edition : Maybe Edition } initialModel : Time -> Model initialModel initialTime = let (id, idGenerator) = getId initialIdGenerator - timerName = "Timer " ++ (toString id) in { currentTime = initialTime - , timers = Dict.insert id (initialTimer initialTime timerName) Dict.empty + , timers = Dict.insert id (initialTimer initialTime) Dict.empty , timerIdGenerator = idGenerator - , timerEdition = Nothing + , edition = Nothing } numberOfTimers : Model -> Int diff --git a/src/Model/Timer.elm b/src/Model/Timer.elm index f05c487..35850fc 100644 --- a/src/Model/Timer.elm +++ b/src/Model/Timer.elm @@ -11,17 +11,17 @@ import Model.TimerState (..) type alias Timer = { creationTime : Time - , name : String + , name : Maybe String , initialTime : Time , currentTime : Time , state : TimerState } -initialTimer : Time -> String -> Timer -initialTimer creationTime name = +initialTimer : Time -> Timer +initialTimer creationTime = let initialTime = 5 * 60 * 1000 in { creationTime = creationTime - , name = name + , name = Nothing , initialTime = initialTime , currentTime = initTime initialTime , state = Idle |