summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-10-23 18:52:14 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-10-23 18:52:14 +0200 |
commit | 0c39f5749de5aa17b410a18a40cccbd6ac5b9717 (patch) | |
tree | 78f0b53ccf2bda4cad84eb5d0096e250a7f27105 /src | |
parent | fc301462a384226c76d2487c402493adbb6b6dbe (diff) |
Roster editor still wip...
Diffstat (limited to 'src')
-rw-r--r-- | src/roster-editor/src/Comm/AddChar.elm | 2 | ||||
-rw-r--r-- | src/roster-editor/src/ElmModule/Update.elm | 8 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Character.elm | 107 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/GlyphBoard.elm | 11 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Inventory.elm | 6 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/Portrait.elm | 6 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/ServerReply.elm | 2 | ||||
-rw-r--r-- | src/roster-editor/src/Struct/WeaponSet.elm | 8 | ||||
-rw-r--r-- | src/roster-editor/src/Update/HandleServerReply.elm | 30 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetArmor.elm | 14 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetGlyph.elm | 41 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetGlyphBoard.elm | 40 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetPortrait.elm | 38 | ||||
-rw-r--r-- | src/roster-editor/src/Update/SetWeapon.elm | 57 | ||||
-rw-r--r-- | src/roster-editor/src/View/Character.elm | 15 |
15 files changed, 333 insertions, 52 deletions
diff --git a/src/roster-editor/src/Comm/AddChar.elm b/src/roster-editor/src/Comm/AddChar.elm index e2b580a..21cbb77 100644 --- a/src/roster-editor/src/Comm/AddChar.elm +++ b/src/roster-editor/src/Comm/AddChar.elm @@ -16,7 +16,7 @@ import Struct.ServerReply -------------------------------------------------------------------------------- internal_decoder : ( - (Struct.Character.Type, Int, Int, Int) -> + (Struct.Character.Type, String, Int, Int, Int) -> Struct.ServerReply.Type ) internal_decoder char_and_refs = (Struct.ServerReply.AddCharacter char_and_refs) diff --git a/src/roster-editor/src/ElmModule/Update.elm b/src/roster-editor/src/ElmModule/Update.elm index 6896a11..f095ee8 100644 --- a/src/roster-editor/src/ElmModule/Update.elm +++ b/src/roster-editor/src/ElmModule/Update.elm @@ -69,11 +69,11 @@ update event model = (Struct.Event.SelectedArmor ref) -> (Update.SetArmor.apply_to new_model ref) - (Struct.Event.SelectedWeapon ref) -> - (Update.SetWeapon.apply_to new_model ref) + (Struct.Event.SelectedWeapon (ref, is_main)) -> + (Update.SetWeapon.apply_to new_model ref is_main) - (Struct.Event.SelectedGlyph ref) -> - (Update.SetGlyph.apply_to new_model ref) + (Struct.Event.SelectedGlyph (ref, index)) -> + (Update.SetGlyph.apply_to new_model ref index) (Struct.Event.SelectedGlyphBoard ref) -> (Update.SetGlyphBoard.apply_to new_model ref) diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm index 72ea314..ab0e452 100644 --- a/src/roster-editor/src/Struct/Character.elm +++ b/src/roster-editor/src/Struct/Character.elm @@ -3,15 +3,20 @@ module Struct.Character exposing Type, get_index, get_name, - get_portrait_id, + set_name, + get_portrait, + set_portrait, get_armor, + set_armor, get_current_omnimods, get_attributes, get_statistics, get_weapons, set_weapons, --- get_glyph_board, --- get_glyphes, + get_glyph_board, + set_glyph_board, + get_glyphs, + set_glyph, decoder ) @@ -27,6 +32,7 @@ import Struct.Attributes import Struct.Glyph import Struct.GlyphBoard import Struct.Omnimods +import Struct.Portrait import Struct.Statistics import Struct.Weapon import Struct.WeaponSet @@ -51,42 +57,76 @@ type alias Type = { ix : Int, name : String, - portrait : String, + portrait : Struct.Portrait.Type, attributes : Struct.Attributes.Type, statistics : Struct.Statistics.Type, weapons : Struct.WeaponSet.Type, armor : Struct.Armor.Type, glyph_board : Struct.GlyphBoard.Type, - glyphes : (Array.Array Struct.Glyph.Type), + glyphs : (Array.Array Struct.Glyph.Type), current_omnimods : Struct.Omnimods.Type } -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -finish_decoding : PartiallyDecoded -> (Type, Int, Int, Int) +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 - glyphes = (Array.empty) + glyphs = (Array.empty) default_attributes = (Struct.Attributes.default) almost_char = { ix = add_char.ix, name = add_char.nam, - portrait = add_char.prt, + portrait = (Struct.Portrait.default), attributes = default_attributes, statistics = (Struct.Statistics.new_raw default_attributes), weapons = weapon_set, armor = armor, glyph_board = glyph_board, - glyphes = glyphes, + glyphs = glyphs, current_omnimods = add_char.current_omnimods } in - (almost_char, add_char.awp, add_char.swp, add_char.ar) + (almost_char, add_char.prt, add_char.awp, add_char.swp, add_char.ar) + +refresh_omnimods : Type -> Type +refresh_omnimods char = + let + current_omnimods = + (Struct.Omnimods.merge + (Struct.Omnimods.merge + (Struct.Weapon.get_omnimods + (Struct.WeaponSet.get_active_weapon char.weapons) + ) + (Struct.Armor.get_omnimods char.armor) + ) + (Struct.GlyphBoard.get_omnimods_with_glyphs + char.glyphs + char.glyph_board + ) + ) + current_attributes = + (Struct.Omnimods.apply_to_attributes + current_omnimods + (Struct.Attributes.default) + ) + current_statistics = + (Struct.Omnimods.apply_to_statistics + current_omnimods + (Struct.Statistics.new_raw current_attributes) + ) + in + {char | + attributes = current_attributes, + statistics = current_statistics, + current_omnimods = current_omnimods + } + -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- @@ -97,8 +137,14 @@ get_index c = c.ix get_name : Type -> String get_name c = c.name -get_portrait_id : Type -> String -get_portrait_id c = c.portrait +set_name : String -> Type -> Type +set_name name char = {char | name = name} + +get_portrait : Type -> Struct.Portrait.Type +get_portrait c = c.portrait + +set_portrait : Struct.Portrait.Type -> Type -> Type +set_portrait portrait char = {char | portrait = portrait} get_current_omnimods : Type -> Struct.Omnimods.Type get_current_omnimods c = c.current_omnimods @@ -112,24 +158,35 @@ get_statistics char = char.statistics get_weapons : Type -> Struct.WeaponSet.Type get_weapons char = char.weapons +set_weapons : Struct.WeaponSet.Type -> Type -> Type +set_weapons weapons char = (refresh_omnimods {char | weapons = weapons}) + get_armor : Type -> Struct.Armor.Type get_armor char = char.armor -get_armor_variation : Type -> String -get_armor_variation char = - case char.portrait of - -- Currently hardcoded to match crows from characters.css - "11" -> "1" - "4" -> "1" - _ -> "0" +set_armor : Struct.Armor.Type -> Type -> Type +set_armor armor char = (refresh_omnimods {char | armor = armor}) -set_weapons : Struct.WeaponSet.Type -> Type -> Type -set_weapons weapons char = - {char | - weapons = weapons - } +get_glyph_board : Type -> Struct.GlyphBoard.Type +get_glyph_board char = char.glyph_board + +set_glyph_board : Struct.GlyphBoard.Type -> Type -> Type +set_glyph_board glyph_board char = + (refresh_omnimods + {char | + glyph_board = glyph_board, + glyphs = (Array.empty) + } + ) + +get_glyphs : Type -> (Array.Array Struct.Glyph.Type) +get_glyphs char = char.glyphs + +set_glyph : Int -> Struct.Glyph.Type -> Type -> Type +set_glyph index glyph char = + (refresh_omnimods {char | glyphs = (Array.set index glyph char.glyphs)}) -decoder : (Json.Decode.Decoder (Type, Int, Int, Int)) +decoder : (Json.Decode.Decoder (Type, String, Int, Int, Int)) decoder = (Json.Decode.map (finish_decoding) diff --git a/src/roster-editor/src/Struct/GlyphBoard.elm b/src/roster-editor/src/Struct/GlyphBoard.elm index 94e53da..27ecfeb 100644 --- a/src/roster-editor/src/Struct/GlyphBoard.elm +++ b/src/roster-editor/src/Struct/GlyphBoard.elm @@ -5,15 +5,19 @@ module Struct.GlyphBoard exposing get_name, get_id, get_omnimods, + get_omnimods_with_glyphs, decoder, none ) -- Elm ------------------------------------------------------------------------- +import Array + import Json.Decode import Json.Decode.Pipeline -- Roster Editor --------------------------------------------------------------- +import Struct.Glyph import Struct.Omnimods -------------------------------------------------------------------------------- @@ -44,6 +48,13 @@ get_name g = g.name get_omnimods : Type -> Struct.Omnimods.Type get_omnimods g = g.omnimods +get_omnimods_with_glyphs : ( + (Array.Array Struct.Glyph.Type) -> + Type -> + Struct.Omnimods.Type + ) +get_omnimods_with_glyphs glyphs board = board.omnimods + decoder : (Json.Decode.Decoder Type) decoder = (Json.Decode.Pipeline.decode diff --git a/src/roster-editor/src/Struct/Inventory.elm b/src/roster-editor/src/Struct/Inventory.elm index a24f31a..85e0d07 100644 --- a/src/roster-editor/src/Struct/Inventory.elm +++ b/src/roster-editor/src/Struct/Inventory.elm @@ -24,7 +24,7 @@ import Set type alias Type = { portraits : (Set.Set Int), - glyphes : (Set.Set Int), + glyphs : (Set.Set Int), glyph_boards : (Set.Set Int), weapons : (Set.Set Int), armors : (Set.Set Int) @@ -41,7 +41,7 @@ has_portrait : Int -> Type -> Bool has_portrait id inv = (Set.member id inv.portraits) has_glyph : Int -> Type -> Bool -has_glyph id inv = (Set.member id inv.glyphes) +has_glyph id inv = (Set.member id inv.glyphs) has_glyph_board : Int -> Type -> Bool has_glyph_board id inv = (Set.member id inv.glyph_boards) @@ -56,7 +56,7 @@ empty : Type empty = { portraits = (Set.empty), - glyphes = (Set.empty), + glyphs = (Set.empty), glyph_boards = (Set.empty), weapons = (Set.empty), armors = (Set.empty) diff --git a/src/roster-editor/src/Struct/Portrait.elm b/src/roster-editor/src/Struct/Portrait.elm index 125a416..400b64d 100644 --- a/src/roster-editor/src/Struct/Portrait.elm +++ b/src/roster-editor/src/Struct/Portrait.elm @@ -2,7 +2,7 @@ module Struct.Portrait exposing ( Type, Ref, - none, + default, get_id, get_name, get_body_id, @@ -36,8 +36,8 @@ type alias Ref = String -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- -none : Type -none = +default : Type +default = { id = "cat", name = "Black Cat", diff --git a/src/roster-editor/src/Struct/ServerReply.elm b/src/roster-editor/src/Struct/ServerReply.elm index 5b66b63..4d592f5 100644 --- a/src/roster-editor/src/Struct/ServerReply.elm +++ b/src/roster-editor/src/Struct/ServerReply.elm @@ -24,7 +24,7 @@ type Type = | AddGlyphBoard Struct.GlyphBoard.Type | AddPortrait Struct.Portrait.Type | AddWeapon Struct.Weapon.Type - | AddCharacter (Struct.Character.Type, Int, Int, Int) + | AddCharacter (Struct.Character.Type, String, Int, Int, Int) -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- diff --git a/src/roster-editor/src/Struct/WeaponSet.elm b/src/roster-editor/src/Struct/WeaponSet.elm index de96daf..ac483fe 100644 --- a/src/roster-editor/src/Struct/WeaponSet.elm +++ b/src/roster-editor/src/Struct/WeaponSet.elm @@ -3,7 +3,9 @@ module Struct.WeaponSet exposing Type, new, get_active_weapon, + set_active_weapon, get_secondary_weapon, + set_secondary_weapon, switch_weapons ) @@ -32,8 +34,14 @@ new wp0 wp1 = { active = wp0, secondary = wp1 } get_active_weapon : Type -> Struct.Weapon.Type get_active_weapon set = set.active +set_active_weapon : Struct.Weapon.Type -> Type -> Type +set_active_weapon weapon set = {set | active = weapon} + get_secondary_weapon : Type -> Struct.Weapon.Type get_secondary_weapon set = set.secondary +set_secondary_weapon : Struct.Weapon.Type -> Type -> Type +set_secondary_weapon weapon set = {set | secondary = weapon} + switch_weapons : Type -> Type switch_weapons set = {set | active = set.secondary, secondary = set.active} diff --git a/src/roster-editor/src/Update/HandleServerReply.elm b/src/roster-editor/src/Update/HandleServerReply.elm index 22a2aa0..c5ad496 100644 --- a/src/roster-editor/src/Update/HandleServerReply.elm +++ b/src/roster-editor/src/Update/HandleServerReply.elm @@ -24,6 +24,7 @@ import Struct.Model import Struct.Portrait import Struct.ServerReply import Struct.Weapon +import Struct.WeaponSet -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -44,6 +45,16 @@ armor_getter model ref = (Just w) -> w Nothing -> Struct.Armor.none +portrait_getter : ( + Struct.Model.Type -> + Struct.Portrait.Ref -> + Struct.Portrait.Type + ) +portrait_getter model ref = + case (Dict.get ref model.portraits) of + (Just w) -> w + Nothing -> Struct.Portrait.default + ----------- disconnected : ( @@ -126,20 +137,33 @@ set_inventory inv current_state = ({model | inventory = inv}, cmds) add_character : ( - (Struct.Character.Type, Int, Int, Int) -> + (Struct.Character.Type, String, Int, Int, Int) -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) -> (Struct.Model.Type, (List (Cmd Struct.Event.Type))) ) add_character char_and_refs current_state = let (model, cmds) = current_state - (char, awp_ref, swp_ref, ar_ref) = char_and_refs + (char, prt_ref, awp_ref, swp_ref, ar_ref) = char_and_refs + prt = (portrait_getter model prt_ref) awp = (weapon_getter model awp_ref) swp = (weapon_getter model swp_ref) ar = (armor_getter model ar_ref) in ( - (Struct.Model.add_character char model), + (Struct.Model.add_character + (Struct.Character.set_armor + ar + (Struct.Character.set_weapons + (Struct.WeaponSet.new awp swp) + (Struct.Character.set_portrait + prt + char + ) + ) + ) + model + ), cmds ) diff --git a/src/roster-editor/src/Update/SetArmor.elm b/src/roster-editor/src/Update/SetArmor.elm index ee87f60..31b8291 100644 --- a/src/roster-editor/src/Update/SetArmor.elm +++ b/src/roster-editor/src/Update/SetArmor.elm @@ -1,9 +1,11 @@ module Update.SetArmor exposing (apply_to) -- Elm ------------------------------------------------------------------------- +import Dict -- Roster Editor --------------------------------------------------------------- import Struct.Armor +import Struct.Character import Struct.Error import Struct.Event import Struct.Model @@ -23,17 +25,13 @@ apply_to : ( apply_to model ref = ( ( - case model.edited_char of - (Just char) -> + case (model.edited_char, (Dict.get ref model.armors)) of + ((Just char), (Just armor)) -> {model | - edited_char = - (Just - ) + edited_char = (Just (Struct.Character.set_armor armor char)) } - Nothing -> - ... error - + _ -> model ), Cmd.none ) diff --git a/src/roster-editor/src/Update/SetGlyph.elm b/src/roster-editor/src/Update/SetGlyph.elm new file mode 100644 index 0000000..00d0ba8 --- /dev/null +++ b/src/roster-editor/src/Update/SetGlyph.elm @@ -0,0 +1,41 @@ +module Update.SetGlyph exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Roster Editor --------------------------------------------------------------- +import Struct.Character +import Struct.Error +import Struct.Event +import Struct.Glyph +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Glyph.Ref -> + Int -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model ref index = + ( + ( + case (model.edited_char, (Dict.get ref model.glyphs)) of + ((Just char), (Just glyph)) -> + {model | + edited_char = + (Just + (Struct.Character.set_glyph index glyph char) + ) + } + + _ -> model + ), + Cmd.none + ) diff --git a/src/roster-editor/src/Update/SetGlyphBoard.elm b/src/roster-editor/src/Update/SetGlyphBoard.elm new file mode 100644 index 0000000..bac0469 --- /dev/null +++ b/src/roster-editor/src/Update/SetGlyphBoard.elm @@ -0,0 +1,40 @@ +module Update.SetGlyphBoard exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Roster Editor --------------------------------------------------------------- +import Struct.Character +import Struct.Error +import Struct.Event +import Struct.GlyphBoard +import Struct.Model + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.GlyphBoard.Ref -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model ref = + ( + ( + case (model.edited_char, (Dict.get ref model.glyph_boards)) of + ((Just char), (Just glyph_board)) -> + {model | + edited_char = + (Just + (Struct.Character.set_glyph_board glyph_board char) + ) + } + + _ -> model + ), + Cmd.none + ) diff --git a/src/roster-editor/src/Update/SetPortrait.elm b/src/roster-editor/src/Update/SetPortrait.elm new file mode 100644 index 0000000..236da59 --- /dev/null +++ b/src/roster-editor/src/Update/SetPortrait.elm @@ -0,0 +1,38 @@ +module Update.SetPortrait exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Roster Editor --------------------------------------------------------------- +import Struct.Character +import Struct.Error +import Struct.Event +import Struct.Model +import Struct.Portrait + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Portrait.Ref -> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model ref = + ( + ( + case (model.edited_char, (Dict.get ref model.portraits)) of + ((Just char), (Just portrait)) -> + {model | + edited_char = + (Just (Struct.Character.set_portrait portrait char)) + } + + _ -> model + ), + Cmd.none + ) diff --git a/src/roster-editor/src/Update/SetWeapon.elm b/src/roster-editor/src/Update/SetWeapon.elm new file mode 100644 index 0000000..77e46ec --- /dev/null +++ b/src/roster-editor/src/Update/SetWeapon.elm @@ -0,0 +1,57 @@ +module Update.SetWeapon exposing (apply_to) + +-- Elm ------------------------------------------------------------------------- +import Dict + +-- Roster Editor --------------------------------------------------------------- +import Struct.Character +import Struct.Error +import Struct.Event +import Struct.Model +import Struct.Weapon +import Struct.WeaponSet + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : ( + Struct.Model.Type -> + Struct.Weapon.Ref -> + Bool-> + (Struct.Model.Type, (Cmd Struct.Event.Type)) + ) +apply_to model ref is_main = + ( + ( + case (model.edited_char, (Dict.get ref model.weapons)) of + ((Just char), (Just weapon)) -> + {model | + edited_char = + (Just + (Struct.Character.set_weapons + ( + if (is_main) + then + (Struct.WeaponSet.set_active_weapon + weapon + (Struct.Character.get_weapons char) + ) + else + (Struct.WeaponSet.set_secondary_weapon + weapon + (Struct.Character.get_weapons char) + ) + ) + char + ) + ) + } + + _ -> model + ), + Cmd.none + ) diff --git a/src/roster-editor/src/View/Character.elm b/src/roster-editor/src/View/Character.elm index 91f6424..93c71ad 100644 --- a/src/roster-editor/src/View/Character.elm +++ b/src/roster-editor/src/View/Character.elm @@ -12,6 +12,7 @@ import Html.Attributes import Struct.Armor import Struct.Character import Struct.Event +import Struct.Portrait -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- @@ -33,7 +34,10 @@ get_icon_head_html char = [ (Html.Attributes.class "character-icon-head"), (Html.Attributes.class - ("asset-character-icon-" ++ (Struct.Character.get_portrait_id char)) + ( + "asset-character-icon-" + ++ (Struct.Armor.get_image_id (Struct.Character.get_armor char)) + ) ) ] [ @@ -48,7 +52,7 @@ get_portrait_body_html char = (Html.Attributes.class ( "asset-character-portrait-" - ++ (Struct.Character.get_portrait_id char) + ++ (Struct.Portrait.get_id (Struct.Character.get_portrait char)) ) ) ] @@ -70,8 +74,11 @@ get_portrait_armor_html char = ), (Html.Attributes.class ( - "asset-armor-variation-0" - -- TODO: link this to the portrait. + "asset-armor-variation-" + ++ + (Struct.Portrait.get_body_id + (Struct.Character.get_portrait char) + ) ) ) ] |