summaryrefslogtreecommitdiff |
diff options
author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-07-10 22:13:48 +0200 |
---|---|---|
committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2018-07-10 22:13:48 +0200 |
commit | 7b891ce04190365080fb4ef5d8dac68528a81af1 (patch) | |
tree | 78f332b074723167bde91b46929e450c8c6049c9 /src/map-editor | |
parent | f63602557a2f7320a7e02a3bf7dd9b339efaf4d1 (diff) |
Still working on it...
Diffstat (limited to 'src/map-editor')
-rw-r--r-- | src/map-editor/src/Comm/LoadMap.elm (renamed from src/map-editor/src/Comm/LoadBattlemap.elm) | 6 | ||||
-rw-r--r-- | src/map-editor/src/Comm/Okay.elm | 22 | ||||
-rw-r--r-- | src/map-editor/src/Comm/Send.elm | 11 | ||||
-rw-r--r-- | src/map-editor/src/Constants/Movement.elm | 10 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Event.elm | 15 | ||||
-rw-r--r-- | src/map-editor/src/Struct/HelpRequest.elm | 4 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Map.elm (renamed from src/map-editor/src/Struct/Battlemap.elm) | 66 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Model.elm | 170 | ||||
-rw-r--r-- | src/map-editor/src/Struct/ServerReply.elm | 13 | ||||
-rw-r--r-- | src/map-editor/src/Struct/Toolbox.elm | 15 | ||||
-rw-r--r-- | src/map-editor/src/Struct/UI.elm | 53 | ||||
-rw-r--r-- | src/map-editor/src/Update/HandleServerReply.elm | 151 | ||||
-rw-r--r-- | src/map-editor/src/Update/SelectTile.elm | 147 |
13 files changed, 111 insertions, 572 deletions
diff --git a/src/map-editor/src/Comm/LoadBattlemap.elm b/src/map-editor/src/Comm/LoadMap.elm index cd29acf..2907f3a 100644 --- a/src/map-editor/src/Comm/LoadBattlemap.elm +++ b/src/map-editor/src/Comm/LoadMap.elm @@ -1,4 +1,4 @@ -module Comm.LoadBattlemap exposing (try) +module Comm.LoadMap exposing (try) -- Elm ------------------------------------------------------------------------- import Json.Encode @@ -25,7 +25,7 @@ try_encoding model = [ ("stk", (Json.Encode.string model.session_token)), ("pid", (Json.Encode.string model.player_id)), - ("bmi", (Json.Encode.string model.battlemap_id)) + ("mix", (Json.Encode.string model.map_ix)) ] ) ) @@ -37,6 +37,6 @@ try : Struct.Model.Type -> (Maybe (Cmd Struct.Event.Type)) try model = (Comm.Send.try_sending model - Constants.IO.battlemap_loading_handler + Constants.IO.map_loading_handler try_encoding ) diff --git a/src/map-editor/src/Comm/Okay.elm b/src/map-editor/src/Comm/Okay.elm new file mode 100644 index 0000000..8ade538 --- /dev/null +++ b/src/map-editor/src/Comm/Okay.elm @@ -0,0 +1,22 @@ +module Comm.Okay exposing (decode) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode + +-- Battlemap ------------------------------------------------------------------- +import Struct.Tile +import Struct.ServerReply + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decode : (Json.Decode.Decoder Struct.ServerReply.Type) +decode = (Json.Decode.succeed Struct.ServerReply.Okay) diff --git a/src/map-editor/src/Comm/Send.elm b/src/map-editor/src/Comm/Send.elm index a6129cd..cbb6a28 100644 --- a/src/map-editor/src/Comm/Send.elm +++ b/src/map-editor/src/Comm/Send.elm @@ -7,13 +7,8 @@ import Json.Decode import Json.Encode -- Battlemap ------------------------------------------------------------------- -import Comm.AddArmor -import Comm.AddChar import Comm.AddTile -import Comm.AddWeapon import Comm.SetMap -import Comm.SetTimeline -import Comm.TurnResults import Struct.Event import Struct.ServerReply @@ -30,12 +25,8 @@ internal_decoder : String -> (Json.Decode.Decoder Struct.ServerReply.Type) internal_decoder reply_type = case reply_type of "add_tile" -> (Comm.AddTile.decode) - "add_armor" -> (Comm.AddArmor.decode) - "add_char" -> (Comm.AddChar.decode) - "add_weapon" -> (Comm.AddWeapon.decode) "set_map" -> (Comm.SetMap.decode) - "turn_results" -> (Comm.TurnResults.decode) - "set_timeline" -> (Comm.SetTimeline.decode) + "okay" -> (Comm.Okay.decode) other -> (Json.Decode.fail ( diff --git a/src/map-editor/src/Constants/Movement.elm b/src/map-editor/src/Constants/Movement.elm new file mode 100644 index 0000000..a2a5c1e --- /dev/null +++ b/src/map-editor/src/Constants/Movement.elm @@ -0,0 +1,10 @@ +module Constants.Movement exposing (..) + +max_points : Int +max_points = 200 + +cost_when_occupied_tile : Int +cost_when_occupied_tile = 201 + +cost_when_out_of_bounds : Int +cost_when_out_of_bounds = 255 diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index 716718e..2edd09b 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -15,26 +15,13 @@ import Struct.UI -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type Type = - AbortTurnRequest - | AnimationEnded - | AttackWithoutMovingRequest - | CharacterInfoRequested Int - | CharacterSelected Int - | DebugLoadBattlemapRequest - | DebugTeamSwitchRequest - | DebugTestAnimation - | DirectionRequested Struct.Direction.Type + None | Failed Struct.Error.Type - | LookingForCharacter Int - | None | ScaleChangeRequested Float | ServerReplied (Result Http.Error (List Struct.ServerReply.Type)) | TabSelected Struct.UI.Tab | TileSelected Struct.Location.Ref - | CharacterOrTileSelected Struct.Location.Ref - | TurnEnded | RequestedHelp Struct.HelpRequest.Type - | WeaponSwitchRequest attempted : (Result.Result err val) -> Type attempted act = diff --git a/src/map-editor/src/Struct/HelpRequest.elm b/src/map-editor/src/Struct/HelpRequest.elm index 3357b56..92d80eb 100644 --- a/src/map-editor/src/Struct/HelpRequest.elm +++ b/src/map-editor/src/Struct/HelpRequest.elm @@ -3,11 +3,11 @@ module Struct.HelpRequest exposing (Type(..)) -- Elm ------------------------------------------------------------------------- -- Battlemap ------------------------------------------------------------------- -import Struct.Character +import Struct.Toolbox -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type Type = None - | HelpOnRank Struct.Character.Rank + | HelpOnTool Struct.Toolbox.Tool diff --git a/src/map-editor/src/Struct/Battlemap.elm b/src/map-editor/src/Struct/Map.elm index fee4901..b5ee795 100644 --- a/src/map-editor/src/Struct/Battlemap.elm +++ b/src/map-editor/src/Struct/Map.elm @@ -1,4 +1,4 @@ -module Struct.Battlemap exposing +module Struct.Map exposing ( Type, empty, @@ -14,13 +14,10 @@ module Struct.Battlemap exposing -- Elm ------------------------------------------------------------------------- import Array --- Battlemap ------------------------------------------------------------------- -import Struct.Character +-- Map ------------------------------------------------------------------- import Struct.Tile import Struct.Location -import Constants.Movement - -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -35,29 +32,29 @@ type alias Type = -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- location_to_index : Struct.Location.Type -> Type -> Int -location_to_index loc bmap = - ((loc.y * bmap.width) + loc.x) +location_to_index loc map = + ((loc.y * map.width) + loc.x) has_location : Struct.Location.Type -> Type -> Bool -has_location loc bmap = +has_location loc map = ( (loc.x >= 0) && (loc.y >= 0) - && (loc.x < bmap.width) - && (loc.y < bmap.height) + && (loc.x < map.width) + && (loc.y < map.height) ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- get_width : Type -> Int -get_width bmap = bmap.width +get_width map = map.width get_height : Type -> Int -get_height bmap = bmap.height +get_height map = map.height get_tiles : Type -> (Array.Array Struct.Tile.Instance) -get_tiles bmap = bmap.content +get_tiles map = map.content empty : Type empty = @@ -80,44 +77,11 @@ try_getting_tile_at : ( Type -> (Maybe Struct.Tile.Instance) ) -try_getting_tile_at loc bmap = - (Array.get (location_to_index loc bmap) bmap.content) - -get_movement_cost_function : ( - Type -> - Struct.Location.Type -> - (List Struct.Character.Type) -> - Struct.Location.Type -> - Int - ) -get_movement_cost_function bmap start_loc char_list loc = - if (has_location loc bmap) - then - case (Array.get (location_to_index loc bmap) bmap.content) of - (Just tile) -> - if - (List.any - ( - \c -> - ( - ((Struct.Character.get_location c) == loc) - && (loc /= start_loc) - && (Struct.Character.is_alive c) - ) - ) - char_list - ) - then - Constants.Movement.cost_when_occupied_tile - else - (Struct.Tile.get_instance_cost tile) - - Nothing -> Constants.Movement.cost_when_out_of_bounds - else - Constants.Movement.cost_when_out_of_bounds +try_getting_tile_at loc map = + (Array.get (location_to_index loc map) map.content) solve_tiles : (List Struct.Tile.Type) -> Type -> Type -solve_tiles tiles bmap = - {bmap | - content = (Array.map (Struct.Tile.solve_tile_instance tiles) bmap.content) +solve_tiles tiles map = + {map | + content = (Array.map (Struct.Tile.solve_tile_instance tiles) map.content) } diff --git a/src/map-editor/src/Struct/Model.elm b/src/map-editor/src/Struct/Model.elm index 0095364..4f089ec 100644 --- a/src/map-editor/src/Struct/Model.elm +++ b/src/map-editor/src/Struct/Model.elm @@ -2,18 +2,9 @@ module Struct.Model exposing ( Type, new, - add_character, - update_character, - update_character_fun, - add_weapon, - add_armor, add_tile, invalidate, - initialize_animator, - apply_animator_step, - move_animator_to_next_step, reset, - full_debug_reset, clear_error ) @@ -22,19 +13,13 @@ import Array import Dict --- Battlemap ------------------------------------------------------------------- -import Struct.Armor -import Struct.Battlemap -import Struct.Character -import Struct.CharacterTurn +-- Map ------------------------------------------------------------------- +import Struct.Map import Struct.Error import Struct.Flags import Struct.HelpRequest import Struct.Tile -import Struct.TurnResult -import Struct.TurnResultAnimator import Struct.UI -import Struct.Weapon import Util.Array @@ -44,20 +29,13 @@ import Util.Array type alias Type = { help_request: Struct.HelpRequest.Type, - animator: (Maybe Struct.TurnResultAnimator.Type), - battlemap: Struct.Battlemap.Type, - characters: (Array.Array Struct.Character.Type), - weapons: (Dict.Dict Struct.Weapon.Ref Struct.Weapon.Type), - armors: (Dict.Dict Struct.Armor.Ref Struct.Armor.Type), + map: Struct.Map.Type, tiles: (Dict.Dict Struct.Tile.Ref Struct.Tile.Type), error: (Maybe Struct.Error.Type), player_id: String, - battlemap_id: String, + map_id: String, session_token: String, - player_ix: Int, - ui: Struct.UI.Type, - char_turn: Struct.CharacterTurn.Type, - timeline: (Array.Array Struct.TurnResult.Type) + ui: Struct.UI.Type } -------------------------------------------------------------------------------- @@ -70,18 +48,14 @@ type alias Type = new : Struct.Flags.Type -> Type new flags = let - maybe_battlemap_id = (Struct.Flags.maybe_get_param "id" flags) + maybe_map_id = (Struct.Flags.maybe_get_param "id" flags) model = { help_request = Struct.HelpRequest.None, - animator = Nothing, - battlemap = (Struct.Battlemap.empty), - characters = (Array.empty), - weapons = (Dict.empty), - armors = (Dict.empty), + map = (Struct.Map.empty), tiles = (Dict.empty), error = Nothing, - battlemap_id = "", + map_id = "", player_id = ( if (flags.user_id == "") @@ -89,55 +63,20 @@ new flags = else flags.user_id ), session_token = flags.token, - player_ix = 0, - ui = (Struct.UI.default), - char_turn = (Struct.CharacterTurn.new), - timeline = (Array.empty) + ui = (Struct.UI.default) } in - case maybe_battlemap_id of + case maybe_map_id of Nothing -> (invalidate (Struct.Error.new Struct.Error.Failure - "Could not find battlemap id." + "Could not find map id." ) model ) - (Just id) -> {model | battlemap_id = id} - -add_character : Struct.Character.Type -> Type -> Type -add_character char model = - {model | - characters = - (Array.push - char - model.characters - ) - } - -add_weapon : Struct.Weapon.Type -> Type -> Type -add_weapon wp model = - {model | - weapons = - (Dict.insert - (Struct.Weapon.get_id wp) - wp - model.weapons - ) - } - -add_armor : Struct.Armor.Type -> Type -> Type -add_armor ar model = - {model | - armors = - (Dict.insert - (Struct.Armor.get_id ar) - ar - model.armors - ) - } + (Just id) -> {model | map_id = id} add_tile : Struct.Tile.Type -> Type -> Type add_tile tl model = @@ -158,90 +97,7 @@ reset model = ui = (Struct.UI.reset_displayed_nav (Struct.UI.set_previous_action Nothing model.ui) - ), - char_turn = (Struct.CharacterTurn.new) - } - -full_debug_reset : Type -> Type -full_debug_reset model = - {model | - help_request = Struct.HelpRequest.None, - animator = Nothing, - battlemap = (Struct.Battlemap.empty), - characters = (Array.empty), - weapons = (Dict.empty), - armors = (Dict.empty), - tiles = (Dict.empty), - error = Nothing, - ui = (Struct.UI.default), - char_turn = (Struct.CharacterTurn.new), - timeline = (Array.empty) - } - -initialize_animator : Type -> Type -initialize_animator model = - let - timeline_list = (Array.toList model.timeline) - in - {model | - animator = - (Struct.TurnResultAnimator.maybe_new - (List.reverse timeline_list) - True - ), - ui = (Struct.UI.default), - characters = - (List.foldr - (Struct.TurnResult.apply_inverse_to_characters) - model.characters - timeline_list - ) - } - -move_animator_to_next_step : Type -> Type -move_animator_to_next_step model = - case model.animator of - Nothing -> model - (Just animator) -> - {model | - animator = - (Struct.TurnResultAnimator.maybe_trigger_next_step animator) - } - -apply_animator_step : Type -> Type -apply_animator_step model = - case model.animator of - Nothing -> model - (Just animator) -> - {model | - characters = - case - (Struct.TurnResultAnimator.get_current_animation animator) - of - (Struct.TurnResultAnimator.TurnResult turn_result) -> - (Struct.TurnResult.apply_step_to_characters - turn_result - model.characters - ) - - _ -> model.characters - } - -update_character : Int -> Struct.Character.Type -> Type -> Type -update_character ix new_val model = - {model | - characters = (Array.set ix new_val model.characters) - } - -update_character_fun : ( - Int -> - ((Maybe Struct.Character.Type) -> (Maybe Struct.Character.Type)) -> - Type -> - Type - ) -update_character_fun ix fun model = - {model | - characters = (Util.Array.update ix (fun) model.characters) + ) } invalidate : Struct.Error.Type -> Type -> Type diff --git a/src/map-editor/src/Struct/ServerReply.elm b/src/map-editor/src/Struct/ServerReply.elm index 5b88933..6f2da71 100644 --- a/src/map-editor/src/Struct/ServerReply.elm +++ b/src/map-editor/src/Struct/ServerReply.elm @@ -3,12 +3,8 @@ module Struct.ServerReply exposing (Type(..)) -- Elm ------------------------------------------------------------------------- -- Battlemap ------------------------------------------------------------------- -import Struct.Armor -import Struct.Battlemap -import Struct.Character +import Struct.Map import Struct.Tile -import Struct.TurnResult -import Struct.Weapon -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -16,13 +12,8 @@ import Struct.Weapon type Type = Okay - | AddArmor Struct.Armor.Type - | AddWeapon Struct.Weapon.Type - | AddCharacter (Struct.Character.Type, Int, Int, Int) | AddTile Struct.Tile.Type - | SetMap Struct.Battlemap.Type - | TurnResults (List Struct.TurnResult.Type) - | SetTimeline (List Struct.TurnResult.Type) + | SetMap Struct.Map.Type -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- diff --git a/src/map-editor/src/Struct/Toolbox.elm b/src/map-editor/src/Struct/Toolbox.elm new file mode 100644 index 0000000..81f7c2a --- /dev/null +++ b/src/map-editor/src/Struct/Toolbox.elm @@ -0,0 +1,15 @@ +module Struct.Toolbox exposing (Tool(..)) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Toolbox + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Tool = + Simple + | Select + | Fill + | Square diff --git a/src/map-editor/src/Struct/UI.elm b/src/map-editor/src/Struct/UI.elm index 447cfc4..aa83bd6 100644 --- a/src/map-editor/src/Struct/UI.elm +++ b/src/map-editor/src/Struct/UI.elm @@ -18,40 +18,30 @@ module Struct.UI exposing try_getting_displayed_nav, set_displayed_nav, reset_displayed_nav, - -- Manual Controls - has_manual_controls_enabled, -- Previous Action - has_focus, get_previous_action, set_previous_action ) -- Battlemap ------------------------------------------------------------------- import Struct.Location -import Struct.Navigator -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- type Tab = StatusTab - | CharactersTab + | TilesTab | SettingsTab - | TimelineTab type Action = - UsedManualControls - | SelectedLocation Struct.Location.Ref - | SelectedCharacter Int - | AttackedCharacter Int + SelectedLocation Struct.Location.Ref type alias Type = { zoom_level : Float, - show_manual_controls : Bool, displayed_tab : (Maybe Tab), - previous_action : (Maybe Action), - displayed_nav : (Maybe Struct.Navigator.Type) + previous_action : (Maybe Action) } -------------------------------------------------------------------------------- @@ -65,10 +55,8 @@ default : Type default = { zoom_level = 1.0, - show_manual_controls = True, displayed_tab = Nothing, - previous_action = Nothing, - displayed_nav = Nothing + previous_action = Nothing } -- Zoom ------------------------------------------------------------------------ @@ -95,43 +83,14 @@ to_string : Tab -> String to_string tab = case tab of StatusTab -> "Status" - CharactersTab -> "Characters" + TilesTab -> "Tiles" SettingsTab -> "Settings" - TimelineTab -> "Timeline" get_all_tabs : (List Tab) get_all_tabs = - [StatusTab, CharactersTab, SettingsTab, TimelineTab] - --- Navigator ------------------------------------------------------------------- -try_getting_displayed_nav : Type -> (Maybe Struct.Navigator.Type) -try_getting_displayed_nav ui = ui.displayed_nav - -set_displayed_nav : Struct.Navigator.Type -> Type -> Type -set_displayed_nav nav ui = {ui | displayed_nav = (Just nav)} - -reset_displayed_nav : Type -> Type -reset_displayed_nav ui = {ui | displayed_nav = Nothing} - --- ManualControls -------------------------------------------------------------- -has_manual_controls_enabled : Type -> Bool -has_manual_controls_enabled ui = ui.show_manual_controls - -toggle_manual_controls : Type -> Type -toggle_manual_controls ui = - if (ui.show_manual_controls) - then - {ui | show_manual_controls = False} - else - {ui | show_manual_controls = True} - -set_enable_manual_controls : Bool -> Type -> Type -set_enable_manual_controls val ui = {ui | show_manual_controls = val} + [StatusTab, TilesTab, SettingsTab] -- Previous Action ------------------------------------------------------------- -has_focus : Type -> Bool -has_focus ui = True - set_previous_action : (Maybe Action) -> Type -> Type set_previous_action act ui = {ui | previous_action = act} diff --git a/src/map-editor/src/Update/HandleServerReply.elm b/src/map-editor/src/Update/HandleServerReply.elm index bc347c9..8d5f07d 100644 --- a/src/map-editor/src/Update/HandleServerReply.elm +++ b/src/map-editor/src/Update/HandleServerReply.elm @@ -11,19 +11,14 @@ import Http import Time --- Battlemap ------------------------------------------------------------------- -import Struct.Armor -import Struct.Battlemap -import Struct.Character +-- Map ------------------------------------------------------------------- +import Struct.Map import Struct.Error import Struct.Event import Struct.Model import Struct.ServerReply import Struct.Tile -import Struct.TurnResult -import Struct.TurnResultAnimator import Struct.UI -import Struct.Weapon -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -32,30 +27,6 @@ import Struct.Weapon -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -weapon_getter : Struct.Model.Type -> Struct.Weapon.Ref -> Struct.Weapon.Type -weapon_getter model ref = - case (Dict.get ref model.weapons) of - (Just w) -> w - Nothing -> Struct.Weapon.none - -armor_getter : Struct.Model.Type -> Struct.Armor.Ref -> Struct.Armor.Type -armor_getter model ref = - case (Dict.get ref model.armors) of - (Just w) -> w - Nothing -> Struct.Armor.none - ------------ - -add_armor : ( - Struct.Armor.Type -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) - ) -add_armor ar current_state = - case current_state of - (_, (Just _)) -> current_state - (model, _) -> ((Struct.Model.add_armor ar model), Nothing) - add_tile : ( Struct.Tile.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -66,41 +37,8 @@ add_tile tl current_state = (_, (Just _)) -> current_state (model, _) -> ((Struct.Model.add_tile tl model), Nothing) -add_weapon : ( - Struct.Weapon.Type -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) - ) -add_weapon wp current_state = - case current_state of - (_, (Just _)) -> current_state - (model, _) -> ((Struct.Model.add_weapon wp model), Nothing) - -add_character : ( - (Struct.Character.Type, Int, Int, Int) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) - ) -add_character char_and_refs current_state = - case current_state of - (_, (Just _)) -> current_state - (model, _) -> - let - (char, awp_ref, swp_ref, ar_ref) = char_and_refs - awp = (weapon_getter model awp_ref) - swp = (weapon_getter model swp_ref) - ar = (armor_getter model ar_ref) - in - ( - (Struct.Model.add_character - (Struct.Character.fill_missing_equipment awp swp ar char) - model - ), - Nothing - ) - set_map : ( - Struct.Battlemap.Type -> + Struct.Map.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> (Struct.Model.Type, (Maybe Struct.Error.Type)) ) @@ -110,58 +48,11 @@ set_map map current_state = (model, _) -> ( {model | - battlemap = - (Struct.Battlemap.solve_tiles (Dict.values model.tiles) map) + map = (Struct.Map.solve_tiles (Dict.values model.tiles) map) }, Nothing ) -add_to_timeline : ( - (List Struct.TurnResult.Type) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) - ) -add_to_timeline turn_results current_state = - case current_state of - (_, (Just _)) -> current_state - - (model, _) -> - ( - {model | - animator = - (Struct.TurnResultAnimator.maybe_new - (List.reverse turn_results) - False - ), - timeline = - (Array.append - (Array.fromList turn_results) - model.timeline - ), - ui = - (Struct.UI.set_displayed_tab - Struct.UI.TimelineTab - model.ui - ) - }, - Nothing - ) - -set_timeline : ( - (List Struct.TurnResult.Type) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) -> - (Struct.Model.Type, (Maybe Struct.Error.Type)) - ) -set_timeline turn_results current_state = - case current_state of - (_, (Just _)) -> current_state - - (model, _) -> - ( - {model | timeline = (Array.fromList turn_results)}, - Nothing - ) - apply_command : ( Struct.ServerReply.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> @@ -169,27 +60,12 @@ apply_command : ( ) apply_command command current_state = case command of - (Struct.ServerReply.AddWeapon wp) -> - (add_weapon wp current_state) - - (Struct.ServerReply.AddArmor ar) -> - (add_armor ar current_state) - (Struct.ServerReply.AddTile tl) -> (add_tile tl current_state) - (Struct.ServerReply.AddCharacter char) -> - (add_character char current_state) - (Struct.ServerReply.SetMap map) -> (set_map map current_state) - (Struct.ServerReply.TurnResults results) -> - (add_to_timeline results current_state) - - (Struct.ServerReply.SetTimeline timeline) -> - (set_timeline timeline current_state) - Struct.ServerReply.Okay -> current_state -------------------------------------------------------------------------------- @@ -212,19 +88,6 @@ apply_to model query_result = ) (Result.Ok commands) -> - let - new_model = - ( - case (List.foldl (apply_command) (model, Nothing) commands) of - (updated_model, Nothing) -> updated_model - (_, (Just error)) -> (Struct.Model.invalidate error model) - ) - in - ( - new_model, - if (new_model.animator == Nothing) - then - Cmd.none - else - (Delay.after 1 Time.millisecond Struct.Event.AnimationEnded) - ) + case (List.foldl (apply_command) (model, Nothing) commands) of + (updated_model, Nothing) -> updated_model + (_, (Just error)) -> (Struct.Model.invalidate error model) diff --git a/src/map-editor/src/Update/SelectTile.elm b/src/map-editor/src/Update/SelectTile.elm index 6d05476..e6bb9fd 100644 --- a/src/map-editor/src/Update/SelectTile.elm +++ b/src/map-editor/src/Update/SelectTile.elm @@ -3,129 +3,15 @@ module Update.SelectTile exposing (apply_to) -- Elm ------------------------------------------------------------------------- -- Battlemap ------------------------------------------------------------------- -import Struct.CharacterTurn -import Struct.Direction import Struct.Error import Struct.Event import Struct.Location import Struct.Model -import Struct.Navigator import Struct.UI -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -try_autopiloting : ( - Struct.Direction.Type -> - (Maybe Struct.Navigator.Type) -> - (Maybe Struct.Navigator.Type) - ) -try_autopiloting dir maybe_nav = - case maybe_nav of - (Just navigator) -> - (Struct.Navigator.try_adding_step dir navigator) - - Nothing -> Nothing - -go_to_tile : ( - Struct.Model.Type -> - Struct.Navigator.Type -> - Struct.Location.Ref -> - (Struct.Model.Type, (Cmd Struct.Event.Type)) - ) -go_to_tile model navigator loc_ref = - if - ( - loc_ref - == - (Struct.Location.get_ref - (Struct.Navigator.get_current_location navigator) - ) - ) - then - -- We are already there. - if - ( - (Struct.UI.get_previous_action model.ui) - == - (Just (Struct.UI.SelectedLocation loc_ref)) - ) - then - -- And we just clicked on that tile. - ( - {model | - char_turn = - (Struct.CharacterTurn.lock_path model.char_turn) - }, - Cmd.none - ) - else - -- And we didn't just click on that tile. - ( - {model | - ui = - (Struct.UI.reset_displayed_nav - (Struct.UI.set_displayed_tab - Struct.UI.StatusTab - (Struct.UI.set_previous_action - (Just (Struct.UI.SelectedLocation loc_ref)) - model.ui - ) - ) - ) - }, - Cmd.none - ) - else - -- We have to try getting there. - case - (Struct.Navigator.try_getting_path_to - loc_ref - navigator - ) - of - (Just path) -> - case - (List.foldr - (try_autopiloting) - (Just (Struct.Navigator.clear_path navigator)) - path - ) - of - (Just new_navigator) -> - ( - {model | - char_turn = - (Struct.CharacterTurn.set_navigator - new_navigator - model.char_turn - ), - ui = - (Struct.UI.set_displayed_tab - Struct.UI.StatusTab - (Struct.UI.set_previous_action - (Just (Struct.UI.SelectedLocation loc_ref)) - model.ui - ) - ) - }, - Cmd.none - ) - - Nothing -> - ( - (Struct.Model.invalidate - (Struct.Error.new - Struct.Error.Programming - "SelectTile/Navigator: Could not follow own path." - ) - model - ), - Cmd.none - ) - - Nothing -> -- Clicked outside of the range indicator - ((Struct.Model.reset model), Cmd.none) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -136,23 +22,18 @@ apply_to : ( (Struct.Model.Type, (Cmd Struct.Event.Type)) ) apply_to model loc_ref = - case (Struct.CharacterTurn.try_getting_navigator model.char_turn) of - (Just navigator) -> - (go_to_tile model navigator loc_ref) - - _ -> - ( - {model | - ui = - (Struct.UI.reset_displayed_nav - (Struct.UI.set_displayed_tab - Struct.UI.StatusTab - (Struct.UI.set_previous_action - (Just (Struct.UI.SelectedLocation loc_ref)) - model.ui - ) - ) + ( + {model | + ui = + (Struct.UI.reset_displayed_nav + (Struct.UI.set_displayed_tab + Struct.UI.StatusTab + (Struct.UI.set_previous_action + (Just (Struct.UI.SelectedLocation loc_ref)) + model.ui ) - }, - Cmd.none - ) + ) + ) + }, + Cmd.none + ) |