| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2019-11-22 17:38:18 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2019-11-22 17:38:18 +0100 | 
| commit | 056513525e544d73ce8917739654c0ea0a437c2c (patch) | |
| tree | ea348195b6684381631de6153e6ab01474327ca6 | |
| parent | f6f7a84e71cc0affd7bfd2ea51a7e67202586836 (diff) | |
...
22 files changed, 588 insertions, 260 deletions
| diff --git a/src/battle/src/ElmModule/Update.elm b/src/battle/src/ElmModule/Update.elm index ccf3e12..437e921 100644 --- a/src/battle/src/ElmModule/Update.elm +++ b/src/battle/src/ElmModule/Update.elm @@ -20,7 +20,6 @@ import Update.SelectTab  import Update.SelectTile  import Update.SendLoadBattleRequest  import Update.SetRequestedHelp -import Update.SwitchTeam  import Update.SwitchWeapon  import Update.TestAnimation  import Update.UndoAction @@ -83,15 +82,9 @@ update event model =        (Struct.Event.TabSelected tab) ->           (Update.SelectTab.apply_to new_model tab) -      Struct.Event.DebugTeamSwitchRequest -> -         (Update.SwitchTeam.apply_to new_model) -        Struct.Event.DebugTestAnimation ->           (Update.TestAnimation.apply_to new_model) -      (Struct.Event.DebugLoadBattleRequest) -> -         (Update.SendLoadBattleRequest.apply_to new_model) -        (Struct.Event.ServerReplied result) ->           (Update.HandleServerReply.apply_to model result) diff --git a/src/battle/src/ElmModule/View.elm b/src/battle/src/ElmModule/View.elm index 243a98d..0471247 100644 --- a/src/battle/src/ElmModule/View.elm +++ b/src/battle/src/ElmModule/View.elm @@ -35,7 +35,7 @@ view model =           (Html.Lazy.lazy2              (View.Controlled.get_html)              model.char_turn -            model.player_ix +            model.battle.own_player_ix           ),           (Html.div              [ diff --git a/src/battle/src/Struct/Battle.elm b/src/battle/src/Struct/Battle.elm new file mode 100644 index 0000000..1798786 --- /dev/null +++ b/src/battle/src/Struct/Battle.elm @@ -0,0 +1,240 @@ +module Struct.Battle exposing +   ( +      Type, +      new, + +      add_character, +      get_character, +      set_character, +      update_character, +      get_characters, +      set_characters, + +      add_player, +      get_player, +      set_player, +      get_players, +      set_players, + +      get_timeline, +      set_timeline, + +      get_map, +      set_map, + +      get_id, + +      get_own_player_index, + +      tile_omnimods_fun +   ) + +-- Elm ------------------------------------------------------------------------- +import Array + +import Dict + +import Set + +-- Battle ---------------------------------------------------------------------- +import Battle.Struct.Omnimods + +-- Battle Map ------------------------------------------------------------------ +import BattleMap.Struct.Location +import BattleMap.Struct.Map +import BattleMap.Struct.Marker + +-- Local Module ---------------------------------------------------------------- +import Struct.Character +import Struct.TurnResult +import Struct.Player + +import Util.Array + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = +   { +      id : String, +      map : BattleMap.Struct.Map.Type, +      characters : (Array.Array Struct.Character.Type), +      players : (Array.Array Struct.Player.Type), +      timeline : (Array.Array Struct.TurnResult.Type), + +      -- Having this here is kind of a hack. +      own_player_ix : Int +   } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +-- TODO: move this elsewhere, this is too complicated a function for a module +-- that's not solely focused on attacks of opportunity. +regenerate_attack_of_opportunity_markers_of_char : ( +      Int -> +      Struct.Character.Type -> +      Type -> +      Type +   ) +regenerate_attack_of_opportunity_markers_of_char char_ix char battle = +   if ((Struct.Character.get_player_index char) == battle.own_player_ix) +   then battle +   else +      let +         marker_name = ("matk_c" ++ (String.fromInt char_ix)) +         map_without_this_marker = +            (BattleMap.Struct.Map.remove_marker marker_name battle.map) +      in +         case (Struct.Character.get_melee_attack_range char) of +            0 -> {battle | map = map_without_this_marker} +            attack_range -> +                  {battle | +                     map = +                        (BattleMap.Struct.Map.add_marker +                           marker_name +                           (BattleMap.Struct.Marker.new_melee_attack +                              char_ix +                              (BattleMap.Struct.Location.add_neighborhood_to_set +                                 (BattleMap.Struct.Map.get_width +                                    map_without_this_marker +                                 ) +                                 (BattleMap.Struct.Map.get_height +                                    map_without_this_marker +                                 ) +                                 attack_range +                                 (Struct.Character.get_location char) +                                 (Set.empty) +                              ) +                           ) +                           map_without_this_marker +                        ) +                  } + +regenerate_attack_of_opportunity_markers : Int -> Type -> Type +regenerate_attack_of_opportunity_markers char_ix battle = +   case (Array.get char_ix battle.characters) of +      Nothing -> battle +      (Just char) -> +         (regenerate_attack_of_opportunity_markers_of_char char_ix char battle) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +tile_omnimods_fun : ( +      BattleMap.Struct.DataSet.Type -> +      (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) +   ) +tile_omnimods_fun dataset battle = +   (\loc -> (BattleMap.Struct.Map.get_omnimods_at loc dataset battle.map)) + +new : Type +new = +   { +      id = "", +      map = (BattleMap.Struct.Map.empty), +      characters = (Array.empty), +      players = (Array.empty), +      timeline = (Array.empty), + +      own_player_ix = -1 +   } + +-------------------- +---- Characters ---- +-------------------- +add_character : Struct.Character.Type -> Type -> Type +add_character char battle = +   let characters = battle.characters in +      (regenerate_attack_of_opportunity_markers_of_char +         (Array.length characters) +         char +         {battle | characters = (Array.push char characters)} +      ) + +get_character : Int -> Type -> (Maybe Struct.Character.Type) +get_character ix battle = (Array.get ix battle.characters) + +set_character : Int -> Struct.Character.Type -> Type -> Type +set_character ix char battle = +   {battle | characters = (Array.set ix char battle.characters) } + +update_character : ( +      Int -> +      ((Maybe Struct.Character.Type) -> (Maybe Struct.Character.Type)) -> +      Type -> +      Type +   ) +update_character ix fun battle = +   {battle | characters = (Util.Array.update ix (fun) battle.characters) } + +get_characters : Type -> (Array.Array Struct.Character.Type) +get_characters battle = battle.characters + +set_characters : (Array.Array Struct.Character.Type) -> Type -> Type +set_characters chars battle = {battle | characters = chars} + +----------------- +---- Players ---- +----------------- +add_player : Struct.Flags.Type -> Struct.Player.Type -> Type -> Type +add_player flags pl battle = +   {battle | +      players = (Array.push pl battle.players) +      own_player_ix = +         if (Struct.Player.get_id == (Struct.Flags.get_player_id flags)) +         then (Array.size battle.players) +         else battle.own_player_ix +   } + +get_player : Int -> Type -> (Maybe Struct.Player.Type) +get_player ix battle = (Array.get ix battle.players) + +set_player : Int -> Struct.Player.Type -> Type -> Type +set_player ix pl battle = +   {battle | players = (Array.set ix pl battle.players) } + +update_player : ( +      Int -> +      ((Maybe Struct.Player.Type) -> (Maybe Struct.Player.Type)) -> +      Type -> +      Type +   ) +update_player ix fun battle = +   {battle | players = (Util.Array.update ix (fun) battle.players) } + +get_players : Type -> (Array.Array Struct.Player.Type) +get_players battle = battle.players + +set_players : (Array.Array Struct.Player.Type) -> Type -> Type +set_players pls battle = {battle | players = pls} + +------------------ +---- Timeline ---- +------------------ +get_timeline : Type -> (Array.Array Struct.TurnResult.Type) +get_timeline battle = battle.timeline + +set_timeline : (Array.Array Struct.TurnResult.Type) -> Type -> Type +set_timeline timeline battle = {battle | timeline = timeline} + +------------- +---- Map ---- +------------- +get_map : Type -> BattleMap.Struct.Map.Type +get_map battle = battle.map + +set_map : BattleMap.Struct.Map.Type -> Type -> Type +set_map map battle = {battle | map = map} + +------------ +---- ID ---- +------------ +get_id : Type -> String +get_id battle = battle.id + +-------------------------- +---- Own Player Index ---- +-------------------------- +get_own_player_index : Type -> Int +get_own_player_index battle = battle.own_player_ix diff --git a/src/battle/src/Struct/TurnResultAnimator.elm b/src/battle/src/Struct/TurnResultAnimator.elm index 9736c72..49acdb8 100644 --- a/src/battle/src/Struct/TurnResultAnimator.elm +++ b/src/battle/src/Struct/TurnResultAnimator.elm @@ -127,44 +127,47 @@ initialize_animator model =           players = players        } -move_animator_to_next_step : Type -> Type -move_animator_to_next_step model = -   case model.animator of -      Nothing -> model +move_animator_to_next_step : (Maybe Type) -> (Maybe Type) +move_animator_to_next_step maybe_animator = +   case maybe_animator of +      Nothing -> maybe_animator        (Just animator) -> -         case (Struct.TurnResultAnimator.maybe_trigger_next_step animator) of -            Nothing -> -               (Set.foldl -                  (regenerate_attack_of_opportunity_markers) -                  {model | animator = Nothing } -                  (Struct.TurnResultAnimator.get_animated_character_indices -                     animator -                  ) +         (Struct.TurnResultAnimator.maybe_trigger_next_step animator) + +--         case (Struct.TurnResultAnimator.maybe_trigger_next_step animator) of +--            Nothing -> +--               (Set.foldl +--                  (regenerate_attack_of_opportunity_markers) +--                  {model | animator = Nothing } +--                  (Struct.TurnResultAnimator.get_animated_character_indices +--                     animator +--                  ) +--               ) +-- +--            just_next_animator -> {model | animator = just_next_animator } + +apply_animator_step : ( +      BattleMap.Struct.DataSet.Type -> +      Battle.Struct.Type -> +      Battle.Struct.Type +   ) +apply_animator_step dataset animator battle = +   case (Struct.TurnResultAnimator.get_current_animation animator) of +      (Struct.TurnResultAnimator.TurnResult turn_result) -> +         let +            (characters, players) = +               (Struct.TurnResult.apply_step +                  (Struct.Battle.get_tile_omnimods_fun dataset battle) +                  turn_result +                  battle                 ) +         in +            (Struct.Battle.set_players +               players +               (Struct.Battle.set_characters characters battle) +            ) -            just_next_animator -> {model | animator = just_next_animator } - -apply_animator_step : Type -> Type -apply_animator_step model = -   case model.animator of -      Nothing -> model -      (Just animator) -> -         case (Struct.TurnResultAnimator.get_current_animation animator) of -            (Struct.TurnResultAnimator.TurnResult turn_result) -> -               let -                  (characters, players) = -                     (Struct.TurnResult.apply_step -                        (tile_omnimods_fun model) -                        turn_result -                        model.characters -                        model.players -                     ) -               in -                  {model | -                     characters = characters, -                     players = players -                  } -            _ -> model +      _ -> battle  --------------------------------------------------------------------------------  -- EXPORTED -------------------------------------------------------------------- diff --git a/src/battle/src/Update/DisplayCharacterInfo.elm b/src/battle/src/Update/DisplayCharacterInfo.elm index 46037fd..ed1c0ec 100644 --- a/src/battle/src/Update/DisplayCharacterInfo.elm +++ b/src/battle/src/Update/DisplayCharacterInfo.elm @@ -7,6 +7,7 @@ import Task  -- Local Module ----------------------------------------------------------------  import Action.Scroll +import Struct.Battle  import Struct.Character  import Struct.Event  import Struct.Model @@ -17,7 +18,7 @@ import Struct.UI  --------------------------------------------------------------------------------  scroll_to_char : Struct.Model.Type -> Int -> (Cmd Struct.Event.Type)  scroll_to_char model char_ix = -   case (Array.get char_ix model.characters) of +   case (Struct.Battle.get_character char_ix model.battle) of        (Just char) ->           (Task.attempt              (Struct.Event.attempted) diff --git a/src/battle/src/Update/EndTurn.elm b/src/battle/src/Update/EndTurn.elm index b226452..56231a8 100644 --- a/src/battle/src/Update/EndTurn.elm +++ b/src/battle/src/Update/EndTurn.elm @@ -33,7 +33,7 @@ make_it_so model char nav =        (Just cmd) ->           (              (Struct.Model.reset -               (Struct.Model.update_character_fun +               (Struct.Model.update_character                    (Struct.Character.get_index char)                    (maybe_disable_char)                    model diff --git a/src/battle/src/Update/HandleAnimationEnded.elm b/src/battle/src/Update/HandleAnimationEnded.elm index 72801ed..6bde87a 100644 --- a/src/battle/src/Update/HandleAnimationEnded.elm +++ b/src/battle/src/Update/HandleAnimationEnded.elm @@ -12,6 +12,7 @@ import Task  -- Local Module ----------------------------------------------------------------  import Action.Scroll +import Struct.Battle  import Struct.Character  import Struct.Event  import Struct.Model @@ -28,7 +29,7 @@ handle_char_focus : (        (Struct.Model.Type, (Cmd Struct.Event.Type))     )  handle_char_focus model animator char_index = -   case (Array.get char_index model.characters) of +   case (Struct.Battle.get_character char_index model.battle) of        (Just char) ->           if (Struct.TurnResultAnimator.waits_for_focus animator)           then @@ -123,5 +124,4 @@ apply_to model =     in        case new_model.animator of           Nothing -> (new_model, Cmd.none) -         (Just animator) -> -            (prepare_next_animation new_model animator) +         (Just animator) -> (prepare_next_animation new_model animator) diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm index f13118e..969358e 100644 --- a/src/battle/src/Update/HandleServerReply.elm +++ b/src/battle/src/Update/HandleServerReply.elm @@ -22,24 +22,28 @@ import Util.Http  -- Battle Characters -----------------------------------------------------------  import BattleCharacters.Struct.Armor +import BattleCharacters.Struct.DataSet  import BattleCharacters.Struct.Equipment  import BattleCharacters.Struct.Glyph  import BattleCharacters.Struct.GlyphBoard  import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Skill  import BattleCharacters.Struct.Weapon  -- Battle Map ------------------------------------------------------------------ +import BattleMap.Struct.DataSet  import BattleMap.Struct.Map  import BattleMap.Struct.Tile  -- Local Module ----------------------------------------------------------------  import Constants.IO -import Struct.Player +import Struct.Battle  import Struct.Character  import Struct.Error  import Struct.Event  import Struct.Model +import Struct.Player  import Struct.ServerReply  import Struct.TurnResult  import Struct.TurnResultAnimator @@ -84,7 +88,16 @@ add_armor : (     )  add_armor ar current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_armor ar model), cmds) +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_armor +                  ar +                  model.characters_dataset +               ) +         }, +         cmds +      )  add_portrait : (        BattleCharacters.Struct.Portrait.Type -> @@ -93,43 +106,103 @@ add_portrait : (     )  add_portrait pt current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_portrait pt model), cmds) +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_portrait +                  pt +                  model.characters_dataset +               ) +         }, +         cmds +      )  add_glyph_board : (        BattleCharacters.Struct.GlyphBoard.Type ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type)))     ) -add_glyph_board pt current_state = +add_glyph_board gb current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_glyph_board pt model), cmds) +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_glyph_board +                  gb +                  model.characters_dataset +               ) +         }, +         cmds +      )  add_glyph : (        BattleCharacters.Struct.Glyph.Type ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type)))     ) -add_glyph pt current_state = +add_glyph gl current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_glyph pt model), cmds) +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_glyph +                  gl +                  model.characters_dataset +               ) +         }, +         cmds +      ) -add_tile : ( -      BattleMap.Struct.Tile.Type -> +add_weapon : ( +      BattleCharacters.Struct.Weapon.Type ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type)))     ) -add_tile tl current_state = +add_weapon wp current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_tile tl model), cmds) +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_weapon +                  wp +                  model.characters_dataset +               ) +         }, +         cmds +      ) -add_weapon : ( -      BattleCharacters.Struct.Weapon.Type -> +add_skill : ( +      BattleCharacters.Struct.Skill.Type ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->        (Struct.Model.Type, (List (Cmd Struct.Event.Type)))     ) -add_weapon wp current_state = +add_skill sk current_state = +   let (model, cmds) = current_state in +      ( +         {model | +            characters_dataset = +               (BattleCharacters.Struct.DataSet.add_skill +                  sk +                  model.characters_dataset +               ) +         }, +         cmds +      ) + +add_tile : ( +      BattleMap.Struct.Tile.Type -> +      (Struct.Model.Type, (List (Cmd Struct.Event.Type))) -> +      (Struct.Model.Type, (List (Cmd Struct.Event.Type))) +   ) +add_tile tl current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_weapon wp model), cmds) +      ( +         {model | +            map_dataset = +               (BattleMap.Struct.DataSet.add_tile tl model.map_dataset) +         }, +         cmds +      )  add_player : (        Struct.Player.Type -> @@ -138,7 +211,12 @@ add_player : (     )  add_player pl current_state =     let (model, cmds) = current_state in -      ((Struct.Model.add_player pl model), cmds) +      ( +         {model | +            battle = (Struct.Battle.add_player model.flags pl model.battle) +         }, +         cmds +      )  add_character : (        Struct.Character.Unresolved -> @@ -148,20 +226,17 @@ add_character : (  add_character unresolved_char current_state =     let (model, cmds) = current_state in        ( -         (Struct.Model.add_character -            (Struct.Character.resolve -               (Struct.Model.tile_omnimods_fun model) -               (BattleCharacters.Struct.Equipment.resolve -                  (BattleCharacters.Struct.Weapon.find model.weapons) -                  (BattleCharacters.Struct.Armor.find model.armors) -                  (BattleCharacters.Struct.Portrait.find model.portraits) -                  (BattleCharacters.Struct.GlyphBoard.find model.glyph_boards) -                  (BattleCharacters.Struct.Glyph.find model.glyphs) +         {model | +            battle = +               (Struct.Battle.add_character +                  (Struct.Character.resolve +                     (Struct.Model.tile_omnimods_fun model) +                     model.characters_dataset +                     unresolved_char +                  ) +                  model.battle                 ) -               unresolved_char -            ) -            model -         ), +         },           cmds        ) @@ -174,7 +249,14 @@ set_map map current_state =     let (model, cmds) = current_state in        (           {model | -            map = (BattleMap.Struct.Map.solve_tiles model.tiles map) +            battle = +               (Struct.Battle.set_map +                  (BattleMap.Struct.Map.solve_tiles +                     model.map_dataset +                     (Struct.Battle.get_map model.battle) +                  ) +                  model.battle +               )           },           cmds        ) @@ -193,15 +275,18 @@ add_to_timeline turn_results current_state =                    (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 +               ), +            battle = +               (Struct.Battle.set_timeline +                  (Array.append +                     (Array.fromList turn_results) +                     (Struct.Battle.get_timeline model.battle) +                  ) +                  model.battle                 )           },           ( @@ -218,7 +303,13 @@ set_timeline : (  set_timeline turn_results current_state =     let (model, cmds) = current_state in        ( -         {model | timeline = (Array.fromList turn_results)}, +         {model | +            battle = +               (Struct.Battle.set_timeline +                  (Array.fromList turn_results) +                  model.battle +               ) +         },           cmds        ) @@ -240,6 +331,9 @@ apply_command command current_state =        (Struct.ServerReply.AddPortrait pt) ->           (add_portrait pt current_state) +      (Struct.ServerReply.AddSkill sk) -> +         (add_skill sk current_state) +        (Struct.ServerReply.AddGlyphBoard pt) ->           (add_glyph_board pt current_state) diff --git a/src/battle/src/Update/LookForCharacter.elm b/src/battle/src/Update/LookForCharacter.elm index 8e7efc7..1c2af0a 100644 --- a/src/battle/src/Update/LookForCharacter.elm +++ b/src/battle/src/Update/LookForCharacter.elm @@ -7,6 +7,7 @@ import Task  -- Local Module ----------------------------------------------------------------  import Action.Scroll +import Struct.Battle  import Struct.Character  import Struct.Event  import Struct.Model @@ -17,7 +18,7 @@ import Struct.UI  --------------------------------------------------------------------------------  scroll_to_char : Struct.Model.Type -> Int -> (Cmd Struct.Event.Type)  scroll_to_char model char_ix = -   case (Array.get char_ix model.characters) of +   case (Struct.Battle.get_character char_ix model.battle) of        (Just char) ->           (Task.attempt              (Struct.Event.attempted) diff --git a/src/battle/src/Update/SelectCharacter.elm b/src/battle/src/Update/SelectCharacter.elm index 9dfe73d..c18bb35 100644 --- a/src/battle/src/Update/SelectCharacter.elm +++ b/src/battle/src/Update/SelectCharacter.elm @@ -31,11 +31,11 @@ import Struct.UI  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  get_character_navigator : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.Character.Type ->        Struct.Navigator.Type     ) -get_character_navigator model char = +get_character_navigator battle char =     let        base_char = (Struct.Character.get_base_character char)        weapon = (BattleCharacters.Struct.Character.get_active_weapon base_char) @@ -48,10 +48,12 @@ get_character_navigator model char =           (BattleCharacters.Struct.Weapon.get_defense_range weapon)           (BattleCharacters.Struct.Weapon.get_attack_range weapon)           (BattleMap.Struct.Map.get_tile_data_function -            model.map +            (Struct.Battle.get_map battle)              (List.map                 (Struct.Character.get_location) -               (Array.toList model.characters) +               (Array.toList +                  (Struct.Battle.get_characters battle) +               )              )              (Struct.Character.get_location char)           ) @@ -92,7 +94,7 @@ ctrl_or_focus_character model target_char_id target_char =              (case (Struct.UI.try_getting_displayed_nav model.ui) of                 (Just dnav) -> dnav                 Nothing -> -                  (get_character_navigator model target_char) +                  (get_character_navigator model.battle target_char)              )        in           {model | @@ -117,7 +119,7 @@ ctrl_or_focus_character model target_char_id target_char =              (Struct.UI.set_previous_action                 (Just (Struct.UI.SelectedCharacter target_char_id))                 (Struct.UI.set_displayed_nav -                  (get_character_navigator model target_char) +                  (get_character_navigator model.battle target_char)                    model.ui                 )              ) @@ -162,7 +164,7 @@ second_click_on : (        (Struct.Model.Type, (Cmd Struct.Event.Type))     )  second_click_on model target_char_id = -   case (Array.get target_char_id model.characters) of +   case (Struct.Battle.get_character target_char_id model.battle) of        (Just target_char) ->           case              ( @@ -253,7 +255,7 @@ first_click_on model target_char_id =     then        (model, Cmd.none)     else -      case (Array.get target_char_id model.characters) of +      case (Struct.Battle.get_character target_char_id model.battle) of           (Just target_char) ->              (                 {model | @@ -263,7 +265,7 @@ first_click_on model target_char_id =                          (Struct.UI.set_displayed_tab                             Struct.UI.StatusTab                             (Struct.UI.set_displayed_nav -                              (get_character_navigator model target_char) +                              (get_character_navigator model.battle target_char)                                model.ui                             )                          ) @@ -299,7 +301,5 @@ apply_to model target_char_id =        ==        (Just (Struct.UI.SelectedCharacter target_char_id))     ) -   then -      (second_click_on model target_char_id) -   else -      (first_click_on model target_char_id) +   then (second_click_on model target_char_id) +   else (first_click_on model target_char_id) diff --git a/src/battle/src/Update/SelectCharacterOrTile.elm b/src/battle/src/Update/SelectCharacterOrTile.elm index 7c7994f..2135927 100644 --- a/src/battle/src/Update/SelectCharacterOrTile.elm +++ b/src/battle/src/Update/SelectCharacterOrTile.elm @@ -7,6 +7,7 @@ import Util.Array  import BattleMap.Struct.Location  -- Local Module ---------------------------------------------------------------- +import Struct.Battle  import Struct.Character  import Struct.Event  import Struct.Model @@ -39,7 +40,7 @@ apply_to model loc_ref =                 (Struct.Character.is_alive c)              )           ) -         model.characters +         (Struct.Battle.get_characters model.battle)        )     of        (Just char) -> diff --git a/src/battle/src/Update/SwitchTeam.elm b/src/battle/src/Update/SwitchTeam.elm deleted file mode 100644 index 85224ac..0000000 --- a/src/battle/src/Update/SwitchTeam.elm +++ /dev/null @@ -1,26 +0,0 @@ -module Update.SwitchTeam exposing (apply_to) - --- Local Module ---------------------------------------------------------------- -import Struct.Model -import Struct.Event - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) -apply_to model = -   if (model.player_ix == 0) -   then -      ( -         (Struct.Model.reset {model | player_id = "1", player_ix = 1}), -         Cmd.none -      ) -   else -      ( -         (Struct.Model.reset {model | player_id = "0", player_ix = 0}), -         Cmd.none -      ) diff --git a/src/battle/src/Update/UndoAction.elm b/src/battle/src/Update/UndoAction.elm index b171d6c..3941535 100644 --- a/src/battle/src/Update/UndoAction.elm +++ b/src/battle/src/Update/UndoAction.elm @@ -14,6 +14,7 @@ import BattleCharacters.Struct.Weapon  import BattleMap.Struct.Map  -- Local Module ---------------------------------------------------------------- +import Struct.Battle  import Struct.Character  import Struct.CharacterTurn  import Struct.Event @@ -24,11 +25,11 @@ import Struct.Navigator  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  get_character_navigator : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.Character.Type ->        Struct.Navigator.Type     ) -get_character_navigator model char = +get_character_navigator battle char =     let        base_char = (Struct.Character.get_base_character char)        weapon = (BattleCharacters.Struct.Character.get_active_weapon base_char) @@ -44,7 +45,7 @@ get_character_navigator model char =              model.map              (List.map                 (Struct.Character.get_location) -               (Array.toList model.characters) +               (Array.toList (Struct.Battle.get_characters battle))              )              (Struct.Character.get_location char)           ) @@ -57,16 +58,16 @@ handle_reset_character_turn model =        (Just current_char) ->           case -            (Array.get +            (Struct.Battle.get_character                 (Struct.Character.get_index current_char) -               model.characters +               model.battle              )           of              Nothing -> model.char_turn              (Just reset_char) ->                 (Struct.CharacterTurn.set_navigator -                  (get_character_navigator model reset_char) +                  (get_character_navigator model.battle reset_char)                    (Struct.CharacterTurn.set_active_character                       reset_char                       (Struct.CharacterTurn.new) @@ -98,14 +99,13 @@ handle_undo_switched_weapons model =  handle_undo_chose_target : Struct.Model.Type -> Struct.CharacterTurn.Type  handle_undo_chose_target model = -   let -      tile_omnimods = (Struct.Model.tile_omnimods_fun model) -   in -      (Struct.CharacterTurn.lock_path -         (Struct.CharacterTurn.unlock_path -            (Struct.CharacterTurn.set_target Nothing model.char_turn) -         ) -      ) +   (Struct.CharacterTurn.set_target Nothing model.char_turn +-- Was previously something like below, but that looks really wrong: +--   (Struct.CharacterTurn.lock_path +--      (Struct.CharacterTurn.unlock_path +--         model.char_turn +--      ) +--   )  --------------------------------------------------------------------------------  -- EXPORTED -------------------------------------------------------------------- diff --git a/src/battle/src/View/Controlled/Targets.elm b/src/battle/src/View/Controlled/Targets.elm index 3457731..7dd5636 100644 --- a/src/battle/src/View/Controlled/Targets.elm +++ b/src/battle/src/View/Controlled/Targets.elm @@ -10,21 +10,21 @@ import Html.Attributes  import Battle.Struct.Attributes  -- Local Module ---------------------------------------------------------------- +import Struct.Battle  import Struct.Character  import Struct.Event -import Struct.Model  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  get_target_info_html : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.Character.Ref ->        (Html.Html Struct.Event.Type)     ) -get_target_info_html model char_ref = -   case (Dict.get char_ref model.characters) of +get_target_info_html battle char_ref = +   case (Struct.Battle.get_character char_ref battle) of        Nothing -> (Html.text "Error: Unknown character selected.")        (Just char) ->           (Html.text @@ -61,14 +61,14 @@ get_target_info_html model char_ref =  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  get_html : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.Character.Ref ->        (Html.Html Struct.Event.Type)     ) -get_html model target_ref = +get_html battle target_ref =     (Html.div        [           (Html.Attributes.class "side-bar-targets")        ] -      [(get_target_info_html model target_ref)] +      [(get_target_info_html battle target_ref)]     ) diff --git a/src/battle/src/View/Map.elm b/src/battle/src/View/Map.elm index dc0c770..d95aa21 100644 --- a/src/battle/src/View/Map.elm +++ b/src/battle/src/View/Map.elm @@ -99,17 +99,16 @@ maybe_print_navigator interactive maybe_nav =  get_characters_html : (        Struct.Model.Type -> -      (Array.Array Struct.Character.Type) ->        (Html.Html Struct.Event.Type)     ) -get_characters_html model characters = +get_characters_html model =     (Html.div        [           (Html.Attributes.class "characters")        ]        (List.map           (View.Map.Character.get_html model) -         (Array.toList model.characters) +         (Array.toList (Struct.Battle.get_characters model.battle))        )     ) @@ -142,10 +141,8 @@ get_html model =           )        ]        [ -         (Html.Lazy.lazy (get_tiles_html) model.map), -         -- Not in lazy mode, because I can't easily get rid of that 'model' -         -- parameter. -         (get_characters_html model model.characters), +         (Html.Lazy.lazy (get_tiles_html) model.battle.map), +         (Html.Lazy.lazy (get_characters_html model)),           (Html.Lazy.lazy2              (maybe_print_navigator)              True @@ -154,7 +151,7 @@ get_html model =           (Html.Lazy.lazy2              (maybe_print_navigator)              False -            (Struct.UI.try_getting_displayed_nav model.ui) +            model.ui.displayed_nav           )        ]     ) diff --git a/src/battle/src/View/MessageBoard.elm b/src/battle/src/View/MessageBoard.elm index 082d2c9..9b31f65 100644 --- a/src/battle/src/View/MessageBoard.elm +++ b/src/battle/src/View/MessageBoard.elm @@ -25,6 +25,6 @@ get_html model =        Nothing ->           case model.animator of              (Just animator) -> -               (View.MessageBoard.Animator.get_html model animator) +               (View.MessageBoard.Animator.get_html model.battle animator)              Nothing -> (View.MessageBoard.Help.get_html model) diff --git a/src/battle/src/View/MessageBoard/Animator.elm b/src/battle/src/View/MessageBoard/Animator.elm index c653e5e..99ff190 100644 --- a/src/battle/src/View/MessageBoard/Animator.elm +++ b/src/battle/src/View/MessageBoard/Animator.elm @@ -7,8 +7,8 @@ import Html  import Util.Html  -- Local Module ---------------------------------------------------------------- +import Struct.Battle  import Struct.Event -import Struct.Model  import Struct.TurnResult  import Struct.TurnResultAnimator @@ -18,15 +18,15 @@ import View.MessageBoard.Animator.Attack  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  get_turn_result_html : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.TurnResult.Type ->        (Html.Html Struct.Event.Type)     ) -get_turn_result_html model turn_result = +get_turn_result_html battle turn_result =     case turn_result of        (Struct.TurnResult.Attacked attack) ->           (View.MessageBoard.Animator.Attack.get_html -            model +            battle              (Struct.TurnResult.get_actor_index turn_result)              (Struct.TurnResult.get_attack_defender_index attack)              (Struct.TurnResult.maybe_get_attack_next_step attack) @@ -38,18 +38,18 @@ get_turn_result_html model turn_result =  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  get_html : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Struct.TurnResultAnimator.Type ->        (Html.Html Struct.Event.Type)     ) -get_html model animator = +get_html battle animator =     case (Struct.TurnResultAnimator.get_current_animation animator) of        (Struct.TurnResultAnimator.TurnResult turn_result) -> -         (get_turn_result_html model turn_result) +         (get_turn_result_html battle turn_result)        (Struct.TurnResultAnimator.AttackSetup (attacker_id, defender_id)) ->           (View.MessageBoard.Animator.Attack.get_html -            model +            battle              attacker_id              defender_id              Nothing diff --git a/src/battle/src/View/MessageBoard/Animator/Attack.elm b/src/battle/src/View/MessageBoard/Animator/Attack.elm index 4378c5a..6b79903 100644 --- a/src/battle/src/View/MessageBoard/Animator/Attack.elm +++ b/src/battle/src/View/MessageBoard/Animator/Attack.elm @@ -11,9 +11,9 @@ import BattleCharacters.Struct.Character  -- Local Module ----------------------------------------------------------------  import Struct.Attack +import Struct.Battle  import Struct.Character  import Struct.Event -import Struct.Model  import View.Controlled.CharacterCard @@ -120,10 +120,8 @@ get_attack_animation_class : (     )  get_attack_animation_class attack char =     if (attack.critical) -   then -      "animated-portrait-attack-critical" -   else -      "animated-portrait-attacks" +   then "animated-portrait-attack-critical" +   else "animated-portrait-attacks"  get_defense_animation_class : (        Struct.Attack.Type -> @@ -134,23 +132,17 @@ get_defense_animation_class attack char =     if (attack.damage == 0)     then        if (attack.precision == Struct.Attack.Miss) -      then -         "animated-portrait-dodges" -      else -         "animated-portrait-undamaged" +      then "animated-portrait-dodges" +      else "animated-portrait-undamaged"     else if ((Struct.Character.get_current_health char) > 0)     then        if (attack.precision == Struct.Attack.Graze) -      then -         "animated-portrait-grazed-damage" -      else -         "animated-portrait-damaged" +      then "animated-portrait-grazed-damage" +      else "animated-portrait-damaged"     else        if (attack.precision == Struct.Attack.Graze) -      then -         "animated-portrait-grazed-death" -      else -         "animated-portrait-dies" +      then "animated-portrait-grazed-death" +      else "animated-portrait-dies"  get_attacker_card : (        (Maybe Struct.Attack.Type) -> @@ -297,11 +289,16 @@ get_placeholder_html characters attacker_ix defender_ix maybe_attack =  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  get_html : ( -      Struct.Model.Type -> +      Struct.Battle.Type ->        Int ->        Int ->        (Maybe Struct.Attack.Type) ->        (Html.Html Struct.Event.Type)     ) -get_html model attacker_ix defender_ix maybe_attack = -   (get_placeholder_html model.characters attacker_ix defender_ix maybe_attack) +get_html battle attacker_ix defender_ix maybe_attack = +   (get_placeholder_html +      (Struct.Battle.get_characters battle) +      attacker_ix +      defender_ix +      maybe_attack +   ) diff --git a/src/battle/src/View/SubMenu/Status.elm b/src/battle/src/View/SubMenu/Status.elm index b5d69f7..af5ace3 100644 --- a/src/battle/src/View/SubMenu/Status.elm +++ b/src/battle/src/View/SubMenu/Status.elm @@ -10,13 +10,15 @@ import Html.Lazy  -- Battle Map ------------------------------------------------------------------  import BattleMap.Struct.Location +import BattleMap.View.TileInfo +  -- Local Module ----------------------------------------------------------------  import Struct.Event  import Struct.Model  import Struct.UI  import View.SubMenu.Status.CharacterInfo -import View.SubMenu.Status.TileInfo +  --------------------------------------------------------------------------------  -- LOCAL -----------------------------------------------------------------------  -------------------------------------------------------------------------------- @@ -34,9 +36,11 @@ get_html model =        [           (case (Struct.UI.get_previous_action model.ui) of              (Just (Struct.UI.SelectedLocation loc)) -> -               (View.SubMenu.Status.TileInfo.get_html -                  model -                  (BattleMap.Struct.Location.from_ref loc) +               (Html.Lazy.lazy3 +                  (BattleMap.View.TileInfo.get_html) +                  model.map_dataset +                  loc +                  model.battle.map                 )              (Just (Struct.UI.SelectedCharacter target_char)) -> diff --git a/src/battle/src/View/SubMenu/Timeline.elm b/src/battle/src/View/SubMenu/Timeline.elm index 50c1ba3..7c081f4 100644 --- a/src/battle/src/View/SubMenu/Timeline.elm +++ b/src/battle/src/View/SubMenu/Timeline.elm @@ -8,6 +8,7 @@ import Html.Attributes  import Html.Lazy  -- Local Module ---------------------------------------------------------------- +import Struct.Battle  import Struct.Character  import Struct.Event  import Struct.TurnResult @@ -61,13 +62,8 @@ get_turn_result_html characters player_ix turn_result =        (Struct.TurnResult.PlayerTurnStarted pturns) ->           (View.SubMenu.Timeline.PlayerTurnStart.get_html pturns) -true_get_html : ( -      (Array.Array Struct.Character.Type) -> -      Int -> -      (Array.Array Struct.TurnResult.Type) -> -      (Html.Html Struct.Event.Type) -   ) -true_get_html characters player_ix turn_results = +true_get_html : Struct.Battle.Type -> (Html.Html Struct.Event.Type) +true_get_html battle =     (Html.div        [           (Html.Attributes.class "tabmenu-content"), @@ -75,8 +71,11 @@ true_get_html characters player_ix turn_results =        ]        (Array.toList           (Array.map -            (get_turn_result_html characters player_ix) -            turn_results +            (get_turn_result_html +               (Struct.Battle.get_characters battle) +               (Struct.Battle.get_own_player_index battle) +            ) +            (Struct.Battle.get_turn_results battle)           )        )     ) @@ -86,9 +85,4 @@ true_get_html characters player_ix turn_results =  --------------------------------------------------------------------------------  get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)  get_html model = -   (Html.Lazy.lazy3 -      (true_get_html) -      model.characters -      model.player_ix -      model.timeline -   ) +   (Html.Lazy.lazy (true_get_html) model.battle) diff --git a/src/shared/battle-characters/BattleCharacters/Comm/AddSkill.elm b/src/shared/battle-characters/BattleCharacters/Comm/AddSkill.elm new file mode 100644 index 0000000..d132050 --- /dev/null +++ b/src/shared/battle-characters/BattleCharacters/Comm/AddSkill.elm @@ -0,0 +1,30 @@ +module BattleCharacters.Comm.AddSkill exposing (decode) + +-- Elm ------------------------------------------------------------------------- +import Json.Decode + +-- Battle Characters ----------------------------------------------------------- +import BattleCharacters.Struct.Skill + +-- Local Module ---------------------------------------------------------------- +import Struct.ServerReply + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +internal_decoder : BattleCharacters.Struct.Skill.Type -> Struct.ServerReply.Type +internal_decoder sk = (Struct.ServerReply.AddSkill sk) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +decode : (Json.Decode.Decoder Struct.ServerReply.Type) +decode = +   (Json.Decode.map +      (internal_decoder) +      (BattleCharacters.Struct.Skill.decoder) +   ) diff --git a/src/battle/src/View/SubMenu/Status/TileInfo.elm b/src/shared/battle-map/BattleMap/View/TileInfo.elm index ff983b2..0dc57ff 100644 --- a/src/battle/src/View/SubMenu/Status/TileInfo.elm +++ b/src/shared/battle-map/BattleMap/View/TileInfo.elm @@ -1,4 +1,4 @@ -module View.SubMenu.Status.TileInfo exposing (get_html) +module BattleMap.View.TileInfo exposing (get_html)  -- Elm -------------------------------------------------------------------------  import Dict @@ -32,7 +32,7 @@ import Struct.Model  -- LOCAL -----------------------------------------------------------------------  --------------------------------------------------------------------------------  get_icon : (BattleMap.Struct.TileInstance.Type -> (Html.Html Struct.Event.Type)) -get_icon tile = +get_icon tile_instance =     (Html.div        [           (Html.Attributes.class "tile-card-icon"), @@ -42,38 +42,30 @@ get_icon tile =                 "tile-variant-"                 ++                 (String.fromInt -                  (BattleMap.Struct.TileInstance.get_local_variant_ix tile) +                  (BattleMap.Struct.TileInstance.get_local_variant_ix +                     tile_instance +                  )                 )              )           )        ] -      (BattleMap.View.Tile.get_content_html tile) +      (BattleMap.View.Tile.get_content_html tile_instance)     ) -get_name : ( -      Struct.Model.Type -> -      BattleMap.Struct.TileInstance.Type -> -      (Html.Html Struct.Event.Type) -   ) -get_name model tile_inst = -   case -      (Dict.get -         (BattleMap.Struct.TileInstance.get_class_id tile_inst) -         model.tiles -      ) -   of -      Nothing -> (Util.Html.nothing) -      (Just tile) -> -         (Html.div -            [ -               (Html.Attributes.class "info-card-name"), -               (Html.Attributes.class "info-card-text-field"), -               (Html.Attributes.class "tile-card-name") -            ] -            [ -               (Html.text (BattleMap.Struct.Tile.get_name tile)) -            ] +get_name : BattleMap.Struct.Tile.Type -> (Html.Html Struct.Event.Type) +get_name tile = +   (Html.div +      [ +         (Html.Attributes.class "info-card-name"), +         (Html.Attributes.class "info-card-text-field"), +         (Html.Attributes.class "tile-card-name") +      ] +      [ +         (Html.text +            (BattleMap.Struct.Tile.get_name tile)           ) +      ] +   )  get_cost : BattleMap.Struct.TileInstance.Type -> (Html.Html Struct.Event.Type)  get_cost tile_inst = @@ -81,10 +73,8 @@ get_cost tile_inst =        cost = (BattleMap.Struct.TileInstance.get_cost tile_inst)        text =           if (cost > Constants.Movement.max_points) -         then -            "Obstructed" -         else -            ("Cost: " ++ (String.fromInt cost)) +         then "Obstructed" +         else ("Cost: " ++ (String.fromInt cost))     in        (Html.div           [ @@ -96,11 +86,12 @@ get_cost tile_inst =           ]        ) -get_location : BattleMap.Struct.TileInstance.Type -> (Html.Html Struct.Event.Type) +get_location : ( +      BattleMap.Struct.TileInstance.Type -> +      (Html.Html Struct.Event.Type) +   )  get_location tile_inst = -   let -      tile_location = (BattleMap.Struct.TileInstance.get_location tile_inst) -   in +   let tile_location = (BattleMap.Struct.TileInstance.get_location tile_inst) in        (Html.div           [              (Html.Attributes.class "info-card-text-field"), @@ -123,35 +114,43 @@ get_location tile_inst =  -- EXPORTED --------------------------------------------------------------------  --------------------------------------------------------------------------------  get_html : ( -      Struct.Model.Type -> -      BattleMap.Struct.Location.Type -> +      BattleMap.Struct.DataSet.Type -> +      BattleMap.Struct.Location.Ref -> +      BattleMap.Struct.Map.Type ->        (Html.Html Struct.Event.Type)     ) -get_html model loc = -   case (BattleMap.Struct.Map.try_getting_tile_at loc model.map) of -      (Just tile) -> -         (Html.div -            [ -               (Html.Attributes.class "info-card"), -               (Html.Attributes.class "tile-card") -            ] -            [ -               (get_name model tile), +get_html dataset loc_ref map = +   let loc = (BattleMap.Struct.Location.from_ref loc_ref) in +      case (BattleMap.Struct.Map.try_getting_tile_at loc map) of +         (Just tile_instance) -> +            let +               tile_data = +                  (BattleMap.Struct.DataSet.get_tile +                     (BattleMap.Struct.TileInstance.get_class_id tile_instance) +                  ) +            in                 (Html.div                    [ -                     (Html.Attributes.class "info-card-top"), -                     (Html.Attributes.class "tile-card-top") +                     (Html.Attributes.class "info-card"), +                     (Html.Attributes.class "tile-card")                    ]                    [ -                     (get_icon tile), -                     (get_location tile), -                     (get_cost tile) +                     (get_name dataset tile_data), +                     (Html.div +                        [ +                           (Html.Attributes.class "info-card-top"), +                           (Html.Attributes.class "tile-card-top") +                        ] +                        [ +                           (get_icon tile_instance), +                           (get_location tile_instance), +                           (get_cost tile_instance) +                        ] +                     ), +                     (Battle.View.Omnimods.get_signed_html +                        (BattleMap.Struct.Tile.get_omnimods tile_data) +                     )                    ] -               ), -               (Battle.View.Omnimods.get_signed_html -                  ((Struct.Model.tile_omnimods_fun model) loc)                 ) -            ] -         ) -      Nothing -> (Html.text "Error: Unknown tile location selected.") +         Nothing -> (Html.text "Error: Unknown tile location selected.") | 


