From 4b73f3a9765a91509b893943b1785cf3df36a31a Mon Sep 17 00:00:00 2001 From: Mark Wunsch Date: Wed, 19 Oct 2016 10:05:57 -0400 Subject: [PATCH] Hide Turn type constructor --- src/Main.elm | 49 +++++++++++++++++++++++++++---------------------- src/Turn.elm | 37 ++++++++++++++++++++----------------- 2 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/Main.elm b/src/Main.elm index 8ba26ed..7e165ce 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -17,7 +17,7 @@ import Svg exposing (..) import Svg.Attributes exposing (..) import Tabletop exposing (Tabletop, positionFromMouseCoords) import Task -import Turn exposing (Turn) +import Turn exposing (Turn, Phase(..)) import Window @@ -87,26 +87,31 @@ update msg game = Click { x, y } -> case Player.getSelectedGangMember game.player of Just fighter -> - let - attemptMove : Model -> Maybe Model - attemptMove model = - case - positionFromMouseCoords ( x, y ) game.windowScale - |> Model.attemptMove model - of - Ok m -> - Just m - - Err ( s, m ) -> - Just m - in - ( { game - | player = - game.player - |> \p -> { p | gang = Gang.update fighter.id ((flip andThen) attemptMove) p.gang } - } - , Cmd.none - ) + case Turn.phase game.turn of + Movement -> + let + attemptMove : Model -> Maybe Model + attemptMove model = + case + positionFromMouseCoords ( x, y ) game.windowScale + |> Model.attemptMove model + of + Ok m -> + Just m + + Err ( s, m ) -> + Just m + in + ( { game + | player = + game.player + |> \p -> { p | gang = Gang.update fighter.id ((flip andThen) attemptMove) p.gang } + } + , Cmd.none + ) + + _ -> + ( game, Cmd.none ) Nothing -> ( game, Cmd.none ) @@ -204,6 +209,6 @@ view game = :: measuringTape ++ Gang.view game.player.gang Select ) - , Html.strong [] [ Html.text (toString game.turn.phase) ] + , Html.strong [] [ Html.text (Turn.phase game.turn |> toString) ] , selectedFighterProfile ] diff --git a/src/Turn.elm b/src/Turn.elm index 51a045e..26ef992 100644 --- a/src/Turn.elm +++ b/src/Turn.elm @@ -1,4 +1,4 @@ -module Turn exposing (..) +module Turn exposing (Turn, Phase(..), init, round, advance, phase) type Phase @@ -8,33 +8,36 @@ type Phase | Recovery -type alias Turn = - { round : Int - , phase : Phase - } +type Turn + = Turn Int Phase init : Turn init = - { round = 1 - , phase = Movement - } + Turn 1 Movement + + +round : Turn -> Int +round (Turn num _) = + num + + +phase : Turn -> Phase +phase (Turn _ p) = + p advance : Turn -> Turn -advance turn = - case turn.phase of +advance (Turn round phase) = + case phase of Movement -> - { turn | phase = Shooting } + Turn round Shooting Shooting -> - { turn | phase = HandToHand } + Turn round HandToHand HandToHand -> - { turn | phase = Recovery } + Turn round Recovery Recovery -> - { turn - | round = turn.round + 1 - , phase = Movement - } + Turn (round + 1) Movement