summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-01-16 23:02:31 +0100 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2019-01-16 23:02:31 +0100 |
commit | da7d8fa1eecae1a9c1ffd49e87e7cd14a7362fd5 (patch) | |
tree | bd484c7369359d22b66a395a5ae998dabac8adb0 | |
parent | 17b3c3ab34035c57b8594d7f674c5d9ac0a843fb (diff) |
...
-rw-r--r-- | src/battle/Makefile | 2 | ||||
-rw-r--r-- | src/battle/elm-package.json | 20 | ||||
-rwxr-xr-x[-rw-r--r--] | src/battle/src/Action/Scroll.elm | 14 | ||||
-rw-r--r-- | src/main-menu/src/Struct/BattleRequest.elm (renamed from src/main-menu/src/Struct/InvasionRequest.elm) | 55 | ||||
-rw-r--r-- | src/main-menu/src/Struct/BattleSummary.elm | 82 | ||||
-rw-r--r-- | src/main-menu/src/Struct/Event.elm | 10 | ||||
-rw-r--r-- | src/main-menu/src/Struct/UI.elm | 10 | ||||
-rw-r--r-- | src/main-menu/src/Update/HandleNewInvasion.elm | 35 | ||||
-rw-r--r-- | src/main-menu/src/View/Tab/NewInvasion.elm | 62 |
9 files changed, 165 insertions, 125 deletions
diff --git a/src/battle/Makefile b/src/battle/Makefile index 3b58a08..4fabb97 100644 --- a/src/battle/Makefile +++ b/src/battle/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 MAIN_MODULE ?= $(SRC_DIR)/Main.elm diff --git a/src/battle/elm-package.json b/src/battle/elm-package.json deleted file mode 100644 index e824a29..0000000 --- a/src/battle/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/battle/src/Action/Scroll.elm b/src/battle/src/Action/Scroll.elm index cf071ae..fd9e80a 100644..100755 --- a/src/battle/src/Action/Scroll.elm +++ b/src/battle/src/Action/Scroll.elm @@ -1,8 +1,8 @@ module Action.Scroll exposing (to) -- Elm ------------------------------------------------------------------------- -import Dom -import Dom.Scroll +import Browser.Dom +import Browser.Dom.Scroll import Task @@ -25,9 +25,9 @@ tile_to_px ui t = * (toFloat Constants.UI.tile_size) ) -scroll_to_x : Int -> Struct.UI.Type -> (Task.Task Dom.Error ()) +scroll_to_x : Int -> Struct.UI.Type -> (Task.Task Browser.Dom.Error ()) scroll_to_x x ui = - (Dom.Scroll.toX + (Browser.Dom.Scroll.toX Constants.UI.viewer_html_id ( (tile_to_px ui x) @@ -37,9 +37,9 @@ scroll_to_x x ui = ) ) -scroll_to_y : Int -> Struct.UI.Type -> (Task.Task Dom.Error ()) +scroll_to_y : Int -> Struct.UI.Type -> (Task.Task Browser.Dom.Error ()) scroll_to_y y ui = - (Dom.Scroll.toY + (Browser.Dom.Scroll.toY Constants.UI.viewer_html_id ( (tile_to_px ui y) @@ -52,7 +52,7 @@ scroll_to_y y ui = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -to : Struct.Location.Type -> Struct.UI.Type -> (Task.Task Dom.Error (List ())) +to : Struct.Location.Type -> Struct.UI.Type -> (Task.Task Browser.Dom.Error (List ())) to loc ui = (Task.sequence [ diff --git a/src/main-menu/src/Struct/InvasionRequest.elm b/src/main-menu/src/Struct/BattleRequest.elm index 3681b27..a02a1bf 100644 --- a/src/main-menu/src/Struct/InvasionRequest.elm +++ b/src/main-menu/src/Struct/BattleRequest.elm @@ -1,13 +1,13 @@ -module Struct.InvasionRequest exposing +module Struct.BattleRequest exposing ( Type, Size(..), new, get_ix, - get_category, + get_mode, get_size, get_map_id, - set_category, + set_mode, set_size, set_map_id, get_url_params @@ -29,7 +29,8 @@ type Size = type alias Type = { ix : Int, - category : Struct.BattleSummary.InvasionCategory, + mode : Struct.BattleSummary.Mode, + category : Struct.BattleSummary.Category, size : (Maybe Size), map_id : String } @@ -41,11 +42,12 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -new : Int -> Type -new ix = +new : Int -> Struct.BattleSummary.Category -> Type +new ix category= { ix = ix, - category = (Struct.BattleSummary.get_invasion_category ix), + mode = Struct.BattleSummary.Either, + category = category, size = Nothing, map_id = "" } @@ -53,11 +55,11 @@ new ix = get_ix : Type -> Int get_ix ir = ir.ix -get_category : Type -> Struct.BattleSummary.InvasionCategory -get_category ir = ir.category +get_mode : Type -> Struct.BattleSummary.Mode +get_mode ir = ir.mode -set_category : Struct.BattleSummary.InvasionCategory -> Type -> Type -set_category cat ir = {ir | category = cat} +set_mode : Struct.BattleSummary.Mode -> Type -> Type +set_mode mode ir = {ir | mode = mode} get_size : Type -> (Maybe Size) get_size ir = ir.size @@ -74,27 +76,30 @@ set_map_id id ir = {ir | map_id = id} get_url_params : Type -> String get_url_params ir = ( - "?ix=" + "?six=" ++ (String.fromInt ir.ix) + ++ "&cat=" ++ ( case ir.category of - Struct.BattleSummary.InvasionEither -> "" - Struct.BattleSummary.InvasionAttack -> "&m=a" - Struct.BattleSummary.InvasionDefend -> "&m=d" + Struct.BattleSummary.Invasion -> "i" + Struct.BattleSummary.Event -> "e" + Struct.BattleSummary.Campaign -> "c" ) - ++ + ++ "&mod=" ( - case ir.size of - Nothing -> "" - (Just Small) -> "&s=s" - (Just Medium) -> "&s=m" - (Just Large) -> "&s=l" + case ir.mode of + Struct.BattleSummary.Either -> "e" + Struct.BattleSummary.Attack -> "a" + Struct.BattleSummary.Defend -> "d" ) - ++ + ++ "&s=" ( - if (ir.map_id == "") - then "" - else ("&map_id=" ++ ir.map_id) + case ir.size of + (Just Medium) -> "m" + (Just Large) -> "l" + _ -> "s" ) + ++ "&map_id=" + ir.map_id ) diff --git a/src/main-menu/src/Struct/BattleSummary.elm b/src/main-menu/src/Struct/BattleSummary.elm index 3670879..772d52d 100644 --- a/src/main-menu/src/Struct/BattleSummary.elm +++ b/src/main-menu/src/Struct/BattleSummary.elm @@ -1,11 +1,15 @@ module Struct.BattleSummary exposing ( Type, - InvasionCategory(..), + Category(..), + Mode(..), get_id, get_name, - get_last_edit, + get_mode, + get_category, + get_deadline, is_players_turn, + is_pending, is_empty_slot, get_invasion_category, decoder, @@ -21,23 +25,46 @@ import Json.Decode.Pipeline -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -type InvasionCategory = - InvasionAttack - | InvasionDefend - | InvasionEither +type Category = + Invasion + | Event + | Campaign + +type Mode = + Attack + | Defend + | Either type alias Type = { ix : Int, id : String, name : String, - last_edit : String, - is_players_turn : Bool + mode : Mode, + category : Category, + deadline : String, + is_players_turn : Bool, + is_pending : Bool } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +mode_from_string : String -> Mode +mode_from_string str = + case str of + "a" -> Attack + "d" -> Defend + _ -> Either + +category_from_string : String -> Category +category_from_string str = + case str of + "i" -> Invasion + "e" -> Event + _ -> Campaign + + -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -48,22 +75,31 @@ get_id t = t.id get_name : Type -> String get_name t = t.name -get_last_edit : Type -> String -get_last_edit t = t.last_edit +get_mode : Type -> Mode +get_mode t = t.mode + +get_category : Type -> Category +get_category t = t.category + +get_deadline : Type -> String +get_deadline t = t.deadline is_players_turn : Type -> Bool is_players_turn t = t.is_players_turn +is_pending : Type -> Bool +is_pending t = t.is_pending + is_empty_slot : Type -> Bool is_empty_slot t = (t.id == "") -get_invasion_category : Int -> InvasionCategory +get_invasion_category : Int -> Mode get_invasion_category ix = if (ix < 3) - then InvasionAttack + then Attack else if (ix < 6) - then InvasionEither - else InvasionDefend + then Either + else Defend decoder : (Json.Decode.Decoder Type) decoder = @@ -72,8 +108,19 @@ decoder = |> (Json.Decode.Pipeline.required "ix" Json.Decode.int) |> (Json.Decode.Pipeline.required "id" Json.Decode.string) |> (Json.Decode.Pipeline.required "nme" Json.Decode.string) + |> + (Json.Decode.Pipeline.required + "mod" + (Json.Decode.map mode_from_string (Json.Decode.string)) + ) + |> + (Json.Decode.Pipeline.required + "cat" + (Json.Decode.map category_from_string (Json.Decode.string)) + ) |> (Json.Decode.Pipeline.required "ldt" Json.Decode.string) |> (Json.Decode.Pipeline.required "ipt" Json.Decode.bool) + |> (Json.Decode.Pipeline.required "ipd" Json.Decode.bool) ) none : Type @@ -82,6 +129,9 @@ none = ix = -1, id = "", name = "Unknown", - last_edit = "Never", - is_players_turn = False + mode = Either, + category = Campaign, + deadline = "Never", + is_players_turn = False, + is_pending = False } diff --git a/src/main-menu/src/Struct/Event.elm b/src/main-menu/src/Struct/Event.elm index decf171..8699ddb 100644 --- a/src/main-menu/src/Struct/Event.elm +++ b/src/main-menu/src/Struct/Event.elm @@ -6,7 +6,7 @@ import Http -- Main Menu ------------------------------------------------------------------- import Struct.BattleSummary import Struct.Error -import Struct.InvasionRequest +import Struct.BattleRequest import Struct.MapSummary import Struct.ServerReply import Struct.UI @@ -18,10 +18,10 @@ type Type = None | Failed Struct.Error.Type | ServerReplied (Result Http.Error (List Struct.ServerReply.Type)) - | NewInvasion Int - | InvasionSetSize Struct.InvasionRequest.Size - | InvasionSetMap Struct.MapSummary.Type - | InvasionSetCategory Struct.BattleSummary.InvasionCategory + | NewBattle (Int, Struct.BattleRequest.Category) + | BattleSetSize Struct.BattleRequest.Size + | BattleSetMap Struct.MapSummary.Type + | BattleSetMode Struct.BattleSummary.Mode | TabSelected Struct.UI.Tab attempted : (Result.Result err val) -> Type diff --git a/src/main-menu/src/Struct/UI.elm b/src/main-menu/src/Struct/UI.elm index 7539e90..88b38b7 100644 --- a/src/main-menu/src/Struct/UI.elm +++ b/src/main-menu/src/Struct/UI.elm @@ -15,18 +15,18 @@ module Struct.UI exposing ) -- Main Menu ------------------------------------------------------------------- -import Struct.InvasionRequest +import Struct.BattleRequest -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type Tab = DefaultTab - | NewInvasionTab + | NewBattleTab type Action = None - | NewInvasion Struct.InvasionRequest.Type + | NewBattle Struct.BattleRequest.Type type alias Type = { @@ -53,7 +53,7 @@ get_current_tab : Type -> Tab get_current_tab ui = case ui.action of None -> ui.current_tab - (NewInvasion _) -> NewInvasionTab + (NewBattle _) -> NewBattleTab set_current_tab : Tab -> Type -> Type set_current_tab tab ui = {ui | current_tab = tab} @@ -65,7 +65,7 @@ to_string : Tab -> String to_string tab = case tab of DefaultTab -> "Main Menu" - NewInvasionTab -> "New Invasion" + NewBattleTab -> "New Battle" get_action : Type -> Action get_action ui = ui.action diff --git a/src/main-menu/src/Update/HandleNewInvasion.elm b/src/main-menu/src/Update/HandleNewInvasion.elm index 1ea2b8a..0dd53c9 100644 --- a/src/main-menu/src/Update/HandleNewInvasion.elm +++ b/src/main-menu/src/Update/HandleNewInvasion.elm @@ -1,4 +1,4 @@ -module Update.HandleNewInvasion exposing +module Update.HandleNewBattle exposing ( apply_to, set_size, @@ -10,7 +10,7 @@ module Update.HandleNewInvasion exposing -- Main Menu ------------------------------------------------------------------- import Struct.BattleSummary import Struct.Event -import Struct.InvasionRequest +import Struct.BattleRequest import Struct.MapSummary import Struct.Model import Struct.UI @@ -24,7 +24,7 @@ import Struct.UI -------------------------------------------------------------------------------- set_size : ( Struct.Model.Type -> - Struct.InvasionRequest.Size -> + Struct.BattleRequest.Size -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) set_size model size = @@ -32,13 +32,13 @@ set_size model size = Struct.UI.None -> -- TODO: err (model, Cmd.none) - (Struct.UI.NewInvasion invasion) -> + (Struct.UI.NewBattle invasion) -> ( {model | ui = (Struct.UI.set_action - (Struct.UI.NewInvasion - (Struct.InvasionRequest.set_size size invasion) + (Struct.UI.NewBattle + (Struct.BattleRequest.set_size size invasion) ) model.ui ) @@ -48,7 +48,7 @@ set_size model size = set_category : ( Struct.Model.Type -> - Struct.BattleSummary.InvasionCategory -> + Struct.BattleSummary.BattleCategory -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) set_category model category = @@ -56,13 +56,13 @@ set_category model category = Struct.UI.None -> -- TODO: err (model, Cmd.none) - (Struct.UI.NewInvasion invasion) -> + (Struct.UI.NewBattle invasion) -> ( {model | ui = (Struct.UI.set_action - (Struct.UI.NewInvasion - (Struct.InvasionRequest.set_category category invasion) + (Struct.UI.NewBattle + (Struct.BattleRequest.set_category category invasion) ) model.ui ) @@ -80,17 +80,17 @@ set_map model map = Struct.UI.None -> -- TODO: err (model, Cmd.none) - (Struct.UI.NewInvasion invasion) -> + (Struct.UI.NewBattle invasion) -> ( {model | ui = (Struct.UI.set_action - (Struct.UI.NewInvasion - (Struct.InvasionRequest.set_map_id + (Struct.UI.NewBattle + (Struct.BattleRequest.set_map_id "" - (Struct.InvasionRequest.set_size + (Struct.BattleRequest.set_size -- TODO: get from map summary - Struct.InvasionRequest.Small + Struct.BattleRequest.Small invasion ) ) @@ -104,14 +104,15 @@ set_map model map = apply_to : ( Struct.Model.Type -> Int -> + Struct.BattleSummary.Category -> (Struct.Model.Type, (Cmd Struct.Event.Type)) ) -apply_to model ix = +apply_to model ix category = ( {model | ui = (Struct.UI.set_action - (Struct.UI.NewInvasion (Struct.InvasionRequest.new ix)) + (Struct.UI.NewBattle (Struct.BattleRequest.new ix category)) model.ui ) }, diff --git a/src/main-menu/src/View/Tab/NewInvasion.elm b/src/main-menu/src/View/Tab/NewInvasion.elm index b216b4c..8cba188 100644 --- a/src/main-menu/src/View/Tab/NewInvasion.elm +++ b/src/main-menu/src/View/Tab/NewInvasion.elm @@ -1,4 +1,4 @@ -module View.Tab.NewInvasion exposing (get_html) +module View.Tab.NewBattle exposing (get_html) -- Elm ------------------------------------------------------------------------- import Html @@ -9,7 +9,7 @@ import Html.Events import Struct.Event import Struct.Model import Struct.UI -import Struct.InvasionRequest +import Struct.BattleRequest import Struct.BattleSummary -------------------------------------------------------------------------------- @@ -24,8 +24,8 @@ select_category_html = (Html.button [ (Html.Events.onClick - (Struct.Event.InvasionSetCategory - Struct.BattleSummary.InvasionAttack + (Struct.Event.BattleSetCategory + Struct.BattleSummary.BattleAttack ) ) ] @@ -36,8 +36,8 @@ select_category_html = (Html.button [ (Html.Events.onClick - (Struct.Event.InvasionSetCategory - Struct.BattleSummary.InvasionDefend + (Struct.Event.BattleSetCategory + Struct.BattleSummary.BattleDefend ) ) ] @@ -48,7 +48,7 @@ select_category_html = ] ) -select_size_html : Struct.InvasionRequest.Size -> (Html.Html Struct.Event.Type) +select_size_html : Struct.BattleRequest.Size -> (Html.Html Struct.Event.Type) select_size_html max_size = (Html.div [ @@ -57,8 +57,8 @@ select_size_html max_size = (Html.button [ (Html.Events.onClick - (Struct.Event.InvasionSetSize - Struct.InvasionRequest.Small + (Struct.Event.BattleSetSize + Struct.BattleRequest.Small ) ) ] @@ -69,8 +69,8 @@ select_size_html max_size = (Html.button [ (Html.Events.onClick - (Struct.Event.InvasionSetSize - Struct.InvasionRequest.Medium + (Struct.Event.BattleSetSize + Struct.BattleRequest.Medium ) ) ] @@ -81,8 +81,8 @@ select_size_html max_size = (Html.button [ (Html.Events.onClick - (Struct.Event.InvasionSetSize - Struct.InvasionRequest.Large + (Struct.Event.BattleSetSize + Struct.BattleRequest.Large ) ) ] @@ -104,15 +104,19 @@ select_map_html = ) -get_actual_html : Struct.InvasionRequest.Type -> (Html.Html Struct.Event.Type) -get_actual_html inv_req = - case (Struct.InvasionRequest.get_category inv_req) of - Struct.BattleSummary.InvasionEither -> (select_category_html) - Struct.BattleSummary.InvasionAttack -> +get_actual_html : Struct.BattleRequest.Type -> (Html.Html Struct.Event.Type) +get_actual_html battle_req = + case (Struct.BattleRequest.get_category battle_req) of + Struct.BattleSummary.Invasion -> + + _ -> + case + Struct.BattleSummary.Either -> (select_category_html) + Struct.BattleSummary.Attack -> ( - case (Struct.InvasionRequest.get_size inv_req) of + case (Struct.BattleRequest.get_size battle_req) of -- TODO: use roster size as upper limit. - Nothing -> (select_size_html Struct.InvasionRequest.Large) + Nothing -> (select_size_html Struct.BattleRequest.Large) _ -> (Html.a [ @@ -120,7 +124,7 @@ get_actual_html inv_req = ( "/roster-editor/" ++ - (Struct.InvasionRequest.get_url_params inv_req) + (Struct.BattleRequest.get_url_params battle_req) ) ) ] @@ -129,16 +133,16 @@ get_actual_html inv_req = ] ) ) - Struct.BattleSummary.InvasionDefend -> + Struct.BattleSummary.Defend -> ( - case (Struct.InvasionRequest.get_map_id inv_req) of + case (Struct.BattleRequest.get_map_id battle_req) of -- FIXME: Requires model. "" -> (select_map_html) _ -> - case (Struct.InvasionRequest.get_size inv_req) of + case (Struct.BattleRequest.get_size battle_req) of Nothing -> -- TODO: use min(RosterSize, MapSize) as upper limit. - (select_size_html Struct.InvasionRequest.Large) + (select_size_html Struct.BattleRequest.Large) _ -> (Html.a [ @@ -146,8 +150,8 @@ get_actual_html inv_req = ( "/roster-editor/" ++ - (Struct.InvasionRequest.get_url_params - inv_req + (Struct.BattleRequest.get_url_params + battle_req ) ) ) @@ -168,5 +172,5 @@ get_html model = -- TODO: explain & let the user go back to the main menu. (Html.text "Error.") - (Struct.UI.NewInvasion inv_req) -> - (get_actual_html inv_req) + (Struct.UI.NewBattle battle_req) -> + (get_actual_html battle_req) |