summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-11-09 17:55:05 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-11-09 17:55:05 +0100 |
commit | 25e3a440f35cecb2f235442acbe1667fcf19d6da (patch) | |
tree | 9eb8a895b13db47443d621aa4e897c025fc23872 /src/roster-editor | |
parent | 11ab56f19b8979c8f3d164277ad5b40555150f78 (diff) |
[Broken] Working on the aforementioned issue...
Diffstat (limited to 'src/roster-editor')
-rw-r--r-- | src/roster-editor/src/Struct/Character.elm | 167 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/CharacterRecord.elm | 144 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Model.elm | 57 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/ServerReply.elm | 4 |
4 files changed, 256 insertions, 116 deletions
diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm index 89e2a18..a589fcc 100644 --- a/src/roster-editor/src/Struct/Character.elm +++ b/src/roster-editor/src/Struct/Character.elm @@ -1,6 +1,7 @@ module Struct.Character exposing ( Type, + new, get_index, get_name, set_name, @@ -18,9 +19,7 @@ module Struct.Character exposing get_glyphs, set_glyph, set_was_edited, - get_was_edited, - decoder, - encode + get_was_edited ) -- Elm ------------------------------------------------------------------------- @@ -44,19 +43,6 @@ import Struct.WeaponSet -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -type alias PartiallyDecoded = - { - ix : Int, - nam : String, - prt : String, - awp : Int, - swp : Int, - ar : Int, - gb : String, - gls : (List Int), - current_omnimods : Struct.Omnimods.Type - } - type alias Type = { ix : Int, @@ -75,31 +61,6 @@ type alias Type = -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -finish_decoding : PartiallyDecoded -> (Type, String, Int, Int, Int) -finish_decoding add_char = - let - weapon_set = (Struct.WeaponSet.new Struct.Weapon.none Struct.Weapon.none) - armor = Struct.Armor.none - glyph_board = Struct.GlyphBoard.none - glyphs = (Array.empty) - default_attributes = (Struct.Attributes.default) - almost_char = - { - ix = add_char.ix, - name = add_char.nam, - portrait = (Struct.Portrait.default), - attributes = default_attributes, - statistics = (Struct.Statistics.new_raw default_attributes), - weapons = weapon_set, - armor = armor, - glyph_board = glyph_board, - glyphs = glyphs, - current_omnimods = add_char.current_omnimods, - was_edited = False - } - in - (almost_char, add_char.prt, add_char.awp, add_char.swp, add_char.ar) - refresh_omnimods : Type -> Type refresh_omnimods char = let @@ -137,6 +98,67 @@ refresh_omnimods char = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- +new : ( + Int -> + String -> + (Maybe Struct.Portrait.Type) -> + (Maybe Struct.Weapon.Type) -> + (Maybe Struct.Weapon.Type) -> + (Maybe Struct.Armor.Type) -> + (Maybe Struct.GlyphBoard.Type) -> + (List (Maybe Struct.Glyph.Type)) -> + Type + ) +new index name m_portrait m_main_wp m_sec_wp m_armor m_board m_glyphs = + { + ix = index, + name = name, + portrait = + ( + case m_portrait of + (Just portrait) -> portrait + Nothing -> (Struct.Portrait.default) + ), + attributes = (Struct.Attributes.default), + statistics = (Struct.Statistics.default), + weapons = + (Struct.WeaponSet.new + ( + case m_main_wp of + (Just w) -> w + Nothing -> (Struct.Weapon.default) + ) + ( + case m_sec_wp of + (Just w) -> w + Nothing -> (Struct.Weapon.default) + ) + ), + armor = + ( + case m_armor of + (Just armor) -> armor + Nothing -> (Struct.Armor.default) + ), + glyph_board = + ( + case m_board of + (Just board) -> board + Nothing -> (Struct.GlyphBoard.default) + ), + glyphs = + (Array.fromList + (List.map + (\m_g -> + case m_g of + (Just g) -> g + Nothing -> (Struct.Glyph.default) + ) + m_glyphs + ) + current_omnimods = (Struct.Omnimods.none), + was_edited = False + } get_index : Type -> Int get_index c = c.ix @@ -197,66 +219,3 @@ get_was_edited char = char.was_edited set_was_edited : Bool -> Type -> Type set_was_edited val char = {char | was_edited = val} - -decoder : (Json.Decode.Decoder (Type, String, Int, Int, Int)) -decoder = - (Json.Decode.map - (finish_decoding) - (Json.Decode.Pipeline.decode - PartiallyDecoded - |> (Json.Decode.Pipeline.required "ix" Json.Decode.int) - |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) - |> (Json.Decode.Pipeline.required "prt" Json.Decode.string) - |> (Json.Decode.Pipeline.required "awp" Json.Decode.int) - |> (Json.Decode.Pipeline.required "swp" Json.Decode.int) - |> (Json.Decode.Pipeline.required "ar" Json.Decode.int) - |> (Json.Decode.Pipeline.required "gb" Json.Decode.string) - |> (Json.Decode.Pipeline.required - "gls" - (Json.Decode.list Json.Decode.int) - ) - |> (Json.Decode.Pipeline.hardcoded (Struct.Omnimods.none)) - ) - ) - -encode : Type -> Json.Encode.Value -encode char = - (Json.Encode.object - [ - ("ix", (Json.Encode.int char.ix)), - ("nam", (Json.Encode.string char.name)), - ("prt", (Json.Encode.string (Struct.Portrait.get_id char.portrait))), - ( - "awp", - (Json.Encode.int - (Struct.Weapon.get_id - (Struct.WeaponSet.get_active_weapon char.weapons) - ) - ) - ), - ( - "swp", - (Json.Encode.int - (Struct.Weapon.get_id - (Struct.WeaponSet.get_active_weapon char.weapons) - ) - ) - ), - ("ar", (Json.Encode.int (Struct.Armor.get_id char.armor))), - ( - "gb", - (Json.Encode.string (Struct.GlyphBoard.get_id char.glyph_board)) - ), - ( - "gls", - (Json.Encode.list - (Array.toList - (Array.map - ((Struct.Glyph.get_id) >> Json.Encode.string) - char.glyphs - ) - ) - ) - ) - ] - ) diff --git a/src/roster-editor/src/Struct/CharacterRecord.elm b/src/roster-editor/src/Struct/CharacterRecord.elm new file mode 100644 index 0000000..c92014d --- /dev/null +++ b/src/roster-editor/src/Struct/CharacterRecord.elm @@ -0,0 +1,144 @@ +module Struct.CharacterRecord exposing + ( + Type, + get_index, + get_name, + get_portrait_id, + get_armor_id, + get_main_weapon_id, + get_secondary_weapon_id, + get_glyph_board_id, + get_glyph_ids, + from_character, + decoder, + encode + ) + +-- Elm ------------------------------------------------------------------------- +import Array + +import Json.Decode +import Json.Decode.Pipeline +import Json.Encode + +-- Roster Editor --------------------------------------------------------------- +import Struct.Armor +import Struct.Attributes +import Struct.Glyph +import Struct.GlyphBoard +import Struct.Omnimods +import Struct.Portrait +import Struct.Statistics +import Struct.Weapon +import Struct.WeaponSet + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Type = + { + index : Int, + name : String, + portrait_id : String, + main_weapon_id : Int, + secondary_weapon_id : Int, + armor_id : Int, + glyph_board_id : String, + glyph_ids : (List Int) + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_index : Type -> Int +get_index c = c.index + +get_name : Type -> String +get_name c = c.name + +get_portrait_id : Type -> String +get_portrait_id c = c.portrait_id + +get_main_weapon_id : Type -> Int +get_main_weapon_id char = char.main_weapon_id + +get_secondary_weapon_id : Type -> Int +get_secondary_weapon_id char = char.secondary_weapon_id + +get_armor_id : Type -> Int +get_armor_id char = char.armor_id + +get_glyph_board_id : Type -> String +get_glyph_board_id char = char.glyph_board_id + +get_glyph_ids : Type -> (List Int) +get_glyph_ids char = char.glyph_ids + +from_character : Struct.Character.Type -> Type +from_character char = + let + weapons = (Struct.Character.get_weapons char) + in + { + index = (Struct.Character.get_index char), + name = (Struct.Character.get_name char), + portrait_id = + (Struct.Portrait.get_id (Struct.Character.get_portrait char)), + armor_id = (Struct.Armor.get_id (Struct.Character.get_armor char)), + main_weapon_id = + (Struct.Weapon.get_id (Struct.WeaponSet.get_active_weapon weapons)), + secondary_weapon_id = + (Struct.Weapon.get_id (Struct.WeaponSet.get_secondary_weapon weapons)), + glyph_board_id = + (Struct.GlyphBoard.get_id (Struct.Character.get_glyph_board char)), + glyph_ids = + (Array.toList + (Array.map + (Struct.Glyph.get_id) + (Struct.Character.get_glyphs char) + ) + ) + } + +decoder : (Json.Decode.Decoder Type) +decoder = + (Json.Decode.Pipeline.decode + PartiallyDecoded + |> (Json.Decode.Pipeline.required "ix" Json.Decode.int) + |> (Json.Decode.Pipeline.required "nam" Json.Decode.string) + |> (Json.Decode.Pipeline.required "prt" Json.Decode.string) + |> (Json.Decode.Pipeline.required "awp" Json.Decode.int) + |> (Json.Decode.Pipeline.required "swp" Json.Decode.int) + |> (Json.Decode.Pipeline.required "ar" Json.Decode.int) + |> (Json.Decode.Pipeline.required "gb" Json.Decode.string) + |> (Json.Decode.Pipeline.required + "gls" + (Json.Decode.list Json.Decode.int) + ) + ) + +encode : Type -> Json.Encode.Value +encode char = + (Json.Encode.object + [ + ("ix", (Json.Encode.int char.index)), + ("nam", (Json.Encode.string char.name)), + ("prt", (Json.Encode.string char.portrait_id)), + ("awp", (Json.Encode.int char.main_weapon_id)), + ("swp", (Json.Encode.int char.secondary_weapon_id)), + ("ar", (Json.Encode.int char.armor_id)), + ("gb", (Json.Encode.string char.glyph_board_id)), + ( + "gls", + (Json.Encode.list + (List.map (Json.Encode.string) + char.glyph_ids + ) + ) + ) + ] + ) diff --git a/src/roster-editor/src/Struct/Model.elm b/src/roster-editor/src/Struct/Model.elm index ef5b21c..3dd5c3c 100644 --- a/src/roster-editor/src/Struct/Model.elm +++ b/src/roster-editor/src/Struct/Model.elm @@ -2,7 +2,7 @@ module Struct.Model exposing ( Type, new, - add_character, + add_character_record, update_character, update_character_fun, save_character, @@ -26,6 +26,7 @@ import Struct.Flags -- Roster Editor --------------------------------------------------------------- import Struct.Armor import Struct.Character +import Struct.CharacterRecord import Struct.Error import Struct.Glyph import Struct.GlyphBoard @@ -45,6 +46,7 @@ type alias Type = flags: Struct.Flags.Type, help_request: Struct.HelpRequest.Type, characters: (Array.Array Struct.Character.Type), + stalled_characters: (List Struct.CharacterRecord.Type), weapons: (Dict.Dict Struct.Weapon.Ref Struct.Weapon.Type), armors: (Dict.Dict Struct.Armor.Ref Struct.Armor.Type), glyphs: (Dict.Dict Struct.Glyph.Ref Struct.Glyph.Type), @@ -62,6 +64,44 @@ type alias Type = -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- +add_character : Struct.CharacterRecord.Type -> Type -> Type +add_character char_rec model = + let index = (Struct.CharacterRecord.get_index char_rec) in + {model | + characters = + (Array.set + index + (Struct.Character.new + index + (Struct.CharacterRecord.get_name char_rec) + (Dict.get + (Struct.CharacterRecord.get_portrait_id char_rec) + model.portraits + ) + (Dict.get + (Struct.CharacterRecord.get_main_weapon_id char_rec) + model.weapons + ) + (Dict.get + (Struct.CharacterRecord.get_secondary_weapon_id char_rec) + model.weapons + ) + (Dict.get + (Struct.CharacterRecord.get_armor_id char_rec) + model.armors + ) + (Dict.get + (Struct.CharacterRecord.get_glyph_board_id char_rec) + model.glyph_boards + ) + (List.map + (\e -> (Dict.get e model.glyphs)) + (Struct.CharacterRecord.get_glyph_ids char_rec) + ) + ) + model.characters + ) + } -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -72,6 +112,7 @@ new flags = flags = flags, help_request = Struct.HelpRequest.None, characters = (Array.empty), + stalled_characters = [], weapons = (Dict.empty), armors = (Dict.empty), glyphs = (Dict.empty), @@ -91,15 +132,11 @@ new flags = ui = (Struct.UI.default) } -add_character : Struct.Character.Type -> Type -> Type -add_character char model = - {model | - characters = - (Array.push - char - model.characters - ) - } +add_character_record : Struct.CharacterRecord.Type -> Type -> Type +add_character_record char model = + if (condition) + then {model | stalled_characters = (char :: model.stalled_characters)} + else (add_character char model) add_weapon : Struct.Weapon.Type -> Type -> Type add_weapon wp model = diff --git a/src/roster-editor/src/Struct/ServerReply.elm b/src/roster-editor/src/Struct/ServerReply.elm index 4d592f5..1842ea4 100644 --- a/src/roster-editor/src/Struct/ServerReply.elm +++ b/src/roster-editor/src/Struct/ServerReply.elm @@ -4,7 +4,7 @@ module Struct.ServerReply exposing (Type(..)) -- Roster Editor --------------------------------------------------------------- import Struct.Armor -import Struct.Character +import Struct.CharacterRecord import Struct.Glyph import Struct.GlyphBoard import Struct.Inventory @@ -24,7 +24,7 @@ type Type = | AddGlyphBoard Struct.GlyphBoard.Type | AddPortrait Struct.Portrait.Type | AddWeapon Struct.Weapon.Type - | AddCharacter (Struct.Character.Type, String, Int, Int, Int) + | AddCharacter Struct.CharacterRecord.Type -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- |