summaryrefslogtreecommitdiff |
diff options
-rw-r--r-- | src/battlemap/src/Model/EndTurn.elm | 74 | ||||
-rw-r--r-- | src/battlemap/src/Model/SelectTile.elm | 56 | ||||
-rw-r--r-- | src/battlemap/src/Update.elm | 11 |
3 files changed, 85 insertions, 56 deletions
diff --git a/src/battlemap/src/Model/EndTurn.elm b/src/battlemap/src/Model/EndTurn.elm index d24c727..5ab2a46 100644 --- a/src/battlemap/src/Model/EndTurn.elm +++ b/src/battlemap/src/Model/EndTurn.elm @@ -9,53 +9,71 @@ import Battlemap import Character import Error +import Event import Model +import Send.CharacterTurn -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -make_it_so : Model.Type -> Character.Ref -> Model.Type +make_it_so : Model.Type -> Character.Ref -> (Model.Type, (Cmd Event.Type)) make_it_so model char_ref = case (Battlemap.try_getting_navigator_location model.battlemap) of (Just location) -> - (Model.reset - model - (Dict.update - char_ref - (\maybe_char -> - case maybe_char of - (Just char) -> - (Just - (Character.set_location location char) + case (Send.CharacterTurn.try model) of + (Just cmd) -> + ( + (Model.reset + model + (Dict.update + char_ref + (\maybe_char -> + case maybe_char of + (Just char) -> + (Just + (Character.set_location location char) + ) + Nothing -> Nothing ) - Nothing -> Nothing + model.characters + ) + ), + cmd ) - model.characters - ) - ) + + Nothing -> + (model, Cmd.none) Nothing -> - (Model.invalidate - model - (Error.new - Error.Programming - "EndTurn: model moving char, no navigator location." - ) + ( + (Model.invalidate + model + (Error.new + Error.Programming + "EndTurn: model moving char, no navigator location." + ) + ), + Cmd.none ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -apply_to : Model.Type -> Model.Type +apply_to : Model.Type -> (Model.Type, (Cmd Event.Type)) apply_to model = case (Model.get_state model) of - (Model.ControllingCharacter char_ref) -> (make_it_so model char_ref) + (Model.ControllingCharacter char_ref) -> + (make_it_so model char_ref) + _ -> - (Model.invalidate - model - (Error.new - Error.IllegalAction - "This can only be done while moving a character." - ) + ( + (Model.invalidate + model + (Error.new + Error.IllegalAction + "This can only be done while moving a character." + ) + ), + Cmd.none ) diff --git a/src/battlemap/src/Model/SelectTile.elm b/src/battlemap/src/Model/SelectTile.elm index b9b9465..2191d27 100644 --- a/src/battlemap/src/Model/SelectTile.elm +++ b/src/battlemap/src/Model/SelectTile.elm @@ -7,6 +7,8 @@ import Battlemap.Location import Character +import Event + import Model.RequestDirection import Model.EndTurn @@ -20,7 +22,12 @@ autopilot : Battlemap.Direction.Type -> Model.Type -> Model.Type autopilot dir model = (Model.RequestDirection.apply_to model dir) -go_to_tile : Model.Type -> Character.Ref -> Battlemap.Location.Ref -> Model.Type +go_to_tile : ( + Model.Type -> + Character.Ref -> + Battlemap.Location.Ref -> + (Model.Type, (Cmd Event.Type)) + ) go_to_tile model char_ref loc_ref = case (Battlemap.try_getting_navigator_location model.battlemap) of (Just nav_loc) -> @@ -38,13 +45,16 @@ go_to_tile model char_ref loc_ref = (Model.EndTurn.apply_to model) else -- And we didn't just click on that tile. - {model | - ui = - (UI.set_previous_action - model.ui - (Just (UI.SelectedLocation loc_ref)) - ) - } + ( + {model | + ui = + (UI.set_previous_action + model.ui + (Just (UI.SelectedLocation loc_ref)) + ) + }, + Cmd.none + ) else -- We have to try getting there. case @@ -67,26 +77,34 @@ go_to_tile model char_ref loc_ref = path ) in - {new_model | - ui = - (UI.set_previous_action - new_model.ui - (Just (UI.SelectedLocation loc_ref)) - ) - } + ( + {new_model | + ui = + (UI.set_previous_action + new_model.ui + (Just (UI.SelectedLocation loc_ref)) + ) + }, + Cmd.none + ) Nothing -> -- Clicked outside of the range indicator - (Model.reset model model.characters) + ((Model.reset model model.characters), Cmd.none) + Nothing -> -- Clicked outside of the range indicator - (Model.reset model model.characters) + ((Model.reset model model.characters), Cmd.none) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -apply_to : Model.Type -> Battlemap.Location.Ref -> Model.Type +apply_to : ( + Model.Type -> + Battlemap.Location.Ref -> + (Model.Type, (Cmd Event.Type)) + ) apply_to model loc_ref = case (Model.get_state model) of (Model.ControllingCharacter char_ref) -> (go_to_tile model char_ref loc_ref) - _ -> {model | state = (Model.InspectingTile loc_ref)} + _ -> ({model | state = (Model.InspectingTile loc_ref)}, Cmd.none) diff --git a/src/battlemap/src/Update.elm b/src/battlemap/src/Update.elm index d3786d6..091d641 100644 --- a/src/battlemap/src/Update.elm +++ b/src/battlemap/src/Update.elm @@ -26,20 +26,13 @@ update event model = ((Model.RequestDirection.apply_to new_model d), Cmd.none) (Event.TileSelected loc) -> - ((Model.SelectTile.apply_to new_model loc), Cmd.none) + (Model.SelectTile.apply_to new_model loc) (Event.CharacterSelected char_id) -> ((Model.SelectCharacter.apply_to new_model char_id), Cmd.none) Event.TurnEnded -> - ( - (Model.EndTurn.apply_to new_model), --- Cmd.none - (case (Send.CharacterTurn.try model) of - (Just cmd) -> cmd - Nothing -> Cmd.none - ) - ) + (Model.EndTurn.apply_to new_model) (Event.ScaleChangeRequested mod) -> if (mod == 0.0) |