| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'client/elm/battlemap')
| -rw-r--r-- | client/elm/battlemap/src/Battlemap.elm | 21 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Html.elm | 69 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Location.elm | 4 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Navigator.elm | 30 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Battlemap/Tile.elm | 44 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Character.elm | 16 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Model.elm | 49 | ||||
| -rw-r--r-- | client/elm/battlemap/src/Update.elm | 65 | ||||
| -rw-r--r-- | client/elm/battlemap/src/View.elm | 6 | 
9 files changed, 230 insertions, 74 deletions
| diff --git a/client/elm/battlemap/src/Battlemap.elm b/client/elm/battlemap/src/Battlemap.elm index 09b4099..d6c0017 100644 --- a/client/elm/battlemap/src/Battlemap.elm +++ b/client/elm/battlemap/src/Battlemap.elm @@ -1,10 +1,17 @@ -module Battlemap exposing (Battlemap, random, apply_to_tile, has_location) +module Battlemap exposing +   ( +      Battlemap, +      random, +      apply_to_tile, +      has_location, +      apply_to_all_tiles +   ) -import Array exposing (Array, set, get) +import Array exposing (Array, set, get, map)  import Battlemap.Tile exposing (Tile, generate) -import Battlemap.Direction exposing (..) -import Battlemap.Location exposing (..) +import Battlemap.Direction exposing (Direction(..)) +import Battlemap.Location exposing (Location)  type alias Battlemap =     { @@ -34,6 +41,12 @@ has_location bmap loc =        && (loc.y < bmap.height)     ) +apply_to_all_tiles : Battlemap -> (Tile -> Tile) -> Battlemap +apply_to_all_tiles bmap fun = +   {bmap | +      content = (map fun bmap.content) +   } +  apply_to_tile : Battlemap -> Location -> (Tile -> Tile) -> (Maybe Battlemap)  apply_to_tile bmap loc fun =     let diff --git a/client/elm/battlemap/src/Battlemap/Html.elm b/client/elm/battlemap/src/Battlemap/Html.elm index 9f519d1..dc90ed4 100644 --- a/client/elm/battlemap/src/Battlemap/Html.elm +++ b/client/elm/battlemap/src/Battlemap/Html.elm @@ -1,32 +1,57 @@  module Battlemap.Html exposing (view)  import Html exposing (Html, text, table, tr, td) +import Html.Events exposing (onClick) +  -- import List as Lt exposing (map)  import Array as Ay exposing (foldr) -import Update exposing (Msg) +import Update exposing (Msg(..))  import Model exposing (Model)  import Battlemap exposing (Battlemap, random)  import Battlemap.Tile exposing (Tile) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..))  view_battlemap_cell : Tile -> (Html Msg)  view_battlemap_cell t = -   (td -      [] -      [ -         (text -            (case t.nav_level of -               Right -> "R" -               Left -> "L" -               Up -> "U" -               Down -> "D" -               None -> (toString t.floor_level) -            ) +   case t.char_level of +      Nothing -> +         (td +            [] +            [ +               (text "[_]"), +               (text +                  ( +                     (case t.nav_level of +                        Right -> "R" +                        Left -> "L" +                        Up -> "U" +                        Down -> "D" +                        None -> (toString t.floor_level) +                     ) +                  ) +               ) +            ] +         ) +      (Just char_id) -> +         (td +            [ (onClick (SelectCharacter char_id)) ] +            [ +               (text ("[" ++ char_id ++ "]")), +               (text +                  ( +                     (case t.nav_level of +                        Right -> "R" +                        Left -> "L" +                        Up -> "U" +                        Down -> "D" +                        None -> (toString t.floor_level) +                     ) +                  ) +               ) +            ]           ) -      ] -   )  type alias GridBuilder =     { @@ -37,21 +62,21 @@ type alias GridBuilder =     }  foldr_to_html : Tile -> GridBuilder -> GridBuilder -foldr_to_html t bg = -   if (bg.row_size == bg.bmap.width) +foldr_to_html t gb = +   if (gb.row_size == gb.bmap.width)     then -      {bg | +      {gb |           row = [(view_battlemap_cell t)],           row_size = 1,           columns =              ( -               (tr [] bg.row) :: bg.columns +               (tr [] gb.row) :: gb.columns              )        }     else -      {bg | -         row = ((view_battlemap_cell t) :: bg.row), -         row_size = (bg.row_size + 1) +      {gb | +         row = ((view_battlemap_cell t) :: gb.row), +         row_size = (gb.row_size + 1)        }  grid_builder_to_html : GridBuilder -> (List (Html Msg)) diff --git a/client/elm/battlemap/src/Battlemap/Location.elm b/client/elm/battlemap/src/Battlemap/Location.elm index 2fa6d5d..5c7bc48 100644 --- a/client/elm/battlemap/src/Battlemap/Location.elm +++ b/client/elm/battlemap/src/Battlemap/Location.elm @@ -1,6 +1,6 @@  module Battlemap.Location exposing (..) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..))  type alias Location =     { @@ -8,7 +8,7 @@ type alias Location =        y : Int     } -type alias LocationComparable = (Int, Int) +type alias LocationRef = (Int, Int)  neighbor : Location -> Direction -> Location  neighbor loc dir = diff --git a/client/elm/battlemap/src/Battlemap/Navigator.elm b/client/elm/battlemap/src/Battlemap/Navigator.elm index b040676..df0e2cf 100644 --- a/client/elm/battlemap/src/Battlemap/Navigator.elm +++ b/client/elm/battlemap/src/Battlemap/Navigator.elm @@ -1,16 +1,29 @@ -module Battlemap.Navigator exposing (Navigator, new_navigator, go) +module Battlemap.Navigator exposing +   ( +      Navigator, +      new_navigator, +      reset_navigation, +      go +   )  import Set exposing (Set, member, empty, insert)  import Battlemap exposing (Battlemap, has_location, apply_to_tile) -import Battlemap.Location exposing (..) -import Battlemap.Direction exposing (..) -import Battlemap.Tile exposing (set_direction) +import Battlemap.Direction exposing (Direction(..)) +import Battlemap.Tile exposing (Tile, set_direction) + +import Battlemap.Location exposing +   ( +      Location, +      LocationRef, +      neighbor, +      to_comparable +   )  type alias Navigator =     {        current_location : Location, -      visited_locations : (Set LocationComparable) +      visited_locations : (Set LocationRef)     }  new_navigator : Location -> Navigator @@ -20,6 +33,13 @@ new_navigator start =        visited_locations = empty     } + +reset_navigation : Tile -> Tile +reset_navigation t = +   {t | +      nav_level = None +   } +  go : Battlemap -> Navigator -> Direction -> (Battlemap, Navigator)  go battlemap nav dir =     let diff --git a/client/elm/battlemap/src/Battlemap/Tile.elm b/client/elm/battlemap/src/Battlemap/Tile.elm index acedfa4..70268bf 100644 --- a/client/elm/battlemap/src/Battlemap/Tile.elm +++ b/client/elm/battlemap/src/Battlemap/Tile.elm @@ -1,28 +1,42 @@  module Battlemap.Tile exposing (Tile, generate, set_direction) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..)) +import Character exposing (CharacterRef)  import List exposing (map)  import Array exposing (Array, fromList) +import Set exposing (Set)  type alias Tile =     {        floor_level : Int, -      nav_level : Direction ---      char_level : Int, ---      mod_level : Int +      nav_level : Direction, +      char_level : (Maybe CharacterRef) +--    mod_level : (Set TileModifier)     }  set_direction : Direction -> Tile -> Tile  set_direction d t = -   {t | nav_level = d} +   {t | +      nav_level = d +   }  from_int : Int -> Tile  from_int i = -   { -      floor_level = i, -      nav_level = None -   } +   if (i >= 10) +   then +      { +         floor_level = (i - 10), +         nav_level = None, +         char_level = (Just (toString (i - 10))) +      } +   else +      { +         floor_level = i, +         nav_level = None, +         char_level = Nothing +      } +  generate : Int -> Int -> (Array Tile)  generate width height = @@ -30,12 +44,12 @@ generate width height =        (map           (from_int)           [ -            1, 1, 1, 2, 2, 2, -            1, 0, 0, 0, 0, 2, -            1, 0, 1, 2, 0, 2, -            3, 0, 3, 4, 0, 4, -            3, 0, 0, 0, 0, 4, -            3, 3, 3, 4, 4, 4 +            10,   1,    1,    2,    2,    2, +            1,    0,    0,    0,    11,   2, +            1,    0,    1,    2,    0,    2, +            3,    0,    3,    4,    0,    4, +            3,    12,   0,    0,    0,    4, +            3,    3,    3,    4,    4,    4           ]        )     ) diff --git a/client/elm/battlemap/src/Character.elm b/client/elm/battlemap/src/Character.elm new file mode 100644 index 0000000..3082550 --- /dev/null +++ b/client/elm/battlemap/src/Character.elm @@ -0,0 +1,16 @@ +module Character exposing (Character, CharacterRef, to_comparable) + +type alias Character = +   { +      id : String, +      name : String, +      icon : String, +      portrait : String, +      x : Int, +      y : Int +   } + +type alias CharacterRef = String +to_comparable : Character -> CharacterRef +to_comparable c = +   c.id diff --git a/client/elm/battlemap/src/Model.elm b/client/elm/battlemap/src/Model.elm index 3d69c7d..61d827b 100644 --- a/client/elm/battlemap/src/Model.elm +++ b/client/elm/battlemap/src/Model.elm @@ -1,19 +1,60 @@  module Model exposing (Model, model) -import Battlemap as Bp exposing (Battlemap, random) -import Battlemap.Location exposing (..) +import Battlemap as Bp exposing (Battlemap, random, apply_to_all_tiles)  import Battlemap.Navigator as Nr exposing (Navigator, new_navigator) +import Character exposing (Character, CharacterRef) + +import Dict exposing (Dict, empty, insert) +  -- MODEL  type alias Model =     {        battlemap: Bp.Battlemap, -      navigator: (Maybe Nr.Navigator) +      navigator: (Maybe Nr.Navigator), +      selection: (Maybe String), +      characters: (Dict CharacterRef Character)     }  model : Model  model =     {        battlemap = (Bp.random), -      navigator = (Just (Nr.new_navigator {x=2, y=4})) +      navigator = Nothing, +      selection = Nothing, +      characters = +         (insert +            "2" +            { +               id = "2", +               name = "Char2", +               icon = "Icon2", +               portrait = "Portrait2", +               x = 1, +               y = 4 +            } +            (insert +               "1" +               { +                  id = "1", +                  name = "Char1", +                  icon = "Icon1", +                  portrait = "Portrait1", +                  x = 4, +                  y = 1 +               } +               (insert +                  "0" +                  { +                     id = "0", +                     name = "Char0", +                     icon = "Icon0", +                     portrait = "Portrait0", +                     x = 0, +                     y = 0 +                  } +                  empty +               ) +            ) +         )     } diff --git a/client/elm/battlemap/src/Update.elm b/client/elm/battlemap/src/Update.elm index 86b9c6e..719d259 100644 --- a/client/elm/battlemap/src/Update.elm +++ b/client/elm/battlemap/src/Update.elm @@ -2,30 +2,57 @@ module Update exposing (..)  import Model exposing (Model, model) -import Battlemap.Direction exposing (..) +import Battlemap exposing (apply_to_all_tiles) +import Battlemap.Direction exposing (Direction) -import Battlemap.Navigator as Nr exposing (go) +import Battlemap.Navigator as Nr exposing (go, reset_navigation) -type Msg = DirectionRequest Direction | None +import Dict as Dt exposing (get) + +import Character exposing (CharacterRef) + +type Msg = +   DirectionRequest Direction +   | SelectCharacter CharacterRef  update : Msg -> Model -> Model  update msg model =     case msg of        (DirectionRequest d) -> -         (case model.navigator of -            Nothing -> model -            (Just nav) -> -               let -                  (new_bmap, new_nav) = -                     (Nr.go -                        model.battlemap -                        nav -                        d -                     ) -               in -                  {model | -                     battlemap = new_bmap, -                     navigator = (Just new_nav) -                  } +         (case model.selection of +            Nothing -> +               model +            (Just char_id) -> +               (case model.navigator of +                  Nothing -> model +                  (Just nav) -> +                     let +                        (new_bmap, new_nav) = +                           (Nr.go +                              model.battlemap +                              nav +                              d +                           ) +                     in +                        {model | +                           battlemap = new_bmap, +                           navigator = (Just new_nav) +                        } +               )           ) -      _ -> model +      (SelectCharacter char_id) -> +         {model | +            selection = (Just char_id), +            battlemap = +               (apply_to_all_tiles +                  model.battlemap +                  (reset_navigation) +               ), +            navigator = +               (case (Dt.get char_id model.characters) of +                  Nothing -> Nothing +                  (Just char) -> +                     (Just (Nr.new_navigator {x = char.x, y = char.y})) +               ) +         } +      --_ -> model diff --git a/client/elm/battlemap/src/View.elm b/client/elm/battlemap/src/View.elm index 7058681..a76a0a1 100644 --- a/client/elm/battlemap/src/View.elm +++ b/client/elm/battlemap/src/View.elm @@ -1,13 +1,13 @@  module View exposing (view) -import Html exposing (Html, button, div, text, table, tr, td) +import Html exposing (Html, button, div, text)  import Html.Events exposing (onClick) -import Update exposing (..) +import Update exposing (Msg(..))  import Model exposing (Model)  import Battlemap.Html as Batmap exposing (view) -import Battlemap.Direction exposing (..) +import Battlemap.Direction exposing (Direction(..))  -- VIEW | 


