summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2019-11-20 18:35:01 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2019-11-20 18:35:01 +0100 |
commit | f6f7a84e71cc0affd7bfd2ea51a7e67202586836 (patch) | |
tree | 10276cc32eca2e100a11e493909bd5b98eac96b7 /src | |
parent | 6375ecebd314a070b0514e70fd31dc9e3002dfe5 (diff) |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/battle/src/Comm/CharacterTurn.elm | 25 | ||||
-rw-r--r-- | src/battle/src/Comm/LoadBattle.elm | 25 | ||||
-rw-r--r-- | src/battle/src/Comm/Send.elm | 17 | ||||
-rw-r--r-- | src/battle/src/Struct/Model.elm | 391 | ||||
-rw-r--r-- | src/battle/src/Struct/ServerReply.elm | 2 | ||||
-rw-r--r-- | src/battle/src/Struct/TurnResultAnimator.elm | 68 | ||||
-rw-r--r-- | src/battle/src/View/Character.elm | 13 | ||||
-rw-r--r-- | src/battle/src/View/Map/Character.elm | 14 | ||||
-rw-r--r-- | src/battle/src/View/SubMenu.elm | 13 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Inventory.elm | 54 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Model.elm | 19 | ||||
-rw-r--r-- | src/shared/battle-characters/BattleCharacters/Struct/DataSet.elm (renamed from src/shared/battle-characters/BattleCharacters/Struct/Inventory.elm) | 112 | ||||
-rw-r--r-- | src/shared/battle-map/BattleMap/Struct/DataSet.elm | 67 | ||||
-rw-r--r-- | src/shared/elm/Struct/Flags.elm | 10 |
14 files changed, 338 insertions, 492 deletions
diff --git a/src/battle/src/Comm/CharacterTurn.elm b/src/battle/src/Comm/CharacterTurn.elm index 6e3612f..9fd77d1 100644 --- a/src/battle/src/Comm/CharacterTurn.elm +++ b/src/battle/src/Comm/CharacterTurn.elm @@ -3,11 +3,15 @@ module Comm.CharacterTurn exposing (try) -- Elm ------------------------------------------------------------------------- import Json.Encode +-- Shared ---------------------------------------------------------------------- +import Struct.Flags + -- Local Module ---------------------------------------------------------------- import Constants.IO import Comm.Send +import Struct.Battle import Struct.Character import Struct.CharacterTurn import Struct.Event @@ -27,9 +31,24 @@ try_encoding model = (Just (Json.Encode.object [ - ("stk", (Json.Encode.string model.session_token)), - ("pid", (Json.Encode.string model.player_id)), - ("bid", (Json.Encode.string model.battle_id)), + ( + "stk", + (Json.Encode.string + (Struct.Flags.get_session_token model.flags) + ) + ), + ( + "pid", + (Json.Encode.string + (Struct.Flags.get_user_id model.flags) + ) + ), + ( + "bid", + (Json.Encode.string + (Struct.Battle.get_id model.battle) + ) + ), ( "cix", (Json.Encode.int (Struct.Character.get_index char)) diff --git a/src/battle/src/Comm/LoadBattle.elm b/src/battle/src/Comm/LoadBattle.elm index 78a337f..9099f1e 100644 --- a/src/battle/src/Comm/LoadBattle.elm +++ b/src/battle/src/Comm/LoadBattle.elm @@ -3,11 +3,15 @@ module Comm.LoadBattle exposing (try) -- Elm ------------------------------------------------------------------------- import Json.Encode +-- Shared ---------------------------------------------------------------------- +import Struct.Flags + -- Local Module ---------------------------------------------------------------- import Comm.Send import Constants.IO +import Struct.Battle import Struct.Event import Struct.Model @@ -23,9 +27,24 @@ try_encoding model = (Just (Json.Encode.object [ - ("stk", (Json.Encode.string model.session_token)), - ("pid", (Json.Encode.string model.player_id)), - ("bid", (Json.Encode.string model.battle_id)) + ( + "stk", + (Json.Encode.string + (Struct.Flags.get_session_token model.flags) + ) + ), + ( + "pid", + (Json.Encode.string + (Struct.Flags.get_user_id model.flags) + ) + ), + ( + "bid", + (Json.Encode.string + (Struct.Battle.get_id model.battle) + ) + ) ] ) ) diff --git a/src/battle/src/Comm/Send.elm b/src/battle/src/Comm/Send.elm index faac297..009b57e 100644 --- a/src/battle/src/Comm/Send.elm +++ b/src/battle/src/Comm/Send.elm @@ -11,6 +11,7 @@ import BattleCharacters.Comm.AddArmor import BattleCharacters.Comm.AddGlyph import BattleCharacters.Comm.AddGlyphBoard import BattleCharacters.Comm.AddPortrait +import BattleCharacters.Comm.AddSkill import BattleCharacters.Comm.AddWeapon -- Battle Map ------------------------------------------------------------------ @@ -38,16 +39,20 @@ internal_decoder : String -> (Json.Decode.Decoder Struct.ServerReply.Type) internal_decoder reply_type = case reply_type of "add_tile" -> (BattleMap.Comm.AddTile.decode) + "set_map" -> (BattleMap.Comm.SetMap.decode) + "add_armor" -> (BattleCharacters.Comm.AddArmor.decode) - "add_char" -> (Comm.AddChar.decode) - "add_portrait" -> (BattleCharacters.Comm.AddPortrait.decode) - "add_glyph_board" -> (BattleCharacters.Comm.AddGlyphBoard.decode) "add_glyph" -> (BattleCharacters.Comm.AddGlyph.decode) - "add_player" -> (Comm.AddPlayer.decode) + "add_glyph_board" -> (BattleCharacters.Comm.AddGlyphBoard.decode) + "add_portrait" -> (BattleCharacters.Comm.AddPortrait.decode) + "add_skill" -> (BattleCharacters.Comm.AddSkill.decode) "add_weapon" -> (BattleCharacters.Comm.AddWeapon.decode) - "set_map" -> (BattleMap.Comm.SetMap.decode) - "turn_results" -> (Comm.TurnResults.decode) + + "add_char" -> (Comm.AddChar.decode) + "add_player" -> (Comm.AddPlayer.decode) "set_timeline" -> (Comm.SetTimeline.decode) + "turn_results" -> (Comm.TurnResults.decode) + "disconnected" -> (Json.Decode.succeed Struct.ServerReply.Disconnected) "okay" -> (Json.Decode.succeed Struct.ServerReply.Okay) diff --git a/src/battle/src/Struct/Model.elm b/src/battle/src/Struct/Model.elm index 314a7a5..e23cd9e 100644 --- a/src/battle/src/Struct/Model.elm +++ b/src/battle/src/Struct/Model.elm @@ -2,67 +2,28 @@ module Struct.Model exposing ( Type, new, - add_character, - update_character, - update_character_fun, - add_weapon, - add_armor, - add_portrait, - add_glyph_board, - add_glyph, - add_skill, - add_player, - add_tile, invalidate, - initialize_animator, - apply_animator_step, - move_animator_to_next_step, - reset, - full_debug_reset, - clear_error, - tile_omnimods_fun + clear, + clear_error ) --- Elm ------------------------------------------------------------------------- -import Array - -import Dict - -import Set - -- Shared ---------------------------------------------------------------------- import Struct.Flags --- Battle ---------------------------------------------------------------------- -import Battle.Struct.Omnimods - -- Battle Characters ----------------------------------------------------------- -import BattleCharacters.Struct.Armor -import BattleCharacters.Struct.Character -import BattleCharacters.Struct.Glyph -import BattleCharacters.Struct.GlyphBoard -import BattleCharacters.Struct.Portrait -import BattleCharacters.Struct.Skill -import BattleCharacters.Struct.Weapon +import BattleCharacters.Struct.DataSet -- Battle Map ------------------------------------------------------------------ -import BattleMap.Struct.Location -import BattleMap.Struct.Map -import BattleMap.Struct.Marker -import BattleMap.Struct.Tile +import BattleMap.Struct.DataSet -- Local Module ---------------------------------------------------------------- -import Struct.Character import Struct.CharacterTurn import Struct.Error import Struct.HelpRequest import Struct.TurnResult import Struct.TurnResultAnimator -import Struct.Player import Struct.UI -import Util.Array - -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -71,142 +32,40 @@ type alias Type = flags : Struct.Flags.Type, help_request : Struct.HelpRequest.Type, animator : (Maybe Struct.TurnResultAnimator.Type), - map : BattleMap.Struct.Map.Type, - characters : (Array.Array Struct.Character.Type), - players : (Array.Array Struct.Player.Type), - weapons : - (Dict.Dict - BattleCharacters.Struct.Weapon.Ref - BattleCharacters.Struct.Weapon.Type - ), - armors : - (Dict.Dict - BattleCharacters.Struct.Armor.Ref - BattleCharacters.Struct.Armor.Type - ), - portraits : - (Dict.Dict - BattleCharacters.Struct.Portrait.Ref - BattleCharacters.Struct.Portrait.Type - ), - glyph_boards : - (Dict.Dict - BattleCharacters.Struct.GlyphBoard.Ref - BattleCharacters.Struct.GlyphBoard.Type - ), - glyphs : - (Dict.Dict - BattleCharacters.Struct.Glyph.Ref - BattleCharacters.Struct.Glyph.Type - ), - skills : - (Dict.Dict - BattleCharacters.Struct.Skill.Ref - BattleCharacters.Struct.Skill.Type - ), - tiles : (Dict.Dict BattleMap.Struct.Tile.Ref BattleMap.Struct.Tile.Type), - error : (Maybe Struct.Error.Type), - player_id : String, - battle_id : String, - session_token : String, - player_ix : Int, ui : Struct.UI.Type, char_turn : Struct.CharacterTurn.Type, - timeline : (Array.Array Struct.TurnResult.Type) + error : (Maybe Struct.Error.Type), + + battle : Struct.Battle.Type, + + -- Data Sets ------------------------------------------------------------- + characters_data_set : BattleCharacters.Struct.DataSet.Type, + map_data_set : BattleMap.Struct.DataSet.Type } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -regenerate_attack_of_opportunity_markers_of_char : ( - Int -> - Struct.Character.Type -> - Type -> - Type - ) -regenerate_attack_of_opportunity_markers_of_char char_ix char model = - if ((Struct.Character.get_player_index char) == model.player_ix) - then model - else - let - marker_name = ("matk_c" ++ (String.fromInt char_ix)) - map_without_this_marker = - (BattleMap.Struct.Map.remove_marker marker_name model.map) - in - case (Struct.Character.get_melee_attack_range char) of - 0 -> {model | map = map_without_this_marker} - attack_range -> - {model | - 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 model = - case (Array.get char_ix model.characters) of - Nothing -> model - (Just char) -> - (regenerate_attack_of_opportunity_markers_of_char char_ix char model) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -tile_omnimods_fun : ( - Type -> - (BattleMap.Struct.Location.Type -> Battle.Struct.Omnimods.Type) - ) -tile_omnimods_fun model = - (\loc -> (BattleMap.Struct.Map.get_omnimods_at loc model.tiles model.map)) - new : Struct.Flags.Type -> Type new flags = - let - maybe_battle_id = (Struct.Flags.maybe_get_param "id" flags) + let maybe_battle_id = model = { flags = flags, help_request = Struct.HelpRequest.None, animator = Nothing, - map = (BattleMap.Struct.Map.empty), - characters = (Array.empty), - weapons = (Dict.empty), - armors = (Dict.empty), - portraits = (Dict.empty), - glyph_boards = (Dict.empty), - glyphs = (Dict.empty), - skills = (Dict.empty), - tiles = (Dict.empty), - players = (Array.empty), - error = Nothing, - battle_id = "", - player_id = - ( - if (flags.user_id == "") - then "0" - else flags.user_id - ), - session_token = flags.token, - player_ix = 0, ui = (Struct.UI.default), char_turn = (Struct.CharacterTurn.new), - timeline = (Array.empty) + error = Nothing, + + characters_data_set = (BattleCharacters.Struct.DataSet.new), + map_data_set = (BattleMap.Struct.DataSet.new), + + battle = (Struct.Battle.new) } in case maybe_battle_id of @@ -219,110 +78,13 @@ new flags = model ) - (Just id) -> {model | battle_id = id} - -add_character : Struct.Character.Type -> Type -> Type -add_character char model = - let characters = model.characters in - (regenerate_attack_of_opportunity_markers_of_char - (Array.length characters) - char - {model | characters = (Array.push char characters)} - ) - -add_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type -add_weapon wp model = - {model | - weapons = - (Dict.insert - (BattleCharacters.Struct.Weapon.get_id wp) - wp - model.weapons - ) - } + (Just id) -> + {model | + battle = (Struct.Battle.set_battle_id id model.battle) + } -add_armor : BattleCharacters.Struct.Armor.Type -> Type -> Type -add_armor ar model = - {model | - armors = - (Dict.insert - (BattleCharacters.Struct.Armor.get_id ar) - ar - model.armors - ) - } - -add_portrait : BattleCharacters.Struct.Portrait.Type -> Type -> Type -add_portrait pt model = - {model | - portraits = - (Dict.insert - (BattleCharacters.Struct.Portrait.get_id pt) - pt - model.portraits - ) - } - -add_glyph_board : BattleCharacters.Struct.GlyphBoard.Type -> Type -> Type -add_glyph_board pt model = - {model | - glyph_boards = - (Dict.insert - (BattleCharacters.Struct.GlyphBoard.get_id pt) - pt - model.glyph_boards - ) - } - -add_glyph : BattleCharacters.Struct.Glyph.Type -> Type -> Type -add_glyph pt model = - {model | - glyphs = - (Dict.insert - (BattleCharacters.Struct.Glyph.get_id pt) - pt - model.glyphs - ) - } - -add_skill : BattleCharacters.Struct.Skill.Type -> Type -> Type -add_skill sk model = - {model | - skills = - (Dict.insert - (BattleCharacters.Struct.Skill.get_id sk) - sk - model.skills - ) - } - -add_player : Struct.Player.Type -> Type -> Type -add_player pl model = - {model | - players = - (Array.push - pl - model.players - ), - player_ix = - if ((Struct.Player.get_id pl) == model.player_id) - then (Struct.Player.get_index pl) - else model.player_ix - } - -add_tile : BattleMap.Struct.Tile.Type -> Type -> Type -add_tile tl model = - {model | - tiles = - (Dict.insert - (BattleMap.Struct.Tile.get_id tl) - tl - model.tiles - ) - } - -reset : Type -> Type -reset model = +clear : Type -> Type +clear model = {model | help_request = Struct.HelpRequest.None, error = Nothing, @@ -333,111 +95,6 @@ reset model = char_turn = (Struct.CharacterTurn.new) } -full_debug_reset : Type -> Type -full_debug_reset model = - {model | - help_request = Struct.HelpRequest.None, - animator = Nothing, - map = (BattleMap.Struct.Map.empty), - characters = (Array.empty), - weapons = (Dict.empty), - armors = (Dict.empty), - portraits = (Dict.empty), - glyph_boards = (Dict.empty), - glyphs = (Dict.empty), - skills = (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) - (characters, players) = - (List.foldr - (\event (pcharacters, pplayers) -> - (Struct.TurnResult.apply_inverse_step - (tile_omnimods_fun model) - event - pcharacters - pplayers - ) - ) - (model.characters, model.players) - timeline_list - ) - in - {model | - animator = - (Struct.TurnResultAnimator.maybe_new - (List.reverse timeline_list) - True - ), - ui = (Struct.UI.default), - characters = characters, - players = players - } - -move_animator_to_next_step : Type -> Type -move_animator_to_next_step model = - case model.animator of - Nothing -> model - (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 - ) - ) - - 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 - -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 invalidate err model = {model | diff --git a/src/battle/src/Struct/ServerReply.elm b/src/battle/src/Struct/ServerReply.elm index f02f791..d059c17 100644 --- a/src/battle/src/Struct/ServerReply.elm +++ b/src/battle/src/Struct/ServerReply.elm @@ -5,6 +5,7 @@ import BattleCharacters.Struct.Armor import BattleCharacters.Struct.Glyph import BattleCharacters.Struct.GlyphBoard import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Skill import BattleCharacters.Struct.Weapon -- Battle Map ------------------------------------------------------------------ @@ -26,6 +27,7 @@ type Type = | AddPortrait BattleCharacters.Struct.Portrait.Type | AddGlyphBoard BattleCharacters.Struct.GlyphBoard.Type | AddGlyph BattleCharacters.Struct.Glyph.Type + | AddSkill BattleCharacters.Struct.Skill.Type | AddPlayer Struct.Player.Type | AddWeapon BattleCharacters.Struct.Weapon.Type | AddCharacter Struct.Character.Unresolved diff --git a/src/battle/src/Struct/TurnResultAnimator.elm b/src/battle/src/Struct/TurnResultAnimator.elm index d4445f7..9736c72 100644 --- a/src/battle/src/Struct/TurnResultAnimator.elm +++ b/src/battle/src/Struct/TurnResultAnimator.elm @@ -98,6 +98,74 @@ maybe_go_to_next_animation tra = (_, _) -> Nothing +initialize_animator : Type -> Type +initialize_animator model = + let + timeline_list = (Array.toList model.timeline) + (characters, players) = + (List.foldr + (\event (pcharacters, pplayers) -> + (Struct.TurnResult.apply_inverse_step + (tile_omnimods_fun model) + event + pcharacters + pplayers + ) + ) + (model.characters, model.players) + timeline_list + ) + in + {model | + animator = + (Struct.TurnResultAnimator.maybe_new + (List.reverse timeline_list) + True + ), + ui = (Struct.UI.default), + characters = characters, + players = players + } + +move_animator_to_next_step : Type -> Type +move_animator_to_next_step model = + case model.animator of + Nothing -> model + (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 + ) + ) + + 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 + -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- diff --git a/src/battle/src/View/Character.elm b/src/battle/src/View/Character.elm index c5082c9..dc256c6 100644 --- a/src/battle/src/View/Character.elm +++ b/src/battle/src/View/Character.elm @@ -48,11 +48,14 @@ get_alliance_class : ( (Html.Attribute Struct.Event.Type) ) get_alliance_class model char = - if ((Struct.Character.get_player_index char) == model.player_ix) - then - (Html.Attributes.class "character-ally") - else - (Html.Attributes.class "character-enemy") + if + ( + (Struct.Character.get_player_index char) == model.player_i + == + (Struct.Battle.get_own_player_index model.battle) + ) + then (Html.Attributes.class "character-ally") + else (Html.Attributes.class "character-enemy") get_position_style : ( Struct.Character.Type -> diff --git a/src/battle/src/View/Map/Character.elm b/src/battle/src/View/Map/Character.elm index 4b69ebc..b20c29a 100644 --- a/src/battle/src/View/Map/Character.elm +++ b/src/battle/src/View/Map/Character.elm @@ -16,6 +16,7 @@ import BattleCharacters.Struct.Equipment -- Local Module ---------------------------------------------------------------- import Constants.UI +import Struct.Battle import Struct.Character import Struct.CharacterTurn import Struct.Event @@ -80,11 +81,14 @@ get_alliance_class : ( (Html.Attribute Struct.Event.Type) ) get_alliance_class model char = - if ((Struct.Character.get_player_index char) == model.player_ix) - then - (Html.Attributes.class "character-ally") - else - (Html.Attributes.class "character-enemy") + if + ( + (Struct.Character.get_player_index char) + == + (Struct.Battle.get_own_player_index model.battle) + ) + then (Html.Attributes.class "character-ally") + else (Html.Attributes.class "character-enemy") get_position_style : ( Struct.Character.Type -> diff --git a/src/battle/src/View/SubMenu.elm b/src/battle/src/View/SubMenu.elm index 60a1c7d..dea0a86 100644 --- a/src/battle/src/View/SubMenu.elm +++ b/src/battle/src/View/SubMenu.elm @@ -11,6 +11,7 @@ import Html.Lazy import Util.Html -- Local Module ---------------------------------------------------------------- +import Struct.Battle import Struct.CharacterTurn import Struct.Event import Struct.Model @@ -37,10 +38,9 @@ get_inner_html model tab = (View.SubMenu.Status.get_html model) Struct.UI.CharactersTab -> - (Html.Lazy.lazy2 + (Html.Lazy.lazy (View.SubMenu.Characters.get_html) - model.characters - model.player_ix + model.battle ) Struct.UI.SettingsTab -> @@ -71,9 +71,12 @@ get_html model = [ (Html.text "Targeting:"), (Html.Lazy.lazy3 - (View.Controlled.CharacterCard.get_summary_html) + (View.Controlled.CharacterCard.get_summary_html + (Struct.Battle.get_own_player_index + model.battle + ) + ) model.char_turn - model.player_ix char ) ] diff --git a/src/roster-editor/src/Struct/Inventory.elm b/src/roster-editor/src/Struct/Inventory.elm index e04e828..85ae5b5 100644 --- a/src/roster-editor/src/Struct/Inventory.elm +++ b/src/roster-editor/src/Struct/Inventory.elm @@ -25,6 +25,7 @@ import BattleCharacters.Struct.Equipment import BattleCharacters.Struct.Glyph import BattleCharacters.Struct.GlyphBoard import BattleCharacters.Struct.Portrait +import BattleCharacters.Struct.Skill import BattleCharacters.Struct.Weapon -------------------------------------------------------------------------------- @@ -36,7 +37,8 @@ type alias Type = glyphs : (Set.Set BattleCharacters.Struct.Glyph.Ref), glyph_boards : (Set.Set BattleCharacters.Struct.GlyphBoard.Ref), weapons : (Set.Set BattleCharacters.Struct.Weapon.Ref), - armors : (Set.Set BattleCharacters.Struct.Armor.Ref) + armors : (Set.Set BattleCharacters.Struct.Armor.Ref), + skills : (Set.Set BattleCharacters.Struct.Skill.Ref) } -------------------------------------------------------------------------------- @@ -46,63 +48,73 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -has_portrait : Type -> BattleCharacters.Struct.Portrait.Ref -> Bool -has_portrait inv id = (Set.member id inv.portraits) +has_portrait : BattleCharacters.Struct.Portrait.Ref -> Type -> Bool +has_portrait id inv = (Set.member id inv.portraits) -has_glyph : Type -> BattleCharacters.Struct.Glyph.Ref -> Bool -has_glyph inv id = (Set.member id inv.glyphs) +has_glyph : BattleCharacters.Struct.Glyph.Ref -> Type -> Bool +has_glyph id inv = (Set.member id inv.glyphs) -has_glyph_board : Type -> BattleCharacters.Struct.GlyphBoard.Ref -> Bool -has_glyph_board inv id = (Set.member id inv.glyph_boards) +has_glyph_board : BattleCharacters.Struct.GlyphBoard.Ref -> Type -> Bool +has_glyph_board id inv = (Set.member id inv.glyph_boards) -has_weapon : Type -> BattleCharacters.Struct.Weapon.Ref -> Bool -has_weapon inv id = (Set.member id inv.weapons) +has_weapon : BattleCharacters.Struct.Weapon.Ref -> Type -> Bool +has_weapon id inv = (Set.member id inv.weapons) -has_armor : Type -> BattleCharacters.Struct.Armor.Ref -> Bool -has_armor inv id = (Set.member id inv.armors) +has_armor : BattleCharacters.Struct.Armor.Ref -> Type -> Bool +has_armor id inv = (Set.member id inv.armors) -allows : Type -> BattleCharacters.Struct.Equipment.Type -> Bool -allows inv equipment = +has_skill : BattleCharacters.Struct.Skill.Ref -> Type -> Bool +has_skill id inv = (Set.member id inv.skills) + +allows : BattleCharacters.Struct.Equipment.Type -> Type -> Bool +allows equipment inv = ( (has_weapon - inv (BattleCharacters.Struct.Weapon.get_id (BattleCharacters.Struct.Equipment.get_primary_weapon equipment) ) + inv ) && (has_weapon - inv (BattleCharacters.Struct.Weapon.get_id (BattleCharacters.Struct.Equipment.get_secondary_weapon equipment) ) + inv ) && (has_armor - inv (BattleCharacters.Struct.Armor.get_id (BattleCharacters.Struct.Equipment.get_armor equipment) ) + inv ) && (has_portrait - inv (BattleCharacters.Struct.Portrait.get_id (BattleCharacters.Struct.Equipment.get_portrait equipment) ) + inv ) && (has_glyph_board - inv (BattleCharacters.Struct.GlyphBoard.get_id (BattleCharacters.Struct.Equipment.get_glyph_board equipment) ) + inv ) && (List.all - ((BattleCharacters.Struct.Glyph.get_id) >> (has_glyph inv)) + (e -> (has_glyph e inv)) (Array.toList (BattleCharacters.Struct.Equipment.get_glyphs equipment)) ) + && + (has_skill + (BattleCharacters.Struct.Skill.get_id + (BattleCharacters.Struct.Equipment.get_skill equipment) + ) + inv + ) ) empty : Type @@ -112,7 +124,8 @@ empty = glyphs = (Set.empty), glyph_boards = (Set.empty), weapons = (Set.empty), - armors = (Set.empty) + armors = (Set.empty), + skills = (Set.empty) } decoder : (Json.Decode.Decoder Type) @@ -125,4 +138,5 @@ decoder = |> (Json.Decode.Pipeline.hardcoded (Set.empty)) |> (Json.Decode.Pipeline.hardcoded (Set.empty)) |> (Json.Decode.Pipeline.hardcoded (Set.empty)) + |> (Json.Decode.Pipeline.hardcoded (Set.empty)) ) diff --git a/src/roster-editor/src/Struct/Model.elm b/src/roster-editor/src/Struct/Model.elm index 3e573f9..d0d70b4 100644 --- a/src/roster-editor/src/Struct/Model.elm +++ b/src/roster-editor/src/Struct/Model.elm @@ -44,18 +44,19 @@ import Struct.UI type alias Type = { flags : Struct.Flags.Type, + error : (Maybe Struct.Error.Type), + ui : Struct.UI.Type help_request : Struct.HelpRequest.Type, + edited_char : (Maybe Struct.Character.Type), + + roster_id : String, + battle_order : (Array.Array Int), + characters : (Array.Array Struct.Character.Type), unresolved_characters : (List Struct.Character.Unresolved), - inventory : BattleCharacters.Struct.Inventory.Type, - error : (Maybe Struct.Error.Type), - battle_order : (Array.Array Int), - player_id : String, - roster_id : String, - edited_char : (Maybe Struct.Character.Type), inventory : Struct.Inventory.Type, - session_token : String, - ui : Struct.UI.Type + + characters_data_set : BattleCharacters.Struct.DataSet.Type, } -------------------------------------------------------------------------------- @@ -83,7 +84,7 @@ has_loaded_data : Type -> Bool has_loaded_data model = ( ((Array.length model.characters) > 0) - || (BattleCharacters.Struct.Inventory.is_ready model.inventory) + || (BattleCharacters.Struct.DataSet.is_ready model.characters_data_set) ) -------------------------------------------------------------------------------- diff --git a/src/shared/battle-characters/BattleCharacters/Struct/Inventory.elm b/src/shared/battle-characters/BattleCharacters/Struct/DataSet.elm index 9e1347e..4e3050a 100644 --- a/src/shared/battle-characters/BattleCharacters/Struct/Inventory.elm +++ b/src/shared/battle-characters/BattleCharacters/Struct/DataSet.elm @@ -1,4 +1,4 @@ -module BattleCharacters.Struct.Inventory exposing +module BattleCharacters.Struct.DataSet exposing ( Type, new, @@ -75,47 +75,23 @@ type alias Type = new : Type new = { - weapons : - (Dict.Dict - BattleCharacters.Struct.Weapon.Ref - BattleCharacters.Struct.Weapon.Type - ), - armors : - (Dict.Dict - BattleCharacters.Struct.Armor.Ref - BattleCharacters.Struct.Armor.Type - ), - glyphs : - (Dict.Dict - BattleCharacters.Struct.Glyph.Ref - BattleCharacters.Struct.Glyph.Type - ), - glyph_boards : - (Dict.Dict - BattleCharacters.Struct.GlyphBoard.Ref - BattleCharacters.Struct.GlyphBoard.Type - ), - portraits : - (Dict.Dict - BattleCharacters.Struct.Portrait.Ref - BattleCharacters.Struct.Portrait.Type - ), - skills : - (Dict.Dict - BattleCharacters.Struct.Portrait.Ref - BattleCharacters.Struct.Portrait.Type - ), + weapons = (Dict.new), + armors = (Dict.new), + glyphs = (Dict.new), + glyph_boards = (Dict.new), + portraits = (Dict.new), + skills = (Dict.new) } is_ready : Type -> Bool -is_ready inventory = +is_ready data_set = ( - (inventory.portraits /= (Dict.empty)) - && (inventory.weapons /= (Dict.empty)) - && (inventory.armors /= (Dict.empty)) - && (inventory.glyph_boards /= (Dict.empty)) - && (inventory.glyphs /= (Dict.empty)) - && (inventory.skills /= (Dict.empty)) + (data_set.portraits /= (Dict.empty)) + && (data_set.weapons /= (Dict.empty)) + && (data_set.armors /= (Dict.empty)) + && (data_set.glyph_boards /= (Dict.empty)) + && (data_set.glyphs /= (Dict.empty)) + && (data_set.skills /= (Dict.empty)) ) ---- Accessors ----------------------------------------------------------------- @@ -128,19 +104,19 @@ get_weapon : ( Type -> BattleCharacters.Struct.Weapon.Type ) -get_weapon wp_id inventory = - case (Dict.get wp_id inventory.weapons) of +get_weapon wp_id data_set = + case (Dict.get wp_id data_set.weapons) of (Just wp) -> wp Nothing -> BattleCharacters.Struct.Weapon.none add_weapon : BattleCharacters.Struct.Weapon.Type -> Type -> Type -add_weapon wp inventory = - {inventory | +add_weapon wp data_set = + {data_set | weapons = (Dict.insert (BattleCharacters.Struct.Weapon.get_id wp) wp - inventory.weapons + data_set.weapons ) } @@ -152,19 +128,19 @@ get_armor : ( Type -> BattleCharacters.Struct.Armor.Type ) -get_armor ar_id inventory = - case (Dict.get ar_id inventory.armors) of +get_armor ar_id data_set = + case (Dict.get ar_id data_set.armors) of (Just ar) -> ar Nothing -> BattleCharacters.Struct.Armor.none add_armor : BattleCharacters.Struct.Armor.Type -> Type -> Type -add_armor ar inventory = - {inventory | +add_armor ar data_set = + {data_set | armors = (Dict.insert (BattleCharacters.Struct.Armor.get_id ar) ar - inventory.armors + data_set.armors ) } @@ -176,19 +152,19 @@ get_portrait : ( Type -> BattleCharacters.Struct.Portrait.Type ) -get_portrait pt_id inventory = - case (Dict.get pt_id inventory.portraits) of +get_portrait pt_id data_set = + case (Dict.get pt_id data_set.portraits) of (Just pt) -> pt Nothing -> BattleCharacters.Struct.Portrait.none add_portrait : BattleCharacters.Struct.Portrait.Type -> Type -> Type -add_portrait pt inventory = - {inventory | +add_portrait pt data_set = + {data_set | portraits = (Dict.insert (BattleCharacters.Struct.Portrait.get_id pt) pt - inventory.portraits + data_set.portraits ) } @@ -200,19 +176,19 @@ get_glyph : ( Type -> BattleCharacters.Struct.Glyph.Type ) -get_glyph gl_id inventory = - case (Dict.get gl_id inventory.glyphs) of +get_glyph gl_id data_set = + case (Dict.get gl_id data_set.glyphs) of (Just gl) -> gl Nothing -> BattleCharacters.Struct.Glyph.none add_glyph : BattleCharacters.Struct.Glyph.Type -> Type -> Type -add_glyph gl inventory = - {inventory | +add_glyph gl data_set = + {data_set | glyphs = (Dict.insert (BattleCharacters.Struct.Glyph.get_id gl) gl - inventory.glyphs + data_set.glyphs ) } @@ -224,19 +200,19 @@ get_glyph_board : ( Type -> BattleCharacters.Struct.GlyphBoard.Type ) -get_glyph_board gb_id inventory = - case (Dict.get gb_id inventory.glyph_boards) of +get_glyph_board gb_id data_set = + case (Dict.get gb_id data_set.glyph_boards) of (Just gb) -> gb Nothing -> BattleCharacters.Struct.GlyphBoard.none add_glyph_board : BattleCharacters.Struct.GlyphBoard.Type -> Type -> Type -add_glyph_board glb inventory = - {inventory | +add_glyph_board glb data_set = + {data_set | glyph_boards = (Dict.insert (BattleCharacters.Struct.GlyphBoard.get_id glb) glb - inventory.glyph_boards + data_set.glyph_boards ) } @@ -248,19 +224,19 @@ get_skill : ( Type -> BattleCharacters.Struct.Skill.Type ) -get_skill sk_id inventory = - case (Dict.get sk_id inventory.skills) of +get_skill sk_id data_set = + case (Dict.get sk_id data_set.skills) of (Just sk) -> sk Nothing -> BattleCharacters.Struct.Skill.none add_skill : BattleCharacters.Struct.Skill.Type -> Type -> Type -add_skill sk inventory = - {inventory | +add_skill sk data_set = + {data_set | skills = (Dict.insert (BattleCharacters.Struct.Skill.get_id sk) sk - inventory.skills + data_set.skills ) } diff --git a/src/shared/battle-map/BattleMap/Struct/DataSet.elm b/src/shared/battle-map/BattleMap/Struct/DataSet.elm new file mode 100644 index 0000000..f292443 --- /dev/null +++ b/src/shared/battle-map/BattleMap/Struct/DataSet.elm @@ -0,0 +1,67 @@ +module BattleMap.Struct.DataSet exposing + ( + Type, + new, + is_ready, + get_tile, + add_tile + ) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Battle ---------------------------------------------------------------------- +import BattleMap.Struct.Tile + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + tiles : (Dict.Dict BattleMap.Struct.Tile.Ref BattleMap.Struct.Tile.Type) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +new : Type +new = + { + tiles = (Dict.new) + } + +is_ready : Type -> Bool +is_ready data_set = + ( + (data_set.tiles /= (Dict.empty)) + ) + +---- Accessors ----------------------------------------------------------------- + +-------------- +---- Tile ---- +-------------- +get_tile : ( + BattleMap.Struct.Tile.Ref -> + Type -> + BattleMap.Struct.Tile.Type + ) +get_tile tl_id data_set = + case (Dict.get tl_id data_set.tiles) of + (Just tl) -> tl + Nothing -> BattleMap.Struct.Tile.none + +add_tile : BattleMap.Struct.Tile.Type -> Type -> Type +add_tile tl data_set = + {data_set | + tiles = + (Dict.insert + (BattleMap.Struct.Tile.get_id tl) + tl + data_set.tiles + ) + } diff --git a/src/shared/elm/Struct/Flags.elm b/src/shared/elm/Struct/Flags.elm index 9fb9eac..a9f1630 100644 --- a/src/shared/elm/Struct/Flags.elm +++ b/src/shared/elm/Struct/Flags.elm @@ -3,7 +3,9 @@ module Struct.Flags exposing Type, maybe_get_param, force_get_param, - get_params_as_url + get_params_as_url, + get_session_token, + get_user_id ) -- Elm ------------------------------------------------------------------------- @@ -63,3 +65,9 @@ get_params_as_url flags = "" flags.url_params ) + +get_session_token : Type -> String +get_session_token flags = flags.token + +get_user_id : Type -> String +get_user_id flags = flags.user_id |