| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-22 10:47:01 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-12-22 10:47:01 +0100 | 
| commit | 5f9384a442531b7133cce4edc07edffb0729c3d7 (patch) | |
| tree | e8bb40140e2cf84b05a0e5313e2d2b21637c5118 /src/map-editor | |
| parent | 0f2bae1ecdf08aec43b129994ac87570ef42e1f3 (diff) | |
Converts map-editor, JSON broken, dep. updates...
Diffstat (limited to 'src/map-editor')
| -rw-r--r-- | src/map-editor/Makefile | 2 | ||||
| -rw-r--r-- | src/map-editor/elm-package.json | 20 | ||||
| -rw-r--r-- | src/map-editor/elm.json | 29 | ||||
| -rw-r--r-- | src/map-editor/src/Comm/Send.elm | 32 | ||||
| -rw-r--r-- | src/map-editor/src/Comm/SendMapUpdate.elm | 17 | ||||
| -rw-r--r-- | src/map-editor/src/Comm/SetMap.elm | 4 | ||||
| -rw-r--r-- | src/map-editor/src/Main.elm | 6 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Event.elm | 8 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Location.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/Tile.elm | 6 | ||||
| -rw-r--r-- | src/map-editor/src/Struct/TilePattern.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 12 | ||||
| -rw-r--r-- | src/map-editor/src/View/Map.elm | 60 | ||||
| -rw-r--r-- | src/map-editor/src/View/Map/Tile.elm | 92 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Status/TileInfo.elm | 8 | ||||
| -rw-r--r-- | src/map-editor/src/View/SubMenu/Tiles.elm | 2 | ||||
| -rw-r--r-- | src/map-editor/www/index.html | 13 | 
17 files changed, 166 insertions, 149 deletions
| diff --git a/src/map-editor/Makefile b/src/map-editor/Makefile index 3b58a08..737be75 100644 --- a/src/map-editor/Makefile +++ b/src/map-editor/Makefile @@ -5,7 +5,7 @@ SRC_DIR ?= src  WWW_DIR ?= www  WWW_SCRIPT_DIR ?= $(WWW_DIR)/script -ELM_CC ?= elm-make --warn +ELM_CC ?= elm make --optimize  MAIN_MODULE ?= $(SRC_DIR)/Main.elm diff --git a/src/map-editor/elm-package.json b/src/map-editor/elm-package.json deleted file mode 100644 index e824a29..0000000 --- a/src/map-editor/elm-package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ -    "version": "1.0.0", -    "summary": "helpful summary of your project, less than 80 characters", -    "repository": "https://github.com/nsensfel/tacticians-client.git", -    "license": "Apache 2.0", -    "source-directories": [ -        "src", -        "../shared/elm" -    ], -    "exposed-modules": [], -    "dependencies": { -        "NoRedInk/elm-decode-pipeline": "3.0.0 <= v < 4.0.0", -        "andrewMacmurray/elm-delay": "2.0.3 <= v < 3.0.0", -        "elm-lang/core": "5.1.1 <= v < 6.0.0", -        "elm-lang/dom": "1.1.1 <= v < 2.0.0", -        "elm-lang/html": "2.0.0 <= v < 3.0.0", -        "elm-lang/http": "1.0.0 <= v < 2.0.0" -    }, -    "elm-version": "0.18.0 <= v < 0.19.0" -} diff --git a/src/map-editor/elm.json b/src/map-editor/elm.json new file mode 100644 index 0000000..cd41660 --- /dev/null +++ b/src/map-editor/elm.json @@ -0,0 +1,29 @@ +{ +    "type": "application", +    "source-directories": [ +        "src", +        "../shared/elm" +    ], +    "elm-version": "0.19.0", +    "dependencies": { +        "direct": { +            "NoRedInk/elm-json-decode-pipeline": "1.0.0", +            "elm/browser": "1.0.1", +            "elm/core": "1.0.2", +            "elm/html": "1.0.0", +            "elm/http": "2.0.0", +            "elm/json": "1.1.2", +            "elm/url": "1.0.0" +        }, +        "indirect": { +            "elm/bytes": "1.0.7", +            "elm/file": "1.0.1", +            "elm/time": "1.0.0", +            "elm/virtual-dom": "1.0.2" +        } +    }, +    "test-dependencies": { +        "direct": {}, +        "indirect": {} +    } +}
\ No newline at end of file diff --git a/src/map-editor/src/Comm/Send.elm b/src/map-editor/src/Comm/Send.elm index c61be07..4371b07 100644 --- a/src/map-editor/src/Comm/Send.elm +++ b/src/map-editor/src/Comm/Send.elm @@ -58,13 +58,16 @@ try_sending model recipient try_encoding_fun =     case (try_encoding_fun model) of        (Just serial) ->           (Just -            (Http.send -               Struct.Event.ServerReplied -               (Http.post -                  recipient -                  (Http.jsonBody serial) -                  (Json.Decode.list (decode)) -               ) +            (Http.post +               { +                  url = recipient, +                  body = (Http.jsonBody serial), +                  expect = +                     (Http.expectJson +                        Struct.Event.ServerReplied +                        (Json.Decode.list (decode)) +                     ) +               }              )           ) @@ -76,10 +79,13 @@ empty_request : (        (Cmd Struct.Event.Type)     )  empty_request model recipient = -   (Http.send -      Struct.Event.ServerReplied -      (Http.get -         recipient -         (Json.Decode.list (decode)) -      ) +   (Http.get +      { +         url = recipient, +         expect = +            (Http.expectJson +               Struct.Event.ServerReplied +               (Json.Decode.list (decode)) +            ) +      }     ) diff --git a/src/map-editor/src/Comm/SendMapUpdate.elm b/src/map-editor/src/Comm/SendMapUpdate.elm index 0a2b7da..c324ee5 100644 --- a/src/map-editor/src/Comm/SendMapUpdate.elm +++ b/src/map-editor/src/Comm/SendMapUpdate.elm @@ -22,20 +22,21 @@ import Struct.Tile  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- -encode_tile_border_values : Struct.Tile.Border -> (List Json.Encode.Value) +encode_tile_border_values : Struct.Tile.Border -> (List String)  encode_tile_border_values border =     [ -      (Json.Encode.string (Struct.Tile.get_border_type_id border)), -      (Json.Encode.string (Struct.Tile.get_border_variant_id border)) +      (Struct.Tile.get_border_type_id border), +      (Struct.Tile.get_border_variant_id border)     ]  encode_tile_instance : Struct.Tile.Instance -> Json.Encode.Value  encode_tile_instance tile_inst =     (Json.Encode.list +      (Json.Encode.string)        (           [ -            (Json.Encode.string (Struct.Tile.get_type_id tile_inst)), -            (Json.Encode.string (Struct.Tile.get_variant_id tile_inst)) +            (Struct.Tile.get_type_id tile_inst), +            (Struct.Tile.get_variant_id tile_inst)           ]           ++           (List.concatMap @@ -58,10 +59,8 @@ encode_map model =              (                 "t",                 (Json.Encode.list -                  (List.map -                     (encode_tile_instance) -                     (Array.toList (Struct.Map.get_tiles model.map)) -                  ) +                  (encode_tile_instance) +                  (Array.toList (Struct.Map.get_tiles model.map))                 )              )           ] diff --git a/src/map-editor/src/Comm/SetMap.elm b/src/map-editor/src/Comm/SetMap.elm index 171ed34..a60309d 100644 --- a/src/map-editor/src/Comm/SetMap.elm +++ b/src/map-editor/src/Comm/SetMap.elm @@ -50,7 +50,7 @@ deserialize_tile_instance map_width index t =        (a :: (b :: c)) ->           (Struct.Tile.new_instance              { -               x = (index % map_width), +               x = (modBy index map_width),                 y = (index // map_width)              }              a @@ -63,7 +63,7 @@ deserialize_tile_instance map_width index t =        _ ->           (Struct.Tile.new_instance              { -               x = (index % map_width), +               x = (modBy index map_width),                 y = (index // map_width)              }              "0" diff --git a/src/map-editor/src/Main.elm b/src/map-editor/src/Main.elm index 0d22cd5..e404695 100644 --- a/src/map-editor/src/Main.elm +++ b/src/map-editor/src/Main.elm @@ -1,7 +1,7 @@  -- Elm ------------------------------------------------------------------------ -import Html +import Browser --- Battlemap ------------------------------------------------------------------- +-- Map Editor ------------------------------------------------------------------  import Struct.Model  import Struct.Event  import Struct.Flags @@ -13,7 +13,7 @@ import ElmModule.Update  main : (Program Struct.Flags.Type Struct.Model.Type Struct.Event.Type)  main = -   (Html.programWithFlags +   (Browser.element        {           init = ElmModule.Init.init,           view = ElmModule.View.view, diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index 6d22666..3ea77bc 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -36,4 +36,10 @@ attempted act =     case act of        (Result.Ok _) -> None        (Result.Err msg) -> -         (Failed (Struct.Error.new Struct.Error.Failure (toString msg))) +         (Failed +            (Struct.Error.new +               Struct.Error.Failure +               -- TODO: find a way to get some relevant text here. +               "(text representation not implemented)" +            ) +         ) diff --git a/src/map-editor/src/Struct/Location.elm b/src/map-editor/src/Struct/Location.elm index 0b373cb..84025cd 100644 --- a/src/map-editor/src/Struct/Location.elm +++ b/src/map-editor/src/Struct/Location.elm @@ -81,7 +81,7 @@ dist loc_a loc_b =  decoder : (Json.Decode.Decoder Type)  decoder = -   (Json.Decode.Pipeline.decode +   (Json.Decode.succeed        Type        |> (Json.Decode.Pipeline.required "x" Json.Decode.int)        |> (Json.Decode.Pipeline.required "y" Json.Decode.int) diff --git a/src/map-editor/src/Struct/Tile.elm b/src/map-editor/src/Struct/Tile.elm index 2b33ed0..a8df2fc 100644 --- a/src/map-editor/src/Struct/Tile.elm +++ b/src/map-editor/src/Struct/Tile.elm @@ -207,13 +207,13 @@ get_border_variant_id tile_border = tile_border.variant_id  get_local_variant_ix : Instance -> Int  get_local_variant_ix tile_inst = -   ( +   (modBy        (noise_function           tile_inst.location.x           tile_inst.location.y           tile_inst.crossing_cost        ) -      % Constants.UI.local_variants_per_tile +      Constants.UI.local_variants_per_tile     )  solve_tile_instance : (Dict.Dict Ref Type) -> Instance -> Instance @@ -235,7 +235,7 @@ decoder : (Json.Decode.Decoder Type)  decoder =     (Json.Decode.map        (finish_decoding) -      (Json.Decode.Pipeline.decode +      (Json.Decode.succeed           PartiallyDecoded           |> (Json.Decode.Pipeline.required "id" Json.Decode.string)           |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) diff --git a/src/map-editor/src/Struct/TilePattern.elm b/src/map-editor/src/Struct/TilePattern.elm index 6e2e202..71a3af1 100644 --- a/src/map-editor/src/Struct/TilePattern.elm +++ b/src/map-editor/src/Struct/TilePattern.elm @@ -75,7 +75,7 @@ is_wild tp = tp.w  decoder : (Json.Decode.Decoder Type)  decoder = -   (Json.Decode.Pipeline.decode +   (Json.Decode.succeed        Type        |> (Json.Decode.Pipeline.required "v" (Json.Decode.string))        |> (Json.Decode.Pipeline.required "w" (Json.Decode.bool)) diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index e982ef7..e984807 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -3,13 +3,18 @@ module Update.HandleServerReply exposing (apply_to)  -- Elm -------------------------------------------------------------------------  import Http +import Url +  -- Shared ----------------------------------------------------------------------  import Action.Ports  import Struct.Flags +import Util.Http +  -- Map Editor ------------------------------------------------------------------  import Constants.IO +  import Struct.Map  import Struct.Error  import Struct.Event @@ -39,7 +44,7 @@ disconnected current_state =                    Constants.IO.base_url                    ++ "/login/?action=disconnect&goto="                    ++ -                  (Http.encodeUri +                  (Url.percentEncode                       (                          "/map-editor/?"                          ++ (Struct.Flags.get_params_as_url model.flags) @@ -119,7 +124,10 @@ apply_to model query_result =        (Result.Err error) ->           (              (Struct.Model.invalidate -               (Struct.Error.new Struct.Error.Networking (toString error)) +               (Struct.Error.new +                  Struct.Error.Networking +                  (Util.Http.error_to_string error) +               )                 model              ),              Cmd.none diff --git a/src/map-editor/src/View/Map.elm b/src/map-editor/src/View/Map.elm index b28f5c2..d98c088 100644 --- a/src/map-editor/src/View/Map.elm +++ b/src/map-editor/src/View/Map.elm @@ -9,7 +9,7 @@ import Html.Lazy  import List --- Map ------------------------------------------------------------------------- +-- Map Editor ------------------------------------------------------------------  import Constants.UI  import Struct.Event @@ -33,32 +33,28 @@ get_tiles_html tb map =        [           (Html.Attributes.class "map-tiles-layer"),           (Html.Attributes.style -            [ -               ( -                  "width", +            "width" +            ( +               (String.fromInt                    ( -                     (toString -                        ( -                           (Struct.Map.get_width map) -                           * Constants.UI.tile_size -                        ) -                     ) -                     ++ "px" +                     (Struct.Map.get_width map) +                     * Constants.UI.tile_size                    ) -               ), -               ( -                  "height", +               ) +               ++ "px" +            ) +         ), +         (Html.Attributes.style +            "height" +            ( +               (String.fromInt                    ( -                     (toString -                        ( -                           (Struct.Map.get_height map) -                           * Constants.UI.tile_size -                        ) -                     ) -                     ++ "px" +                     (Struct.Map.get_height map) +                     * Constants.UI.tile_size                    )                 ) -            ] +               ++ "px" +            )           )        ]        (List.map @@ -79,21 +75,17 @@ get_html model =        [           (Html.Attributes.class "map-actual"),           (Html.Attributes.style +            "transform"              (                 if ((Struct.UI.get_zoom_level model.ui) == 1) -               then [] +               then ""                 else -                  [ -                     ( -                        "transform", -                        ( -                           "scale(" -                           ++ -                           (toString (Struct.UI.get_zoom_level model.ui)) -                           ++ ")" -                        ) -                     ) -                  ] +                  ( +                     "scale(" +                     ++ +                     (String.fromFloat (Struct.UI.get_zoom_level model.ui)) +                     ++ ")" +                  )              )           )        ] diff --git a/src/map-editor/src/View/Map/Tile.elm b/src/map-editor/src/View/Map/Tile.elm index 32f536c..bf112d1 100644 --- a/src/map-editor/src/View/Map/Tile.elm +++ b/src/map-editor/src/View/Map/Tile.elm @@ -5,7 +5,7 @@ import Html  import Html.Attributes  import Html.Events --- Battlemap ------------------------------------------------------------------- +-- Map Editor ------------------------------------------------------------------  import Constants.UI  import Constants.IO @@ -25,21 +25,19 @@ get_layer_html : (  get_layer_html index border =     (Html.div        [ -         (Html.Attributes.class ("map-tile-icon-f-" ++ (toString index))), +         (Html.Attributes.class +            ("map-tile-icon-f-" ++ (String.fromInt index)) +         ),           (Html.Attributes.style -            [ -               ( -                  "background-image", -                  ( -                     "url(" -                     ++ Constants.IO.tile_assets_url -                     ++ (Struct.Tile.get_border_type_id border) -                     ++ "-f-" -                     ++ (Struct.Tile.get_border_variant_id border) -                     ++ ".svg)" -                  ) -               ) -            ] +            "background-image" +            ( +               "url(" +               ++ Constants.IO.tile_assets_url +               ++ (Struct.Tile.get_border_type_id border) +               ++ "-f-" +               ++ (Struct.Tile.get_border_variant_id border) +               ++ ".svg)" +            )           )        ]        [] @@ -55,17 +53,13 @@ get_content_html tile =           [              (Html.Attributes.class "map-tile-icon-bg"),              (Html.Attributes.style -               [ -                  ( -                     "background-image", -                     ( -                        "url(" -                        ++ Constants.IO.tile_assets_url -                        ++ (Struct.Tile.get_type_id tile) -                        ++ "-bg.svg)" -                     ) -                  ) -               ] +               "background-image" +               ( +                  "url(" +                  ++ Constants.IO.tile_assets_url +                  ++ (Struct.Tile.get_type_id tile) +                  ++ "-bg.svg)" +               )              )           ]           [] @@ -76,19 +70,15 @@ get_content_html tile =              [                 (Html.Attributes.class "map-tile-icon-dt"),                 (Html.Attributes.style -                  [ -                     ( -                        "background-image", -                        ( -                           "url(" -                           ++ Constants.IO.tile_assets_url -                           ++ (Struct.Tile.get_type_id tile) -                           ++ "-v-" -                           ++ (Struct.Tile.get_variant_id tile) -                           ++ ".svg)" -                        ) -                     ) -                  ] +                  "background-image" +                  ( +                     "url(" +                     ++ Constants.IO.tile_assets_url +                     ++ (Struct.Tile.get_type_id tile) +                     ++ "-v-" +                     ++ (Struct.Tile.get_variant_id tile) +                     ++ ".svg)" +                  )                 )              ]              [] @@ -127,7 +117,7 @@ get_html tb tile =              (Html.Attributes.class                 (                    "map-tile-variant-" -                  ++ (toString (Struct.Tile.get_local_variant_ix tile)) +                  ++ (String.fromInt (Struct.Tile.get_local_variant_ix tile))                 )              ),              (Html.Attributes.class "clickable"), @@ -135,16 +125,18 @@ get_html tb tile =                 (Struct.Event.TileSelected (Struct.Location.get_ref tile_loc))              ),              (Html.Attributes.style -               [ -                  ( -                     "top", -                     ((toString (tile_loc.y * Constants.UI.tile_size)) ++ "px") -                  ), -                  ( -                     "left", -                     ((toString (tile_loc.x * Constants.UI.tile_size)) ++ "px") -                  ) -               ] +               "top" +               ( +                  (String.fromInt (tile_loc.y * Constants.UI.tile_size)) +                  ++ "px" +               ) +            ), +            (Html.Attributes.style +               "left" +               ( +                  (String.fromInt (tile_loc.x * Constants.UI.tile_size)) +                  ++ "px" +               )              )           ]           (get_content_html tile) diff --git a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm index 91c4b48..450e52d 100644 --- a/src/map-editor/src/View/SubMenu/Status/TileInfo.elm +++ b/src/map-editor/src/View/SubMenu/Status/TileInfo.elm @@ -30,7 +30,7 @@ get_icon tile =           (Html.Attributes.class              (                 "map-tile-variant-" -               ++ (toString (Struct.Tile.get_local_variant_ix tile)) +               ++ (String.fromInt (Struct.Tile.get_local_variant_ix tile))              )           )        ] @@ -64,7 +64,7 @@ get_cost tile =           then              "Obstructed"           else -            ("Cost: " ++ (toString cost)) +            ("Cost: " ++ (String.fromInt cost))     in        (Html.div           [ @@ -88,9 +88,9 @@ get_location tile =              (Html.text                 (                    "{x: " -                  ++ (toString tile_location.x) +                  ++ (String.fromInt tile_location.x)                    ++ "; y: " -                  ++ (toString tile_location.y) +                  ++ (String.fromInt tile_location.y)                    ++ "}"                 )              ) diff --git a/src/map-editor/src/View/SubMenu/Tiles.elm b/src/map-editor/src/View/SubMenu/Tiles.elm index 591b312..d2c4c5b 100644 --- a/src/map-editor/src/View/SubMenu/Tiles.elm +++ b/src/map-editor/src/View/SubMenu/Tiles.elm @@ -16,7 +16,7 @@ import View.Map.Tile  --------------------------------------------------------------------------------  get_icon_html : Int -> (Html.Html Struct.Event.Type)  get_icon_html index = -   let tile_id = (toString index) in +   let tile_id = (String.fromInt index) in        (Html.div           [              (Html.Attributes.class "map-tile"), diff --git a/src/map-editor/www/index.html b/src/map-editor/www/index.html index 3828b22..6c68627 100644 --- a/src/map-editor/www/index.html +++ b/src/map-editor/www/index.html @@ -6,6 +6,7 @@        <link rel="icon" type="image/x-icon" href="/favicon.ico">     </head>     <body> +      <div id="elm-element"></div>        <script src="script/main.js"></script>        <script src="../global/script/session.js"></script>        <script src="../global/script/urlparams.js"></script> @@ -14,12 +15,16 @@           tacticians_online.session.load();           tacticians_online.app = -            Elm.Main.fullscreen +            Elm.Main.init              (                 { -                  user_id: tacticians_online.session.get_user_id(), -                  token: tacticians_online.session.get_token(), -                  url_params: tacticians_online.urlparams.get_parameters() +                  flags: +                     { +                        user_id: tacticians_online.session.get_user_id(), +                        token: tacticians_online.session.get_token(), +                        url_params: tacticians_online.urlparams.get_parameters() +                     }, +                  node: document.getElementById("elm-element")                 }              ); | 


