summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/roster-editor')
-rw-r--r--src/roster-editor/src/Comm/JoinBattle.elm82
-rw-r--r--src/roster-editor/src/Constants/IO.elm.m43
-rw-r--r--src/roster-editor/src/ElmModule/Update.elm4
-rw-r--r--src/roster-editor/src/ElmModule/View.elm2
-rw-r--r--src/roster-editor/src/Struct/Event.elm1
-rw-r--r--src/roster-editor/src/Struct/Model.elm6
-rw-r--r--src/roster-editor/src/Update/JoinBattle.elm28
-rw-r--r--src/roster-editor/src/Update/ToggleBattleIndex.elm10
-rw-r--r--src/roster-editor/src/View/MainMenu.elm35
9 files changed, 157 insertions, 14 deletions
diff --git a/src/roster-editor/src/Comm/JoinBattle.elm b/src/roster-editor/src/Comm/JoinBattle.elm
new file mode 100644
index 0000000..582e269
--- /dev/null
+++ b/src/roster-editor/src/Comm/JoinBattle.elm
@@ -0,0 +1,82 @@
+module Comm.JoinBattle exposing (try)
+
+-- Elm -------------------------------------------------------------------------
+import Array
+
+import Json.Encode
+
+-- Shared ----------------------------------------------------------------------
+import Struct.Flags
+
+-- Roster Editor ---------------------------------------------------------------
+import Comm.Send
+
+import Constants.IO
+
+import Struct.Event
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- TYPES ------------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+try_encoding : Struct.Model.Type -> (Maybe Json.Encode.Value)
+try_encoding model =
+ (Just
+ (Json.Encode.object
+ [
+ ("stk", (Json.Encode.string model.session_token)),
+ ("pid", (Json.Encode.string model.player_id)),
+ (
+ "ix",
+ (Json.Encode.string
+ (Struct.Flags.force_get_param "ix" model.flags)
+ )
+ ),
+ (
+ "m",
+ (Json.Encode.string
+ (Struct.Flags.force_get_param "m" model.flags)
+ )
+ ),
+ (
+ "s",
+ (Json.Encode.string
+ (Struct.Flags.force_get_param "s" model.flags)
+ )
+ ),
+ (
+ "map_id",
+ (Json.Encode.string
+ (Struct.Flags.force_get_param "map_id" model.flags)
+ )
+ ),
+ (
+ "r",
+ (Json.Encode.array
+ (Array.map
+ (Json.Encode.int)
+ (Array.filter
+ (\e -> (e /= -1))
+ model.battle_order
+ )
+ )
+ )
+ )
+ ]
+ )
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+try : Struct.Model.Type -> (Maybe (Cmd Struct.Event.Type))
+try model =
+ (Comm.Send.try_sending
+ model
+ Constants.IO.join_battle_handler
+ try_encoding
+ )
diff --git a/src/roster-editor/src/Constants/IO.elm.m4 b/src/roster-editor/src/Constants/IO.elm.m4
index 17683ac..c09c556 100644
--- a/src/roster-editor/src/Constants/IO.elm.m4
+++ b/src/roster-editor/src/Constants/IO.elm.m4
@@ -12,6 +12,9 @@ roster_loading_handler = (roster_handler_url ++ "/rst_load")
roster_update_handler : String
roster_update_handler = (roster_handler_url ++ "/rst_update")
+join_battle_handler : String
+join_battle_handler = (roster_handler_url ++ "/btl_join")
+
armors_data_url : String
armors_data_url = (base_url ++ "/asset/data/armors.json")
diff --git a/src/roster-editor/src/ElmModule/Update.elm b/src/roster-editor/src/ElmModule/Update.elm
index 923b552..97d787d 100644
--- a/src/roster-editor/src/ElmModule/Update.elm
+++ b/src/roster-editor/src/ElmModule/Update.elm
@@ -9,6 +9,7 @@ import Struct.UI
import Update.GoToMainMenu
import Update.HandleServerReply
+import Update.JoinBattle
import Update.SelectCharacter
import Update.SelectTab
import Update.SendRoster
@@ -74,6 +75,9 @@ update event model =
Struct.Event.SaveRequest ->
(Update.SendRoster.apply_to (Struct.Model.save_character new_model))
+ Struct.Event.GoRequest ->
+ (Update.JoinBattle.apply_to (Struct.Model.save_character new_model))
+
(Struct.Event.SetCharacterName name) ->
(Update.SetName.apply_to new_model name)
diff --git a/src/roster-editor/src/ElmModule/View.elm b/src/roster-editor/src/ElmModule/View.elm
index f559cb5..bf086e3 100644
--- a/src/roster-editor/src/ElmModule/View.elm
+++ b/src/roster-editor/src/ElmModule/View.elm
@@ -27,7 +27,7 @@ view model =
(Html.Attributes.class "fullscreen-module")
]
[
- (View.MainMenu.get_html),
+ (View.MainMenu.get_html model),
(View.CurrentTab.get_html model),
(View.Controlled.get_html model),
(View.MessageBoard.get_html model)
diff --git a/src/roster-editor/src/Struct/Event.elm b/src/roster-editor/src/Struct/Event.elm
index cfafbdd..032a002 100644
--- a/src/roster-editor/src/Struct/Event.elm
+++ b/src/roster-editor/src/Struct/Event.elm
@@ -29,6 +29,7 @@ type Type =
| ClickedOnWeapon Bool
| ClickedOnGlyph Int
| SaveRequest
+ | GoRequest
| SetCharacterName String
diff --git a/src/roster-editor/src/Struct/Model.elm b/src/roster-editor/src/Struct/Model.elm
index b205004..8794aca 100644
--- a/src/roster-editor/src/Struct/Model.elm
+++ b/src/roster-editor/src/Struct/Model.elm
@@ -56,7 +56,7 @@ type alias Type =
glyph_boards: (Dict.Dict Struct.GlyphBoard.Ref Struct.GlyphBoard.Type),
portraits: (Dict.Dict Struct.Portrait.Ref Struct.Portrait.Type),
error: (Maybe Struct.Error.Type),
- used_indices: (Array.Array Bool),
+ battle_order: (Array.Array Int),
player_id: String,
roster_id: String,
edited_char: (Maybe Struct.Character.Type),
@@ -143,7 +143,7 @@ new flags =
then "0"
else flags.user_id
),
- used_indices =
+ battle_order =
(Array.repeat
(
case (Struct.Flags.maybe_get_param "s" flags) of
@@ -153,7 +153,7 @@ new flags =
(Just "l") -> 24
(Just _) -> 0
)
- False
+ -1
),
session_token = flags.token,
edited_char = Nothing,
diff --git a/src/roster-editor/src/Update/JoinBattle.elm b/src/roster-editor/src/Update/JoinBattle.elm
new file mode 100644
index 0000000..eb164bc
--- /dev/null
+++ b/src/roster-editor/src/Update/JoinBattle.elm
@@ -0,0 +1,28 @@
+module Update.JoinBattle exposing (apply_to)
+
+-- Elm -------------------------------------------------------------------------
+--import Array
+
+-- Roster Editor ---------------------------------------------------------------
+import Comm.JoinBattle
+
+import Struct.Event
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type))
+apply_to model =
+ (
+ model,
+ (case (Comm.JoinBattle.try model) of
+ (Just cmd) -> cmd
+ Nothing -> Cmd.none
+ )
+ )
+
diff --git a/src/roster-editor/src/Update/ToggleBattleIndex.elm b/src/roster-editor/src/Update/ToggleBattleIndex.elm
index 42d8374..584c314 100644
--- a/src/roster-editor/src/Update/ToggleBattleIndex.elm
+++ b/src/roster-editor/src/Update/ToggleBattleIndex.elm
@@ -22,11 +22,11 @@ remove_battle_index : (
remove_battle_index model char index =
{model |
edited_char = Nothing,
- used_indices =
+ battle_order =
(Array.set
(Struct.Character.get_battle_index char)
- False
- model.used_indices
+ -1
+ model.battle_order
),
characters =
(Array.set
@@ -43,12 +43,12 @@ give_battle_index : (
Struct.Model.Type
)
give_battle_index model char index =
- case (Util.Array.indexed_search (\e -> (not e)) model.used_indices) of
+ case (Util.Array.indexed_search (\e -> (e == -1)) model.battle_order) of
Nothing -> model
(Just (battle_index, _)) ->
{model |
edited_char = Nothing,
- used_indices = (Array.set battle_index True model.used_indices),
+ battle_order = (Array.set battle_index index model.battle_order),
characters =
(Array.set
index
diff --git a/src/roster-editor/src/View/MainMenu.elm b/src/roster-editor/src/View/MainMenu.elm
index 3663076..e70b5c0 100644
--- a/src/roster-editor/src/View/MainMenu.elm
+++ b/src/roster-editor/src/View/MainMenu.elm
@@ -1,12 +1,18 @@
module View.MainMenu exposing (get_html)
-- Elm -------------------------------------------------------------------------
+import Array
+
import Html
import Html.Attributes
import Html.Events
--- Map -------------------------------------------------------------------
+-- Shared ----------------------------------------------------------------------
+import Util.Html
+
+-- Roster Editor ---------------------------------------------------------------
import Struct.Event
+import Struct.Model
import Struct.UI
--------------------------------------------------------------------------------
@@ -41,14 +47,32 @@ get_save_button_html : (Html.Html Struct.Event.Type)
get_save_button_html =
(Html.button
[ (Html.Events.onClick Struct.Event.SaveRequest) ]
- [ (Html.text "Save") ]
+ [
+ (Html.text "Save")
+ ]
)
+get_go_button_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)
+get_go_button_html model =
+ if ((Array.length model.battle_order) > 0)
+ then
+ (Html.button
+ [
+ (Html.Events.onClick Struct.Event.GoRequest),
+ (Html.Attributes.class "blinking")
+ ]
+ [
+ (Html.text "Go!")
+ ]
+ )
+ else
+ (Util.Html.nothing)
+
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_html : (Html.Html Struct.Event.Type)
-get_html =
+get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)
+get_html model =
(Html.div
[
(Html.Attributes.class "main-menu")
@@ -57,6 +81,7 @@ get_html =
(get_main_menu_button_html),
(get_reset_button_html),
(get_characters_button_html),
- (get_save_button_html)
+ (get_save_button_html),
+ (get_go_button_html model)
]
)