summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-10 13:03:35 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-10 13:03:35 +0100 |
commit | 60236a302381aeb4e97a42fdcc3afef53cf4e831 (patch) | |
tree | c4ebd28b3820c642d6fda31d80db495cbef9b793 | |
parent | 459ff1e67bdbee6dcbd8fdeee7e975be20cad8bb (diff) |
Adds a button to ask for a new battlemap.
The new battlemap is chosen according to the currently selected
character.
-rw-r--r-- | src/battlemap/src/Constants/IO.elm | 3 | ||||
-rw-r--r-- | src/battlemap/src/Event.elm | 1 | ||||
-rw-r--r-- | src/battlemap/src/Send/LoadBattlemap.elm | 83 | ||||
-rw-r--r-- | src/battlemap/src/Update.elm | 10 | ||||
-rw-r--r-- | src/battlemap/src/View/Footer/TabMenu/Settings.elm | 6 |
5 files changed, 103 insertions, 0 deletions
diff --git a/src/battlemap/src/Constants/IO.elm b/src/battlemap/src/Constants/IO.elm index bbd1dfd..27d05a6 100644 --- a/src/battlemap/src/Constants/IO.elm +++ b/src/battlemap/src/Constants/IO.elm @@ -9,3 +9,6 @@ battlemap_handler_url = (base_url ++ "/handler/battlemap") character_turn_handler : String character_turn_handler = (battlemap_handler_url ++ "/character_turn.yaws") + +battlemap_loading_handler : String +battlemap_loading_handler = (battlemap_handler_url ++ "/load_state.yaws") diff --git a/src/battlemap/src/Event.elm b/src/battlemap/src/Event.elm index d0eced0..f9d4b33 100644 --- a/src/battlemap/src/Event.elm +++ b/src/battlemap/src/Event.elm @@ -20,3 +20,4 @@ type Type = | TabSelected UI.Tab | ServerReplied (Result Http.Error (Dict.Dict String (List String))) | DebugTeamSwitchRequest + | DebugLoadBattlemapRequest diff --git a/src/battlemap/src/Send/LoadBattlemap.elm b/src/battlemap/src/Send/LoadBattlemap.elm new file mode 100644 index 0000000..e7dc82a --- /dev/null +++ b/src/battlemap/src/Send/LoadBattlemap.elm @@ -0,0 +1,83 @@ +module Send.LoadBattlemap exposing (try_sending) + +-- Elm ------------------------------------------------------------------------- +import Http + +import Dict + +import Json.Encode +import Json.Decode + +-- Battlemap ------------------------------------------------------------------- +import Constants.IO + +import Battlemap +import Battlemap.Direction + +import UI + +import Model + +import Send + +import Event + +-------------------------------------------------------------------------------- +-- TYPES ------------------------------------------------------------------------ +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +try_encoding : Model.Type -> (Maybe Json.Encode.Value) +try_encoding model = + case (Model.get_state model) of + (Model.ControllingCharacter char_ref) -> + (Just +-- (Json.Encode.encode +-- 0 + (Json.Encode.object + [ + ("battlemap_id", Json.Encode.string char_ref) + ] + ) +-- ) + ) + + _ -> + Nothing + +decode : (Json.Decode.Decoder (Dict.Dict String (List String))) --Send.Reply) +decode = + (Json.Decode.dict + (Json.Decode.list Json.Decode.string) + ) + +-- 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} + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +try_sending : Model.Type -> (Maybe (Cmd Event.Type)) +try_sending model = + case (try_encoding model) of + (Just serial) -> + (Just + (Http.send + Event.ServerReplied + (Http.post + Constants.IO.battlemap_loading_handler + (Http.jsonBody serial) + (decode) + ) + ) + ) + + Nothing -> Nothing diff --git a/src/battlemap/src/Update.elm b/src/battlemap/src/Update.elm index f411659..b0930b8 100644 --- a/src/battlemap/src/Update.elm +++ b/src/battlemap/src/Update.elm @@ -14,6 +14,7 @@ import Model.EndTurn import Model.HandleServerReply import Send.CharacterTurn +import Send.LoadBattlemap update : Event.Type -> Model.Type -> (Model.Type, (Cmd Event.Type)) update event model = @@ -63,6 +64,15 @@ update event model = Cmd.none ) + (Event.DebugLoadBattlemapRequest) -> + ( + model, + (case (Send.LoadBattlemap.try_sending model) of + (Just cmd) -> cmd + Nothing -> Cmd.none + ) + ) + (Event.ServerReplied (Result.Err error)) -> ( (Model.invalidate diff --git a/src/battlemap/src/View/Footer/TabMenu/Settings.elm b/src/battlemap/src/View/Footer/TabMenu/Settings.elm index cda43b2..3c23a15 100644 --- a/src/battlemap/src/View/Footer/TabMenu/Settings.elm +++ b/src/battlemap/src/View/Footer/TabMenu/Settings.elm @@ -43,6 +43,12 @@ get_html model = (Html.Events.onClick Event.DebugTeamSwitchRequest) ] [ (Html.text "[DEBUG] Switch team") ] + ), + (Html.button + [ + (Html.Events.onClick Event.DebugLoadBattlemapRequest) + ] + [ (Html.text "[DEBUG] Load battlemap") ] ) ] ) |