summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-06-07 23:15:42 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-06-07 23:15:42 +0200
commit57fea6c1508231883180bd0480870292f2906eb4 (patch)
tree6d70f9975333e6ec1bbf442a78c711ab444b125f
parent74d7c55569915430c8f4e60b1f19fcbc3f7cafda (diff)
add_armor, add_weapon, server-side chosen armor.
Not tested.
-rw-r--r--src/battlemap/src/Comm/AddArmor.elm26
-rw-r--r--src/battlemap/src/Comm/AddChar.elm7
-rw-r--r--src/battlemap/src/Comm/AddWeapon.elm26
-rw-r--r--src/battlemap/src/Data/Armors.elm77
-rw-r--r--src/battlemap/src/Data/Weapons.elm335
-rw-r--r--src/battlemap/src/Struct/Armor.elm52
-rw-r--r--src/battlemap/src/Struct/Character.elm6
-rw-r--r--src/battlemap/src/Struct/Model.elm33
-rw-r--r--src/battlemap/src/Struct/ServerReply.elm4
-rw-r--r--src/battlemap/src/Struct/Weapon.elm78
-rw-r--r--src/battlemap/src/Update/HandleServerReply.elm37
11 files changed, 248 insertions, 433 deletions
diff --git a/src/battlemap/src/Comm/AddArmor.elm b/src/battlemap/src/Comm/AddArmor.elm
new file mode 100644
index 0000000..7633521
--- /dev/null
+++ b/src/battlemap/src/Comm/AddArmor.elm
@@ -0,0 +1,26 @@
+module Comm.AddArmor exposing (decode)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Armor
+import Struct.Model
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+internal_decoder : Struct.Armor.Type -> Struct.ServerReply.Type
+internal_decoder wp = (Struct.ServerReply.AddArmor wp)
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+decode : (Struct.Model.Type -> (Json.Decode.Decoder Struct.ServerReply.Type))
+decode model =
+ (Json.Decode.map (internal_decoder) (Struct.Armor.decoder))
diff --git a/src/battlemap/src/Comm/AddChar.elm b/src/battlemap/src/Comm/AddChar.elm
index 5a0303f..475600e 100644
--- a/src/battlemap/src/Comm/AddChar.elm
+++ b/src/battlemap/src/Comm/AddChar.elm
@@ -6,9 +6,6 @@ import Dict
import Json.Decode
-- Battlemap -------------------------------------------------------------------
-import Data.Armors
-import Data.Weapons
-
import Struct.Armor
import Struct.Character
import Struct.Model
@@ -26,13 +23,13 @@ weapon_getter : Struct.Model.Type -> Struct.Weapon.Ref -> Struct.Weapon.Type
weapon_getter model ref =
case (Dict.get ref model.weapons) of
(Just w) -> w
- Nothing -> Data.Weapons.none
+ Nothing -> Struct.Weapon.none
armor_getter : Struct.Model.Type -> Struct.Armor.Ref -> Struct.Armor.Type
armor_getter model ref =
case (Dict.get ref model.armors) of
(Just w) -> w
- Nothing -> Data.Armors.none
+ Nothing -> Struct.Armor.none
internal_decoder : Struct.Character.Type -> Struct.ServerReply.Type
internal_decoder char = (Struct.ServerReply.AddCharacter char)
diff --git a/src/battlemap/src/Comm/AddWeapon.elm b/src/battlemap/src/Comm/AddWeapon.elm
new file mode 100644
index 0000000..4c74111
--- /dev/null
+++ b/src/battlemap/src/Comm/AddWeapon.elm
@@ -0,0 +1,26 @@
+module Comm.AddWeapon exposing (decode)
+
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Weapon
+import Struct.Model
+import Struct.ServerReply
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+internal_decoder : Struct.Armor.Type -> Struct.ServerReply.Type
+internal_decoder wp = (Struct.ServerReply.AddWeapon wp)
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+decode : (Struct.Model.Type -> (Json.Decode.Decoder Struct.ServerReply.Type))
+decode model =
+ (Json.Decode.map (internal_decoder) (Struct.Weapon.decoder))
diff --git a/src/battlemap/src/Data/Armors.elm b/src/battlemap/src/Data/Armors.elm
deleted file mode 100644
index 1033945..0000000
--- a/src/battlemap/src/Data/Armors.elm
+++ /dev/null
@@ -1,77 +0,0 @@
-module Data.Armors exposing (generate_dict, none)
--- Elm -------------------------------------------------------------------------
-import Dict
-
--- Battlemap -------------------------------------------------------------------
-import Struct.Armor
-
---------------------------------------------------------------------------------
--- LOCAL -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-dataset : (List (Struct.Armor.Ref, Struct.Armor.Type))
-dataset =
- [
- -- TODO: have those in separate text files, and put them here only at
- -- compilation.
- (
- 0,
- (Struct.Armor.new
- 0
- "None"
- Struct.Armor.Leather
- 0.0
- )
- ),
- (
- 1,
- (Struct.Armor.new
- 1
- "Last Meal's Pelts"
- Struct.Armor.Leather
- 0.5
- )
- ),
- (
- 2,
- (Struct.Armor.new
- 2
- "Bits from a Wall"
- Struct.Armor.Plate
- 0.5
- )
- ),
- (
- 3,
- (Struct.Armor.new
- 3
- "Some Garden Fence"
- Struct.Armor.Chain
- 0.5
- )
- ),
- (
- 4,
- (Struct.Armor.new
- 4
- "Morrigan's Pity"
- Struct.Armor.Kinetic
- 0.5
- )
- )
- ]
-
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-generate_dict : (Dict.Dict Struct.Armor.Ref Struct.Armor.Type)
-generate_dict = (Dict.fromList dataset)
-
--- If it's not found.
-none : (Struct.Armor.Type)
-none =
- (Struct.Armor.new
- 0
- "None"
- Struct.Armor.Leather
- 0.0
- )
diff --git a/src/battlemap/src/Data/Weapons.elm b/src/battlemap/src/Data/Weapons.elm
deleted file mode 100644
index 03ce4a1..0000000
--- a/src/battlemap/src/Data/Weapons.elm
+++ /dev/null
@@ -1,335 +0,0 @@
-module Data.Weapons exposing (generate_dict, none)
--- Elm -------------------------------------------------------------------------
-import Dict
-
--- Battlemap -------------------------------------------------------------------
-import Struct.Weapon
-
---------------------------------------------------------------------------------
--- LOCAL -----------------------------------------------------------------------
---------------------------------------------------------------------------------
-dataset : (List (Struct.Weapon.Ref, Struct.Weapon.Type))
-dataset =
- [
- -- TODO: have those in separate text files, and put them here only at
- -- compilation.
- (
- 0,
- (Struct.Weapon.new
- 0
- "None"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
- ),
- (
- 1,
- (Struct.Weapon.new
- 1
- "Dagger"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Slash
- Struct.Weapon.Light
- )
- ),
- (
- 2,
- (Struct.Weapon.new
- 2
- "Sword"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Slash
- Struct.Weapon.Heavy
- )
- ),
- (
- 3,
- (Struct.Weapon.new
- 3
- "Claymore"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Slash
- Struct.Weapon.Light
- )
- ),
- (
- 4,
- (Struct.Weapon.new
- 4
- "Bardiche"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Slash
- Struct.Weapon.Heavy
- )
- ),
- (
- 5,
- (Struct.Weapon.new
- 5
- "Stiletto"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Pierce
- Struct.Weapon.Light
- )
- ),
- (
- 6,
- (Struct.Weapon.new
- 6
- "Pickaxe"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Pierce
- Struct.Weapon.Heavy
- )
- ),
- (
- 7,
- (Struct.Weapon.new
- 7
- "Rapier"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Pierce
- Struct.Weapon.Light
- )
- ),
- (
- 8,
- (Struct.Weapon.new
- 8
- "Pike"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Pierce
- Struct.Weapon.Heavy
- )
- ),
- (
- 9,
- (Struct.Weapon.new
- 9
- "Club"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
- ),
- (
- 10,
- (Struct.Weapon.new
- 10
- "Mace"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Heavy
- )
- ),
- (
- 11,
- (Struct.Weapon.new
- 11
- "Staff"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
- ),
- (
- 12,
- (Struct.Weapon.new
- 12
- "War Hammer"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Long
- Struct.Weapon.Blunt
- Struct.Weapon.Heavy
- )
- ),
- (
- 13,
- (Struct.Weapon.new
- 13
- "Short Bow (Broadhead)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Slash
- Struct.Weapon.Light
- )
- ),
- (
- 14,
- (Struct.Weapon.new
- 14
- "Short Bow (Blunt)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
- ),
- (
- 15,
- (Struct.Weapon.new
- 15
- "Short Bow (Bodkin Point)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Pierce
- Struct.Weapon.Light
- )
- ),
- (
- 16,
- (Struct.Weapon.new
- 16
- "Long Bow (Broadhead)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Slash
- Struct.Weapon.Light
- )
- ),
- (
- 17,
- (Struct.Weapon.new
- 17
- "Long Bow (Blunt)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
- ),
- (
- 18,
- (Struct.Weapon.new
- 18
- "Long Bow (Bodkin Point)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Pierce
- Struct.Weapon.Light
- )
- ),
- (
- 19,
- (Struct.Weapon.new
- 19
- "Crossbow (Broadhead)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Slash
- Struct.Weapon.Heavy
- )
- ),
- (
- 20,
- (Struct.Weapon.new
- 20
- "Crossbow (Blunt)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Heavy
- )
- ),
- (
- 21,
- (Struct.Weapon.new
- 21
- "Crossbow (Bodkin Point)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Short
- Struct.Weapon.Pierce
- Struct.Weapon.Heavy
- )
- ),
- (
- 22,
- (Struct.Weapon.new
- 22
- "Arbalest (Broadhead)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Slash
- Struct.Weapon.Heavy
- )
- ),
- (
- 23,
- (Struct.Weapon.new
- 23
- "Arbalest (Blunt)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Blunt
- Struct.Weapon.Heavy
- )
- ),
- (
- 24,
- (Struct.Weapon.new
- 24
- "Arbalest (Bodkin Point)"
- 1.0
- Struct.Weapon.Ranged
- Struct.Weapon.Long
- Struct.Weapon.Pierce
- Struct.Weapon.Heavy
- )
- )
- ]
-
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-generate_dict : (Dict.Dict Struct.Weapon.Ref Struct.Weapon.Type)
-generate_dict = (Dict.fromList dataset)
-
--- If it's not found.
-none : (Struct.Weapon.Type)
-none =
- (Struct.Weapon.new
- 0
- "None"
- 1.0
- Struct.Weapon.Melee
- Struct.Weapon.Short
- Struct.Weapon.Blunt
- Struct.Weapon.Light
- )
diff --git a/src/battlemap/src/Struct/Armor.elm b/src/battlemap/src/Struct/Armor.elm
index 141204c..d6dcd67 100644
--- a/src/battlemap/src/Struct/Armor.elm
+++ b/src/battlemap/src/Struct/Armor.elm
@@ -9,9 +9,15 @@ module Struct.Armor exposing
get_category,
get_resistance_to,
get_image_id,
+ decoder,
+ none,
apply_to_attributes
)
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
-- Battlemap -------------------------------------------------------------------
import Struct.Attributes
import Struct.Weapon
@@ -19,6 +25,14 @@ import Struct.Weapon
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
+type alias PartiallyDecoded =
+ {
+ id : Int,
+ nam : String,
+ ct : String,
+ cf : Float
+ }
+
type alias Type =
{
id : Int,
@@ -109,3 +123,41 @@ apply_to_attributes ar atts =
(Struct.Attributes.mod_strength impact atts)
)
)
+
+finish_decoding : PartiallyDecoded -> Type
+finish_decoding add_armor =
+ {
+ id = add_armor.id,
+ name = add_armor.nam,
+ category =
+ (
+ case add_armor.ct of
+ "k" -> Kinetic
+ "c" -> Chain
+ "p" -> Plate
+ _ -> Leather
+ ),
+ coef = add_armor.cf
+ }
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.map
+ (finish_decoding)
+ (Json.Decode.Pipeline.decode
+ PartiallyDecoded
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "ct" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "coef" Json.Decode.float)
+ )
+ )
+
+none : Type
+none =
+ (new
+ 0
+ "None"
+ Leather
+ 0.0
+ )
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm
index 552f213..00abc52 100644
--- a/src/battlemap/src/Struct/Character.elm
+++ b/src/battlemap/src/Struct/Character.elm
@@ -50,7 +50,8 @@ type alias PartiallyDecoded =
ena : Bool,
att : Struct.Attributes.Type,
awp : Int,
- swp : Int
+ swp : Int,
+ ar : Int
}
type alias Type =
@@ -85,7 +86,7 @@ finish_decoding get_weapon get_armor add_char =
active_weapon = (get_weapon add_char.awp)
secondary_weapon = (get_weapon add_char.swp)
weapon_set = (Struct.WeaponSet.new active_weapon secondary_weapon)
- armor = (get_armor (add_char.ix % 4))
+ armor = (get_armor add_char.ar)
act_atts = (Struct.Armor.apply_to_attributes armor add_char.att)
in
{
@@ -190,5 +191,6 @@ decoder get_weapon get_armor =
|> (Json.Decode.Pipeline.required "att" (Struct.Attributes.decoder))
|> (Json.Decode.Pipeline.required "awp" Json.Decode.int)
|> (Json.Decode.Pipeline.required "swp" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "ar" Json.Decode.int)
)
)
diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm
index d75958e..e49ab1c 100644
--- a/src/battlemap/src/Struct/Model.elm
+++ b/src/battlemap/src/Struct/Model.elm
@@ -3,6 +3,8 @@ module Struct.Model exposing
Type,
new,
add_character,
+ add_weapon,
+ add_armor,
invalidate,
reset,
clear_error
@@ -13,9 +15,6 @@ import Dict
import Array
-- Battlemap -------------------------------------------------------------------
-import Data.Armors
-import Data.Weapons
-
import Struct.Armor
import Struct.Battlemap
import Struct.Character
@@ -53,8 +52,8 @@ new =
{
battlemap = (Struct.Battlemap.empty),
characters = (Dict.empty),
- weapons = (Data.Weapons.generate_dict),
- armors = (Data.Armors.generate_dict),
+ weapons = (Dict.empty),
+ armors = (Dict.empty),
error = Nothing,
player_id = "0",
ui = (Struct.UI.default),
@@ -62,7 +61,7 @@ new =
timeline = (Array.empty)
}
-add_character : Struct.Character.Type -> Type -> Type
+add_character : Struct.Character.Type -> Type -> Type
add_character char model =
{model |
characters =
@@ -73,6 +72,28 @@ add_character char model =
)
}
+add_weapon : Struct.Weapon.Type -> Type -> Type
+add_weapon wp model =
+ {model |
+ weapons =
+ (Dict.insert
+ (Struct.Weapon.get_id wp)
+ wp
+ model.weapons
+ )
+ }
+
+add_armor : Struct.Armor.Type -> Type -> Type
+add_armor ar model =
+ {model |
+ armors =
+ (Dict.insert
+ (Struct.Armor.get_id ar)
+ ar
+ model.armors
+ )
+ }
+
reset : (Dict.Dict Struct.Character.Ref Struct.Character.Type) -> Type -> Type
reset characters model =
{model |
diff --git a/src/battlemap/src/Struct/ServerReply.elm b/src/battlemap/src/Struct/ServerReply.elm
index b986abe..1e79f93 100644
--- a/src/battlemap/src/Struct/ServerReply.elm
+++ b/src/battlemap/src/Struct/ServerReply.elm
@@ -3,9 +3,11 @@ module Struct.ServerReply exposing (Type(..))
-- Elm -------------------------------------------------------------------------
-- Battlemap -------------------------------------------------------------------
+import Struct.Armor
import Struct.Battlemap
import Struct.Character
import Struct.TurnResult
+import Struct.Weapon
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -13,6 +15,8 @@ import Struct.TurnResult
type Type =
Okay
+ | AddArmor Struct.Armor.Type
+ | AddWeapon Struct.Weapon.Type
| AddCharacter Struct.Character.Type
| SetMap Struct.Battlemap.Type
| TurnResults (List Struct.TurnResult.Type)
diff --git a/src/battlemap/src/Struct/Weapon.elm b/src/battlemap/src/Struct/Weapon.elm
index ff6e52c..92b7bf4 100644
--- a/src/battlemap/src/Struct/Weapon.elm
+++ b/src/battlemap/src/Struct/Weapon.elm
@@ -7,6 +7,7 @@ module Struct.Weapon exposing
DamageType(..),
DamageModifier(..),
new,
+ get_id,
get_name,
get_range_type,
get_range_modifier,
@@ -16,15 +17,32 @@ module Struct.Weapon exposing
get_defense_range,
get_max_damage,
get_min_damage,
+ decoder,
+ none,
apply_to_attributes
)
+-- Elm -------------------------------------------------------------------------
+import Json.Decode
+import Json.Decode.Pipeline
+
-- Battlemap -------------------------------------------------------------------
import Struct.Attributes
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
+type alias PartiallyDecoded =
+ {
+ id : Int,
+ nam : String,
+ rt : String,
+ rm : String,
+ dt : String,
+ dm : String,
+ cf : Float
+ }
+
type alias Type =
{
id : Int,
@@ -110,6 +128,9 @@ new
dmg_max = dmg_max
}
+get_id : Type -> Int
+get_id wp = wp.id
+
get_name : Type -> String
get_name wp = wp.name
@@ -168,3 +189,60 @@ apply_to_attributes wp atts =
quarter_impact
(Struct.Attributes.mod_speed quarter_impact atts)
)
+
+finish_decoding : PartiallyDecoded -> Type
+finish_decoding add_weapon =
+ (new
+ add_weapon.id
+ add_weapon.nam
+ add_weapon.cf
+ (
+ case add_weapon.rt of
+ "m" -> Melee
+ _ -> Ranged
+ )
+ (
+ case add_weapon.rm of
+ "l" -> Long
+ _ -> Short
+ )
+ (
+ case add_weapon.dt of
+ "s" -> Slash
+ "p" -> Pierce
+ _ -> Blunt
+ )
+ (
+ case add_weapon.dm of
+ "l" -> Light
+ _ -> Heavy
+ )
+ )
+
+decoder : (Json.Decode.Decoder Type)
+decoder =
+ (Json.Decode.map
+ (finish_decoding)
+ (Json.Decode.Pipeline.decode
+ PartiallyDecoded
+ |> (Json.Decode.Pipeline.required "id" Json.Decode.int)
+ |> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "rt" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "rm" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "dt" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "dm" Json.Decode.string)
+ |> (Json.Decode.Pipeline.required "coef" Json.Decode.float)
+ )
+ )
+
+none : Type
+none =
+ (new
+ 0
+ "None"
+ 0.0
+ Melee
+ Short
+ Blunt
+ Light
+ )
diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm
index f0846db..c6e8461 100644
--- a/src/battlemap/src/Update/HandleServerReply.elm
+++ b/src/battlemap/src/Update/HandleServerReply.elm
@@ -6,6 +6,7 @@ import Array
import Http
-- Battlemap -------------------------------------------------------------------
+import Struct.Armor
import Struct.Battlemap
import Struct.Character
import Struct.Error
@@ -14,6 +15,7 @@ import Struct.Model
import Struct.ServerReply
import Struct.TurnResult
import Struct.UI
+import Struct.Weapon
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -22,6 +24,26 @@ import Struct.UI
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
+add_armor : (
+ Struct.Armor.Type ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type)) ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type))
+ )
+add_armor ar current_state =
+ case current_state of
+ (_, (Just _)) -> current_state
+ (model, _) -> ((Struct.Model.add_armor ar model), Nothing)
+
+add_weapon : (
+ Struct.Weapon.Type ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type)) ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type))
+ )
+add_weapon wp current_state =
+ case current_state of
+ (_, (Just _)) -> current_state
+ (model, _) -> ((Struct.Model.add_weapon wp model), Nothing)
+
add_character : (
Struct.Character.Type ->
(Struct.Model.Type, (Maybe Struct.Error.Type)) ->
@@ -30,14 +52,7 @@ add_character : (
add_character char current_state =
case current_state of
(_, (Just _)) -> current_state
- (model, _) ->
- (
- (Struct.Model.add_character
- char
- model
- ),
- Nothing
- )
+ (model, _) -> ((Struct.Model.add_character char model), Nothing)
set_map : (
Struct.Battlemap.Type ->
@@ -110,6 +125,12 @@ apply_command : (
)
apply_command command current_state =
case command of
+ (Struct.ServerReply.AddWeapon wp) ->
+ (add_weapon wp current_state)
+
+ (Struct.ServerReply.AddArmor ar) ->
+ (add_armor ar current_state)
+
(Struct.ServerReply.AddCharacter char) ->
(add_character char current_state)