summaryrefslogtreecommitdiff
blob: 01937e0dbd430e8900ef72fb801e263ba06c701f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module Battlemap.Html exposing (view)

import Array

import Html
import Html.Events

import Battlemap
import Battlemap.Tile
import Battlemap.Direction

import Update
import Model

view_battlemap_cell : Battlemap.Tile.Type -> (Html.Html Update.Type)
view_battlemap_cell t =
   case t.char_level of
      Nothing ->
         (Html.td
            []
            [
               (Html.text "[_]"),
               (Html.text
                  (
                     (case t.nav_level of
                        Battlemap.Direction.Right -> "R"
                        Battlemap.Direction.Left -> "L"
                        Battlemap.Direction.Up -> "U"
                        Battlemap.Direction.Down -> "D"
                        Battlemap.Direction.None -> (toString t.floor_level)
                     )
                  )
               )
            ]
         )
      (Just char_id) ->
         (Html.td
            [ (Html.Events.onClick (Update.SelectCharacter char_id)) ]
            [
               (Html.text ("[" ++ char_id ++ "]")),
               (Html.text
                  (
                     (case t.nav_level of
                        Battlemap.Direction.Right -> "R"
                        Battlemap.Direction.Left -> "L"
                        Battlemap.Direction.Up -> "U"
                        Battlemap.Direction.Down -> "D"
                        Battlemap.Direction.None -> (toString t.floor_level)
                     )
                  )
               )
            ]
         )

type alias GridBuilder =
   {
      row : (List (Html.Html Update.Type)),
      columns : (List (Html.Html Update.Type)),
      row_size : Int,
      bmap : Battlemap.Type
   }

foldr_to_html : Battlemap.Tile.Type -> GridBuilder -> GridBuilder
foldr_to_html t gb =
   if (gb.row_size == gb.bmap.width)
   then
      {gb |
         row = [(view_battlemap_cell t)],
         row_size = 1,
         columns =
            (
               (Html.tr [] gb.row) :: gb.columns
            )
      }
   else
      {gb |
         row = ((view_battlemap_cell t) :: gb.row),
         row_size = (gb.row_size + 1)
      }

grid_builder_to_html : GridBuilder -> (List (Html.Html Update.Type))
grid_builder_to_html gb =
   if (gb.row_size == 0)
   then
      gb.columns
   else
      (grid_builder_to_html
         {gb |
            row = [],
            row_size = 0,
            columns =
               (
                  (Html.tr [] gb.row) :: gb.columns
               )
         }
      )

view_battlemap : Battlemap.Type -> (Html.Html Update.Type)
view_battlemap battlemap =
   (Html.table
      []
      (grid_builder_to_html
         (Array.foldr
            (foldr_to_html)
            {
               row = [],
               columns = [],
               row_size = 0,
               bmap = battlemap
            }
            battlemap.content
         )
      )
   )


view : Model.Type -> (Html.Html Update.Type)
view m =
   (view_battlemap m.battlemap)