summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-27 11:31:17 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-09-27 11:31:17 +0200
commit2d54254e59289c452777fccb1f4d00b56eb7e451 (patch)
treeab0835ea7a5917a4363539022cbc730e582aed8a /elm/battlemap/src/Update
parentd2b5c94b717e2d1b7b73a74a1f1ec6af70890a96 (diff)
Improves error msgs & UI controls.
Diffstat (limited to 'elm/battlemap/src/Update')
-rw-r--r--elm/battlemap/src/Update/DirectionRequest.elm20
-rw-r--r--elm/battlemap/src/Update/EndTurn.elm30
-rw-r--r--elm/battlemap/src/Update/SelectCharacter.elm11
-rw-r--r--elm/battlemap/src/Update/SelectTile.elm25
4 files changed, 71 insertions, 15 deletions
diff --git a/elm/battlemap/src/Update/DirectionRequest.elm b/elm/battlemap/src/Update/DirectionRequest.elm
index da32240..e069439 100644
--- a/elm/battlemap/src/Update/DirectionRequest.elm
+++ b/elm/battlemap/src/Update/DirectionRequest.elm
@@ -11,7 +11,14 @@ import Error
make_it_so : Model.Type -> Battlemap.Direction.Type -> Model.Type
make_it_so model dir =
case model.selection of
- Nothing -> {model | state = (Model.Error Error.Programming)}
+ Nothing ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.Programming
+ "DirectionRequest: model moving char, no selection."
+ )
+ )
(Just selection) ->
let
(new_bmap, new_nav) =
@@ -31,7 +38,14 @@ make_it_so model dir =
apply_to : Model.Type -> Battlemap.Direction.Type -> Model.Type
apply_to model dir =
- case model.state of
+ case (Model.get_state model) of
Model.MovingCharacterWithButtons -> (make_it_so model dir)
Model.MovingCharacterWithClick -> (make_it_so model dir)
- _ -> {model | state = (Model.Error Error.IllegalAction)}
+ _ ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.IllegalAction
+ "This can only be done while moving a character."
+ )
+ )
diff --git a/elm/battlemap/src/Update/EndTurn.elm b/elm/battlemap/src/Update/EndTurn.elm
index b8b4ee5..ce9da28 100644
--- a/elm/battlemap/src/Update/EndTurn.elm
+++ b/elm/battlemap/src/Update/EndTurn.elm
@@ -14,10 +14,24 @@ import Error
make_it_so : Model.Type -> Model.Type
make_it_so model =
case model.selection of
- Nothing -> {model | state = (Model.Error Error.Programming)}
+ Nothing ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.Programming
+ "EndTurn: model moving char, no selection."
+ )
+ )
(Just selection) ->
case (Dict.get selection.character model.characters) of
- Nothing -> {model | state = (Model.Error Error.Programming)}
+ Nothing ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.Programming
+ "EndTurn: model moving char, unknown char selected."
+ )
+ )
(Just char) ->
{model |
state = Model.Default,
@@ -54,8 +68,14 @@ make_it_so model =
apply_to : Model.Type -> Model.Type
apply_to model =
- case model.state of
+ case (Model.get_state model) of
Model.MovingCharacterWithButtons -> (make_it_so model)
Model.MovingCharacterWithClick -> (make_it_so model)
- _ -> {model | state = (Model.Error Error.IllegalAction)}
-
+ _ ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.IllegalAction
+ "This can only be done while moving a character."
+ )
+ )
diff --git a/elm/battlemap/src/Update/SelectCharacter.elm b/elm/battlemap/src/Update/SelectCharacter.elm
index d42c7fc..570f82c 100644
--- a/elm/battlemap/src/Update/SelectCharacter.elm
+++ b/elm/battlemap/src/Update/SelectCharacter.elm
@@ -44,7 +44,14 @@ display_range dist loc_ref indicator bmap =
make_it_so : Model.Type -> Character.Ref -> Model.Type
make_it_so model char_id =
case (Dict.get char_id model.characters) of
- Nothing -> {model | state = (Model.Error Error.Programming)}
+ Nothing ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.Programming
+ "SelectCharacter: Unknown char selected."
+ )
+ )
(Just char) ->
let
new_range_indicator =
@@ -84,5 +91,5 @@ make_it_so model char_id =
apply_to : Model.Type -> Character.Ref -> Model.Type
apply_to model char_id =
- case model.state of
+ case (Model.get_state model) of
_ -> (make_it_so model char_id)
diff --git a/elm/battlemap/src/Update/SelectTile.elm b/elm/battlemap/src/Update/SelectTile.elm
index aa89c30..cc2af35 100644
--- a/elm/battlemap/src/Update/SelectTile.elm
+++ b/elm/battlemap/src/Update/SelectTile.elm
@@ -24,10 +24,18 @@ autopilot dir model =
go_to_tile : Model.Type -> Battlemap.Location.Ref -> Model.Type
go_to_tile model loc_ref =
case model.selection of
- Nothing -> {model | state = (Model.Error Error.Programming)}
+ Nothing ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.Programming
+ "SelectTile: model moving char, no selection."
+ )
+ )
(Just selection) ->
case (Dict.get loc_ref selection.range_indicator) of
- Nothing -> {model | state = Model.Default, selection = Nothing}
+ Nothing -> -- Clicked outside of the range indicator
+ (Model.reset model)
(Just indicator) ->
let
new_model =
@@ -69,12 +77,19 @@ go_to_tile model loc_ref =
then
(Update.EndTurn.apply_to new_model)
else
- {new_model | state = model.state}
+ {new_model | state = Model.MovingCharacterWithClick}
apply_to : Model.Type -> Battlemap.Location.Ref -> Model.Type
apply_to model loc_ref =
- case model.state of
+ case (Model.get_state model) of
Model.MovingCharacterWithButtons -> (go_to_tile model loc_ref)
Model.MovingCharacterWithClick -> (go_to_tile model loc_ref)
- _ -> {model | state = (Model.Error Error.IllegalAction)}
+ _ ->
+ (Model.invalidate
+ model
+ (Error.new
+ Error.IllegalAction
+ "This can only be done while moving a character."
+ )
+ )