From 2c9b2af9ac011a871c5c02d3e2258fca73a98880 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Wed, 27 Sep 2017 10:31:16 +0200 Subject: Splits client and server into two repositories. --- elm/battlemap/src/Update/EndTurn.elm | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 elm/battlemap/src/Update/EndTurn.elm (limited to 'elm/battlemap/src/Update/EndTurn.elm') diff --git a/elm/battlemap/src/Update/EndTurn.elm b/elm/battlemap/src/Update/EndTurn.elm new file mode 100644 index 0000000..7172b2f --- /dev/null +++ b/elm/battlemap/src/Update/EndTurn.elm @@ -0,0 +1,61 @@ +module Update.EndTurn exposing (apply_to) + +import Dict + +import Battlemap +import Battlemap.Direction +import Battlemap.Navigator +import Battlemap.Tile + +import Model + +import Error + +make_it_so : Model.Type -> Model.Type +make_it_so model = + case model.selection of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just selection) -> + case (Dict.get selection.character model.characters) of + Nothing -> {model | state = (Model.Error Error.Programming)} + (Just char) -> + {model | + state = Model.Default, + selection = Nothing, + battlemap = + (Battlemap.apply_to_all_tiles + (Battlemap.apply_to_tile_unsafe + (Battlemap.apply_to_tile_unsafe + model.battlemap + char.location + (\t -> {t | char_level = Nothing}) + ) + selection.navigator.current_location + (\t -> {t | char_level = (Just selection.character)}) + ) + (Battlemap.Tile.reset_tile) + ), + characters = + (Dict.update + selection.character + (\mc -> + case mc of + Nothing -> Nothing + (Just c) -> + (Just + {c | + location = selection.navigator.current_location + } + ) + ) + model.characters + ) + } + +apply_to : Model.Type -> Model.Type +apply_to model = + case model.state of + Model.MovingCharacterWithButtons -> (make_it_so model) + Model.MovingCharacterWithClick -> (make_it_so model) + _ -> {model | state = (Model.Error Error.IllegalAction)} + -- cgit v1.2.3-70-g09d2