aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--src/battle/src/Comm/CharacterTurn.elm76
-rw-r--r--src/battle/src/Comm/Send.elm17
-rw-r--r--src/battle/src/Main.elm4
-rw-r--r--src/battle/src/Struct/CharacterTurn.elm34
-rw-r--r--src/battle/src/Update/EndTurn.elm11
-rw-r--r--src/battle/src/Update/HandleAnimationEnded.elm14
-rw-r--r--src/battle/src/Update/HandleServerReply.elm6
-rw-r--r--src/battle/src/Update/TestAnimation.elm2
-rw-r--r--src/battle/www/index.html13
10 files changed, 72 insertions, 107 deletions
diff --git a/Makefile b/Makefile
index d686f73..31f3ef6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
################################################################################
## CONFIG ######################################################################
################################################################################
-MODULES ?= css global main-menu login roster-editor map-editor asset #battle
+MODULES ?= css global main-menu login roster-editor map-editor asset battle
SRC_DIR = ${CURDIR}/src
WWW_DIR = ${CURDIR}/www
diff --git a/src/battle/src/Comm/CharacterTurn.elm b/src/battle/src/Comm/CharacterTurn.elm
index b59dd4c..7809b00 100644
--- a/src/battle/src/Comm/CharacterTurn.elm
+++ b/src/battle/src/Comm/CharacterTurn.elm
@@ -21,77 +21,6 @@ import Struct.Model
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-encode_move : Struct.Model.Type -> (Maybe Json.Encode.Value)
-encode_move model =
- case (Struct.CharacterTurn.get_path model.char_turn) of
- [] -> Nothing
- path ->
- (Just
- (Json.Encode.object
- [
- ("t", (Json.Encode.string "mov")),
- (
- "p",
- (Json.Encode.list
- (List.map
- (
- (Json.Encode.string)
- <<
- (Struct.Direction.to_string)
- )
- (List.reverse path)
- )
- )
- )
- ]
- )
- )
-
-encode_weapon_switch : Struct.Model.Type -> (Maybe Json.Encode.Value)
-encode_weapon_switch model =
- if (Struct.CharacterTurn.has_switched_weapons model.char_turn)
- then
- (Just
- (Json.Encode.object
- [
- ("t", (Json.Encode.string "swp"))
- ]
- )
- )
- else
- Nothing
-
-encode_attack : Struct.Model.Type -> (Maybe Json.Encode.Value)
-encode_attack model =
- case (Struct.CharacterTurn.try_getting_target model.char_turn) of
- Nothing -> Nothing
-
- (Just ix) ->
- (Just
- (Json.Encode.object
- [
- ("t", (Json.Encode.string "atk")),
- ("tix", (Json.Encode.int ix))
- ]
- )
- )
-
-encode_actions : Struct.Model.Type -> (List Json.Encode.Value)
-encode_actions model =
- case
- (
- (encode_move model),
- (encode_weapon_switch model),
- (encode_attack model)
- )
- of
- ((Just move), Nothing, Nothing) -> [move]
- ((Just move), Nothing, (Just attack)) -> [move, attack]
- ((Just move), (Just switch_weapon), Nothing) -> [move, switch_weapon]
- (Nothing, (Just switch_weapon), Nothing) -> [switch_weapon]
- (Nothing, Nothing, (Just attack)) -> [attack]
- _ -> []
-
try_encoding : Struct.Model.Type -> (Maybe Json.Encode.Value)
try_encoding model =
case (Struct.CharacterTurn.try_getting_active_character model.char_turn) of
@@ -106,10 +35,7 @@ try_encoding model =
"cix",
(Json.Encode.int (Struct.Character.get_index char))
),
- (
- "act",
- (Json.Encode.list (encode_actions model))
- )
+ ("act", (Struct.CharacterTurn.encode model.char_turn))
]
)
)
diff --git a/src/battle/src/Comm/Send.elm b/src/battle/src/Comm/Send.elm
index f501b19..d577e58 100644
--- a/src/battle/src/Comm/Send.elm
+++ b/src/battle/src/Comm/Send.elm
@@ -66,13 +66,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))
+ )
+ }
)
)
diff --git a/src/battle/src/Main.elm b/src/battle/src/Main.elm
index 8140041..e0dd884 100644
--- a/src/battle/src/Main.elm
+++ b/src/battle/src/Main.elm
@@ -1,5 +1,5 @@
-- Elm ------------------------------------------------------------------------
-import Html
+import Browser
-- Map -------------------------------------------------------------------
import Struct.Model
@@ -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/battle/src/Struct/CharacterTurn.elm b/src/battle/src/Struct/CharacterTurn.elm
index c832698..d4cba5f 100644
--- a/src/battle/src/Struct/CharacterTurn.elm
+++ b/src/battle/src/Struct/CharacterTurn.elm
@@ -17,10 +17,12 @@ module Struct.CharacterTurn exposing
set_active_character_no_reset,
set_navigator,
try_getting_active_character,
- try_getting_navigator
+ try_getting_navigator,
+ encode
)
-- Elm -------------------------------------------------------------------------
+import Json.Encode
-- Battle ----------------------------------------------------------------------
import Struct.Character
@@ -208,3 +210,33 @@ set_target target ct =
try_getting_target : Type -> (Maybe Int)
try_getting_target ct = ct.target
+
+encode : Type -> (Json.Encode.Value)
+encode ct =
+ (Json.Encode.object
+ [
+ (
+ "mov",
+ (Json.Encode.list
+ (
+ (Json.Encode.string)
+ <<
+ (Struct.Direction.to_string)
+ )
+ (List.reverse (get_path ct))
+ )
+ ),
+ ("wps", (Json.Encode.bool ct.has_switched_weapons)),
+ (
+ "tar",
+ (Json.Encode.int
+ (
+ case ct.target of
+ Nothing -> -1
+ (Just ix) -> ix
+ )
+ )
+ )
+ ]
+ )
+
diff --git a/src/battle/src/Update/EndTurn.elm b/src/battle/src/Update/EndTurn.elm
index 8aa9e6f..36c5869 100644
--- a/src/battle/src/Update/EndTurn.elm
+++ b/src/battle/src/Update/EndTurn.elm
@@ -64,22 +64,19 @@ apply_to model =
(
Struct.CharacterTurn.MovedCharacter,
(Just char),
- (Just nav)
- ) ->
- (make_it_so model char nav)
+ (Just nav)) ->
+ (make_it_so model char nav)
(
Struct.CharacterTurn.ChoseTarget,
(Just char),
- (Just nav)
- ) ->
+ (Just nav)) ->
(make_it_so model char nav)
(
Struct.CharacterTurn.SwitchedWeapons,
(Just char),
- (Just nav)
- ) ->
+ (Just nav)) ->
(make_it_so model char nav)
(Struct.CharacterTurn.SelectedCharacter, (Just char), (Just nav)) ->
diff --git a/src/battle/src/Update/HandleAnimationEnded.elm b/src/battle/src/Update/HandleAnimationEnded.elm
index 90782e7..332d368 100644
--- a/src/battle/src/Update/HandleAnimationEnded.elm
+++ b/src/battle/src/Update/HandleAnimationEnded.elm
@@ -43,7 +43,7 @@ handle_char_focus model animator char_index =
model.ui
)
),
- (Delay.after 2.0 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 2.0 Delay.Second Struct.Event.AnimationEnded)
]
)
)
@@ -59,7 +59,7 @@ handle_char_focus model animator char_index =
model.ui
)
),
- (Delay.after 0.3 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 0.3 Delay.Second Struct.Event.AnimationEnded)
]
)
)
@@ -68,7 +68,7 @@ handle_char_focus model animator char_index =
_ ->
(
model,
- (Delay.after 1.0 Time.millisecond Struct.Event.AnimationEnded)
+ (Delay.after 1.0 Delay.Millisecond Struct.Event.AnimationEnded)
)
prepare_next_animation : (
@@ -84,7 +84,7 @@ prepare_next_animation model animator =
(Struct.TurnResultAnimator.AttackSetup _) ->
(
model,
- (Delay.after 1.0 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 1.0 Delay.Second Struct.Event.AnimationEnded)
)
(Struct.TurnResultAnimator.TurnResult turn_result) ->
@@ -92,19 +92,19 @@ prepare_next_animation model animator =
(Struct.TurnResult.Attacked _) ->
(
model,
- (Delay.after 3.0 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 3.0 Delay.Second Struct.Event.AnimationEnded)
)
_ ->
(
model,
- (Delay.after 0.1 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 0.1 Delay.Second Struct.Event.AnimationEnded)
)
_ ->
(
model,
- (Delay.after 0.3 Time.second Struct.Event.AnimationEnded)
+ (Delay.after 0.3 Delay.Second Struct.Event.AnimationEnded)
)
--------------------------------------------------------------------------------
diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm
index d3c44f8..f552d98 100644
--- a/src/battle/src/Update/HandleServerReply.elm
+++ b/src/battle/src/Update/HandleServerReply.elm
@@ -11,6 +11,8 @@ import Http
import Time
+import Url
+
-- Shared ----------------------------------------------------------------------
import Action.Ports
@@ -69,7 +71,7 @@ disconnected current_state =
Constants.IO.base_url
++ "/login/?action=disconnect&goto="
++
- (Http.encodeUri
+ (Url.percentEncode
(
"/battle/?"
++ (Struct.Flags.get_params_as_url model.flags)
@@ -173,7 +175,7 @@ add_to_timeline turn_results current_state =
)
},
(
- (Delay.after 1 Time.millisecond Struct.Event.AnimationEnded)
+ (Delay.after 1 Delay.Millisecond Struct.Event.AnimationEnded)
:: cmds
)
)
diff --git a/src/battle/src/Update/TestAnimation.elm b/src/battle/src/Update/TestAnimation.elm
index e23d577..a2fec9a 100644
--- a/src/battle/src/Update/TestAnimation.elm
+++ b/src/battle/src/Update/TestAnimation.elm
@@ -23,5 +23,5 @@ apply_to : (
apply_to model =
(
(Struct.Model.initialize_animator model),
- (Delay.after 1 Time.millisecond Struct.Event.AnimationEnded)
+ (Delay.after 1 Delay.Millisecond Struct.Event.AnimationEnded)
)
diff --git a/src/battle/www/index.html b/src/battle/www/index.html
index 2c69952..9acc21c 100644
--- a/src/battle/www/index.html
+++ b/src/battle/www/index.html
@@ -8,6 +8,7 @@
<link rel="icon" type="image/x-icon" href="/favicon.ico">
</head>
<body>
+ <div id="elm-page"></div>
<script src="script/main.js"></script>
<script src="../global/script/session.js"></script>
<script src="../global/script/urlparams.js"></script>
@@ -16,12 +17,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-page")
}
);