aboutsummaryrefslogtreecommitdiff
path: root/src/View
diff options
context:
space:
mode:
authorJoris Guyonvarch2015-03-15 20:15:19 +0100
committerJoris Guyonvarch2015-03-15 20:16:14 +0100
commitd5ec91d4d01db6f4d476522d5b14e116435ebb7d (patch)
tree76154fddf12254db1488e17752c41530ef8f6095 /src/View
parentce6775641639943a2aee00fa9c2d684aa434bc21 (diff)
Displaying the last score in elm graphics instead of in helm html
Diffstat (limited to 'src/View')
-rw-r--r--src/View/Game.elm57
-rw-r--r--src/View/Page.elm15
-rw-r--r--src/View/Round.elm14
3 files changed, 51 insertions, 35 deletions
diff --git a/src/View/Game.elm b/src/View/Game.elm
index c9c58ff..ad0e9ea 100644
--- a/src/View/Game.elm
+++ b/src/View/Game.elm
@@ -9,35 +9,42 @@ import Graphics.Element (Element)
import Color (..)
import Text (..)
import Text
+import Time (Time)
import Model.Vec2 (Vec2)
import Model.Player (..)
import Model.Game (Game)
import Model.Point (..)
import Model.Config (..)
+import Model.Round (..)
+
+import View.Round (roundView)
gameView : Game -> Element
gameView game =
- let whitePointForms = List.map (pointForm game.time (configColor White)) (game.cloud.points White)
- blackPointForms = List.map (pointForm game.time (configColor Black)) (game.cloud.points Black)
+ let pointsForm color =
+ List.map (pointForm game.time (configColor color)) (game.cloud.points color)
+ |> group
forms =
- boardForms game.boardSize
- ++ playerForms game.player
- ++ whitePointForms
- ++ blackPointForms
- ++ scoreForms game.boardSize game.currentScore
+ [ boardForm game.boardSize
+ , playerForm game.player
+ , pointsForm White
+ , pointsForm Black
+ , scoreForm game.boardSize game.time game.rounds game.currentScore
+ ]
in collage (truncate game.boardSize.x) (truncate game.boardSize.y) forms
-boardForms : Vec2 -> List Form
-boardForms boardSize = [filled boardColor (rect boardSize.x boardSize.y)]
+boardForm : Vec2 -> Form
+boardForm boardSize =
+ filled boardColor (rect boardSize.x boardSize.y)
boardColor : Color
boardColor = rgb 103 123 244
-playerForms : Player -> List Form
-playerForms player =
+playerForm : Player -> Form
+playerForm player =
let playerColor = configColor player.config
- in [circleForm player.pos playerSize playerColor]
+ in circleForm player.pos playerSize playerColor
playerColor : Color
playerColor = rgb 224 224 224
@@ -65,20 +72,28 @@ circleForm pos size color =
outlineColor : Color
outlineColor = rgb 34 34 34
-scoreForms : Vec2 -> Int -> List Form
-scoreForms boardSize score =
- let text = (toString score)
- scorePos = { x = 0.0, y = boardSize.y / 2 - 35 }
- in [textForm text scorePos centered]
+scoreForm : Vec2 -> Time -> List Round -> Int -> Form
+scoreForm boardSize currentRoundTime rounds score =
+ let scorePos =
+ { x = 0.0
+ , y = boardSize.y / 2 - 35
+ }
+ in if currentRoundTime < 5000 && (not (List.isEmpty rounds))
+ then
+ List.head rounds
+ |> roundView
+ |> textForm scorePos
+ else
+ textForm scorePos (toString score)
-textForm : String -> Vec2 -> (Text -> Element) -> Form
-textForm content pos alignment =
+textForm : Vec2 -> String -> Form
+textForm pos content =
let textElement = fromString content
- |> Text.height 30
+ |> Text.height 24
|> typeface ["calibri", "arial"]
|> Text.color textColor
|> bold
- |> alignment
+ |> centered
in textElement
|> toForm
|> move (pos.x, pos.y)
diff --git a/src/View/Page.elm b/src/View/Page.elm
index c85cf91..88b641e 100644
--- a/src/View/Page.elm
+++ b/src/View/Page.elm
@@ -14,7 +14,7 @@ import Model.Game (Game)
import Model.Round (..)
import View.Game (gameView)
-import View.Time (timeView)
+import View.Round (roundView)
pageView : Game -> Html
pageView game =
@@ -41,12 +41,6 @@ pageView game =
|> text
]
)
- , ul
- [ class "rounds" ]
- ( List.map
- (\round -> li [] [ text (roundView round) ])
- game.rounds
- )
, a
[ href "https://github.com/guyonvarch/catchvoid" ]
[ img
@@ -63,10 +57,3 @@ pageView game =
[]
]
]
-
-roundView : Round -> String
-roundView round =
- let score = toString round.score
- hits = "hit" ++ (if round.score > 1 then "s" else "")
- duration = timeView round.duration
- in score ++ " " ++ hits ++ " within " ++ duration
diff --git a/src/View/Round.elm b/src/View/Round.elm
new file mode 100644
index 0000000..81f4f8c
--- /dev/null
+++ b/src/View/Round.elm
@@ -0,0 +1,14 @@
+module View.Round
+ ( roundView
+ ) where
+
+import Model.Round (..)
+
+import View.Time (timeView)
+
+roundView : Round -> String
+roundView round =
+ let score = toString round.score
+ hits = "hit" ++ (if round.score > 1 then "s" else "")
+ duration = timeView round.duration
+ in score ++ " " ++ hits ++ " within " ++ duration