| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2017-10-30 16:53:46 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2017-10-30 16:53:46 +0100 | 
| commit | 0a048ea546b6f0ec142e5c159c037d3949853dec (patch) | |
| tree | 26ddb57d4d3ef9dc2595d4ded5fe31d2a05feed9 /src | |
| parent | 5f318a009042d92acaddc426811db9d608f1dcac (diff) | |
Thinking about how to format the JSON messages.
Diffstat (limited to 'src')
| -rw-r--r-- | src/battlemap/src/Battlemap.elm | 7 | ||||
| -rw-r--r-- | src/battlemap/src/Battlemap/Navigator.elm | 3 | ||||
| -rw-r--r-- | src/battlemap/src/Send/CharacterActions.elm | 93 | ||||
| -rw-r--r-- | src/battlemap/src/UI.elm | 2 | 
4 files changed, 81 insertions, 24 deletions
| diff --git a/src/battlemap/src/Battlemap.elm b/src/battlemap/src/Battlemap.elm index 96be086..f0e2b04 100644 --- a/src/battlemap/src/Battlemap.elm +++ b/src/battlemap/src/Battlemap.elm @@ -6,6 +6,7 @@ module Battlemap exposing        get_tiles,        set_navigator,        clear_navigator_path, +      get_navigator_path,        try_getting_tile_at,        try_getting_navigator_location,        try_getting_navigator_path_to, @@ -108,6 +109,12 @@ clear_navigator_path bmap =        Nothing -> bmap +get_navigator_path : Type -> (List Battlemap.Direction.Type) +get_navigator_path bmap = +   case bmap.navigator of +      (Just navigator) -> (Battlemap.Navigator.get_path navigator) +      Nothing -> [] +  try_getting_navigator_location : Type -> (Maybe Battlemap.Location.Type)  try_getting_navigator_location bmap =     case bmap.navigator of diff --git a/src/battlemap/src/Battlemap/Navigator.elm b/src/battlemap/src/Battlemap/Navigator.elm index aa664a1..852eb2c 100644 --- a/src/battlemap/src/Battlemap/Navigator.elm +++ b/src/battlemap/src/Battlemap/Navigator.elm @@ -94,6 +94,9 @@ get_range_markers : (     )  get_range_markers navigator = (Dict.toList navigator.range_indicators) +get_path : Type -> (List Battlemap.Direction.Type) +get_path navigator = (Battlemap.Navigator.Path.get_summary navigator.path) +  get_summary : Type -> Summary  get_summary navigator =     { diff --git a/src/battlemap/src/Send/CharacterActions.elm b/src/battlemap/src/Send/CharacterActions.elm index 7d2f380..e7aee41 100644 --- a/src/battlemap/src/Send/CharacterActions.elm +++ b/src/battlemap/src/Send/CharacterActions.elm @@ -10,25 +10,66 @@ import Json.Decode  import Constants.IO  import Event + +-------------------------------------------------------------------------------- +-- TYPES ------------------------------------------------------------------------ +-------------------------------------------------------------------------------- +type alias Reply = +  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -encode : Model -> Json.Encode.Value -encode model = -   (Json.Encode.encode -      0 -      (Json.Encode.object -         [ -            ("user_token", Json.Encode.string model.user_token), -            ("char_id", Json.Encode.string ...), -            ("path", Jsong.Encode.string ...), -            ("target_id", Jsong.Encode.string ...) -         ] -      ) -   ) +try_encoding : Model -> (Maybe String) +try_encoding model = +   case (Model.get_state model) of +      (Model.ControllingCharacter char_ref) -> +         (Just +            (Json.Encode.encode +               0 +               (Json.Encode.object +                  [ +                     ("user_token", Json.Encode.string model.user_token), +                     ("char_id", Json.Encode.string char_ref), +                     ( +                        "path", +                        (Json.Encode.list +                           (List.map +                              ( +                                 (Json.Encode.string) +                                 << +                                 (Battlemap.Direction.to_string) +                              ) +                              (Battlemap.get_navigator_path model.battlemap) +                           ) +                        ) +                     ), +                     ( +                        "target_id", +                        (Json.Encode.string +                           (case (UI.get_previous_action model.ui) of +                              (Just (UI.AttackedCharacter id)) -> id +                              _ -> "" +                           ) +                        ) +                     ) +                  ] +               ) +            ) +         ) + +      _ -> +         Nothing  decode : (Json.Decode.Decoder a)  decode = +-- Reply: +-- { +--    TYPES: (list Instr-Type), +--    DATA: (list Instr-Data) +-- } +-- +-- Instr-Type : display-message, move-char, etc... +-- Instr-Data : {category: int, content: string}, {char_id: string, x: int, y: int}  receive : (Http.Result (Http.Error a)) -> Event  receive reply = @@ -36,13 +77,19 @@ receive reply =  --------------------------------------------------------------------------------  -- EXPORTED --------------------------------------------------------------------  -------------------------------------------------------------------------------- -send : Model -> (Http.Request String) -send model = -   (Http.send -      (receive) -      (Http.post -         Constants.IO.battlemap_handler_url -         (Http.jsonBody (encode model)) -         (decode) -      ) -   ) +try_sending : Model -> (Maybe (Http.Request String)) +try_sending model = +   case (try_encoding model) of +      (Just serial) -> +         (Just +            (Http.send +               (receive) +               (Http.post +                  Constants.IO.battlemap_handler_url +                  (Http.jsonBody serial) +                  (decode) +               ) +            ) +         ) + +      Nothing -> Nothing diff --git a/src/battlemap/src/UI.elm b/src/battlemap/src/UI.elm index 8ffc8d2..9f432e8 100644 --- a/src/battlemap/src/UI.elm +++ b/src/battlemap/src/UI.elm @@ -26,7 +26,6 @@ import Battlemap.Location  import Character -  --------------------------------------------------------------------------------  -- TYPES -----------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -39,6 +38,7 @@ type Action =     UsedManualControls     | SelectedLocation Battlemap.Location.Ref     | SelectedCharacter Character.Ref +   | AttackedCharacter Character.Ref  type alias Type =     { | 


