From ad9c08f02cc130540f8bfbab216b82169d0c0956 Mon Sep 17 00:00:00 2001 From: nsensfel Date: Thu, 22 Feb 2018 11:36:23 +0100 Subject: Stores weapons dataset in model. --- src/battlemap/src/Data/Tile.elm | 15 - src/battlemap/src/Data/Tiles.elm | 15 + src/battlemap/src/Data/Weapon.elm | 309 --------------------- src/battlemap/src/Data/Weapons.elm | 309 +++++++++++++++++++++ src/battlemap/src/ElmModule/Init.elm | 4 +- src/battlemap/src/Shim/Model.elm | 28 -- src/battlemap/src/Struct/Model.elm | 18 ++ src/battlemap/src/Struct/Weapon.elm | 3 + .../src/Update/HandleServerReply/AddChar.elm | 29 +- .../src/Update/HandleServerReply/SetMap.elm | 6 +- 10 files changed, 367 insertions(+), 369 deletions(-) delete mode 100644 src/battlemap/src/Data/Tile.elm create mode 100644 src/battlemap/src/Data/Tiles.elm delete mode 100644 src/battlemap/src/Data/Weapon.elm create mode 100644 src/battlemap/src/Data/Weapons.elm delete mode 100644 src/battlemap/src/Shim/Model.elm (limited to 'src') diff --git a/src/battlemap/src/Data/Tile.elm b/src/battlemap/src/Data/Tile.elm deleted file mode 100644 index 43606aa..0000000 --- a/src/battlemap/src/Data/Tile.elm +++ /dev/null @@ -1,15 +0,0 @@ -module Data.Tile exposing (..) - -import Constants.Movement - -get_icon : Int -> String -get_icon i = - toString(i) - -get_cost : Int -> Int -get_cost i = - if (i <= 200) - then - (i + 8) - else - Constants.Movement.cost_when_out_of_bounds diff --git a/src/battlemap/src/Data/Tiles.elm b/src/battlemap/src/Data/Tiles.elm new file mode 100644 index 0000000..eb2dd61 --- /dev/null +++ b/src/battlemap/src/Data/Tiles.elm @@ -0,0 +1,15 @@ +module Data.Tiles exposing (..) + +import Constants.Movement + +get_icon : Int -> String +get_icon i = + toString(i) + +get_cost : Int -> Int +get_cost i = + if (i <= 200) + then + (i + 8) + else + Constants.Movement.cost_when_out_of_bounds diff --git a/src/battlemap/src/Data/Weapon.elm b/src/battlemap/src/Data/Weapon.elm deleted file mode 100644 index 7d81bf8..0000000 --- a/src/battlemap/src/Data/Weapon.elm +++ /dev/null @@ -1,309 +0,0 @@ -module Data.Weapon exposing (generate_dict, shim_none) --- Elm ------------------------------------------------------------------------- -import Dict - --- Battlemap ------------------------------------------------------------------- -import Struct.Weapon - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- -dataset : (List (Int, Struct.Weapon.Type)) -dataset = - [ - -- TODO: have those in separate text files, and put them here only at - -- compilation. - ( - 0, - (Struct.Weapon.new - 0 - "None" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 1, - (Struct.Weapon.new - 1 - "Dagger" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Slash - Struct.Weapon.Light - ) - ), - ( - 2, - (Struct.Weapon.new - 2 - "Sword" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Slash - Struct.Weapon.Heavy - ) - ), - ( - 3, - (Struct.Weapon.new - 3 - "Claymore" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Slash - Struct.Weapon.Light - ) - ), - ( - 4, - (Struct.Weapon.new - 4 - "Bardiche" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Slash - Struct.Weapon.Heavy - ) - ), - ( - 5, - (Struct.Weapon.new - 5 - "Stiletto" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Pierce - Struct.Weapon.Light - ) - ), - ( - 6, - (Struct.Weapon.new - 6 - "Pickaxe" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Pierce - Struct.Weapon.Heavy - ) - ), - ( - 7, - (Struct.Weapon.new - 7 - "Rapier" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Pierce - Struct.Weapon.Light - ) - ), - ( - 8, - (Struct.Weapon.new - 8 - "Pike" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Pierce - Struct.Weapon.Heavy - ) - ), - ( - 9, - (Struct.Weapon.new - 9 - "Club" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 10, - (Struct.Weapon.new - 10 - "Mace" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Heavy - ) - ), - ( - 11, - (Struct.Weapon.new - 11 - "Staff" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 12, - (Struct.Weapon.new - 12 - "War Hammer" - Struct.Weapon.Melee - Struct.Weapon.Long - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 13, - (Struct.Weapon.new - 13 - "Short Bow (Broadhead)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Slash - Struct.Weapon.Light - ) - ), - ( - 14, - (Struct.Weapon.new - 14 - "Short Bow (Blunt)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 15, - (Struct.Weapon.new - 15 - "Short Bow (Bodkin Point)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Pierce - Struct.Weapon.Light - ) - ), - ( - 16, - (Struct.Weapon.new - 16 - "Long Bow (Broadhead)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Slash - Struct.Weapon.Light - ) - ), - ( - 17, - (Struct.Weapon.new - 17 - "Long Bow (Blunt)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Blunt - Struct.Weapon.Light - ) - ), - ( - 18, - (Struct.Weapon.new - 18 - "Long Bow (Bodkin Point)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Pierce - Struct.Weapon.Light - ) - ), - ( - 19, - (Struct.Weapon.new - 19 - "Crossbow (Broadhead)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Slash - Struct.Weapon.Heavy - ) - ), - ( - 20, - (Struct.Weapon.new - 20 - "Crossbow (Blunt)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Heavy - ) - ), - ( - 21, - (Struct.Weapon.new - 21 - "Crossbow (Bodkin Point)" - Struct.Weapon.Ranged - Struct.Weapon.Short - Struct.Weapon.Pierce - Struct.Weapon.Heavy - ) - ), - ( - 19, - (Struct.Weapon.new - 19 - "Arbalest (Broadhead)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Slash - Struct.Weapon.Heavy - ) - ), - ( - 20, - (Struct.Weapon.new - 20 - "Arbalest (Blunt)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Blunt - Struct.Weapon.Heavy - ) - ), - ( - 21, - (Struct.Weapon.new - 21 - "Arbalest (Bodkin Point)" - Struct.Weapon.Ranged - Struct.Weapon.Long - Struct.Weapon.Pierce - Struct.Weapon.Heavy - ) - ) - ] - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- -generate_dict : (Dict.Dict Int Struct.Weapon.Type) -generate_dict = (Dict.fromList dataset) - --- Let's not handle the dict just yet. -shim_none : (Struct.Weapon.Type) -shim_none = - (Struct.Weapon.new - 0 - "None" - Struct.Weapon.Melee - Struct.Weapon.Short - Struct.Weapon.Blunt - Struct.Weapon.Light - ) diff --git a/src/battlemap/src/Data/Weapons.elm b/src/battlemap/src/Data/Weapons.elm new file mode 100644 index 0000000..35d3fc7 --- /dev/null +++ b/src/battlemap/src/Data/Weapons.elm @@ -0,0 +1,309 @@ +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" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 1, + (Struct.Weapon.new + 1 + "Dagger" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Slash + Struct.Weapon.Light + ) + ), + ( + 2, + (Struct.Weapon.new + 2 + "Sword" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Slash + Struct.Weapon.Heavy + ) + ), + ( + 3, + (Struct.Weapon.new + 3 + "Claymore" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Slash + Struct.Weapon.Light + ) + ), + ( + 4, + (Struct.Weapon.new + 4 + "Bardiche" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Slash + Struct.Weapon.Heavy + ) + ), + ( + 5, + (Struct.Weapon.new + 5 + "Stiletto" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Pierce + Struct.Weapon.Light + ) + ), + ( + 6, + (Struct.Weapon.new + 6 + "Pickaxe" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Pierce + Struct.Weapon.Heavy + ) + ), + ( + 7, + (Struct.Weapon.new + 7 + "Rapier" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Pierce + Struct.Weapon.Light + ) + ), + ( + 8, + (Struct.Weapon.new + 8 + "Pike" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Pierce + Struct.Weapon.Heavy + ) + ), + ( + 9, + (Struct.Weapon.new + 9 + "Club" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 10, + (Struct.Weapon.new + 10 + "Mace" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Heavy + ) + ), + ( + 11, + (Struct.Weapon.new + 11 + "Staff" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 12, + (Struct.Weapon.new + 12 + "War Hammer" + Struct.Weapon.Melee + Struct.Weapon.Long + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 13, + (Struct.Weapon.new + 13 + "Short Bow (Broadhead)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Slash + Struct.Weapon.Light + ) + ), + ( + 14, + (Struct.Weapon.new + 14 + "Short Bow (Blunt)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 15, + (Struct.Weapon.new + 15 + "Short Bow (Bodkin Point)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Pierce + Struct.Weapon.Light + ) + ), + ( + 16, + (Struct.Weapon.new + 16 + "Long Bow (Broadhead)" + Struct.Weapon.Ranged + Struct.Weapon.Long + Struct.Weapon.Slash + Struct.Weapon.Light + ) + ), + ( + 17, + (Struct.Weapon.new + 17 + "Long Bow (Blunt)" + Struct.Weapon.Ranged + Struct.Weapon.Long + Struct.Weapon.Blunt + Struct.Weapon.Light + ) + ), + ( + 18, + (Struct.Weapon.new + 18 + "Long Bow (Bodkin Point)" + Struct.Weapon.Ranged + Struct.Weapon.Long + Struct.Weapon.Pierce + Struct.Weapon.Light + ) + ), + ( + 19, + (Struct.Weapon.new + 19 + "Crossbow (Broadhead)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Slash + Struct.Weapon.Heavy + ) + ), + ( + 20, + (Struct.Weapon.new + 20 + "Crossbow (Blunt)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Heavy + ) + ), + ( + 21, + (Struct.Weapon.new + 21 + "Crossbow (Bodkin Point)" + Struct.Weapon.Ranged + Struct.Weapon.Short + Struct.Weapon.Pierce + Struct.Weapon.Heavy + ) + ), + ( + 19, + (Struct.Weapon.new + 19 + "Arbalest (Broadhead)" + Struct.Weapon.Ranged + Struct.Weapon.Long + Struct.Weapon.Slash + Struct.Weapon.Heavy + ) + ), + ( + 20, + (Struct.Weapon.new + 20 + "Arbalest (Blunt)" + Struct.Weapon.Ranged + Struct.Weapon.Long + Struct.Weapon.Blunt + Struct.Weapon.Heavy + ) + ), + ( + 21, + (Struct.Weapon.new + 21 + "Arbalest (Bodkin Point)" + 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" + Struct.Weapon.Melee + Struct.Weapon.Short + Struct.Weapon.Blunt + Struct.Weapon.Light + ) diff --git a/src/battlemap/src/ElmModule/Init.elm b/src/battlemap/src/ElmModule/Init.elm index f7885e4..136a828 100644 --- a/src/battlemap/src/ElmModule/Init.elm +++ b/src/battlemap/src/ElmModule/Init.elm @@ -3,8 +3,6 @@ module ElmModule.Init exposing (init) -- Battlemap ------------------------------------------------------------------- import Send.LoadBattlemap -import Shim.Model - import Struct.Event import Struct.Model @@ -18,7 +16,7 @@ import Struct.Model init : (Struct.Model.Type, (Cmd Struct.Event.Type)) init = let - model = (Shim.Model.generate) + model = (Struct.Model.new) in ( model, diff --git a/src/battlemap/src/Shim/Model.elm b/src/battlemap/src/Shim/Model.elm deleted file mode 100644 index 30bdc95..0000000 --- a/src/battlemap/src/Shim/Model.elm +++ /dev/null @@ -1,28 +0,0 @@ -module Shim.Model exposing (generate) - --- Elm ------------------------------------------------------------------------- -import Dict - --- Struct.Battlemap ------------------------------------------------------------------- -import Struct.Battlemap -import Struct.CharacterTurn -import Struct.UI - --------------------------------------------------------------------------------- --- LOCAL ----------------------------------------------------------------------- --------------------------------------------------------------------------------- - --------------------------------------------------------------------------------- --- EXPORTED -------------------------------------------------------------------- --------------------------------------------------------------------------------- ---generate : Struct.Model.Type -generate = - { - battlemap = (Struct.Battlemap.empty), - characters = (Dict.empty), - error = Nothing, - controlled_team = 0, - player_id = "0", - ui = (Struct.UI.default), - char_turn = (Struct.CharacterTurn.new) - } diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index 9d4e128..fc13655 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -1,6 +1,7 @@ module Struct.Model exposing ( Type, + new, add_character, invalidate, reset, @@ -11,11 +12,14 @@ module Struct.Model exposing import Dict -- Battlemap ------------------------------------------------------------------- +import Data.Weapons + import Struct.Battlemap import Struct.Character import Struct.CharacterTurn import Struct.Error import Struct.UI +import Struct.Weapon -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -24,6 +28,7 @@ type alias Type = { battlemap: Struct.Battlemap.Type, characters: (Dict.Dict Struct.Character.Ref Struct.Character.Type), + weapons: (Dict.Dict Struct.Weapon.Ref Struct.Weapon.Type), error: (Maybe Struct.Error.Type), controlled_team: Int, player_id: String, @@ -38,6 +43,19 @@ type alias Type = -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- +new : Type +new = + { + battlemap = (Struct.Battlemap.empty), + characters = (Dict.empty), + weapons = (Data.Weapons.generate_dict), + error = Nothing, + controlled_team = 0, + player_id = "0", + ui = (Struct.UI.default), + char_turn = (Struct.CharacterTurn.new) + } + add_character : Type -> Struct.Character.Type -> Type add_character model char = {model | diff --git a/src/battlemap/src/Struct/Weapon.elm b/src/battlemap/src/Struct/Weapon.elm index 02afb22..5741a2a 100644 --- a/src/battlemap/src/Struct/Weapon.elm +++ b/src/battlemap/src/Struct/Weapon.elm @@ -1,6 +1,7 @@ module Struct.Weapon exposing ( Type, + Ref, RangeType(..), RangeModifier(..), DamageType(..), @@ -38,6 +39,8 @@ type alias Type = dmg_max : Int } +type alias Ref = Int + type RangeType = Ranged | Melee type RangeModifier = Long | Short -- Having multiple types at the same time, like Warframe does, would be nice. diff --git a/src/battlemap/src/Update/HandleServerReply/AddChar.elm b/src/battlemap/src/Update/HandleServerReply/AddChar.elm index 4d6b3d8..071be3a 100644 --- a/src/battlemap/src/Update/HandleServerReply/AddChar.elm +++ b/src/battlemap/src/Update/HandleServerReply/AddChar.elm @@ -1,11 +1,13 @@ module Update.HandleServerReply.AddChar exposing (apply_to) -- Elm ------------------------------------------------------------------------- +import Dict + import Json.Decode import Json.Decode.Pipeline -- Battlemap ------------------------------------------------------------------- -import Data.Weapon +import Data.Weapons import Struct.Attributes import Struct.Character @@ -39,8 +41,7 @@ type alias CharData = enabled : Bool, att : CharAtt, wp_0 : Int, - wp_1 : Int, - act_wp : Int + wp_1 : Int } -------------------------------------------------------------------------------- @@ -74,7 +75,6 @@ char_decoder = |> (Json.Decode.Pipeline.required "att" attributes_decoder) |> (Json.Decode.Pipeline.required "wp_0" Json.Decode.int) |> (Json.Decode.Pipeline.required "wp_1" Json.Decode.int) - |> (Json.Decode.Pipeline.required "act_wp" Json.Decode.int) ) -------------------------------------------------------------------------------- @@ -109,13 +109,20 @@ apply_to model serialized_char = char_data.att.str ) ( - let - wp_0 = (Data.Weapon.shim_none) - wp_1 = (Data.Weapon.shim_none) - in - case char_data.act_wp of - 0 -> (Struct.WeaponSet.new wp_0 wp_1) - _ -> (Struct.WeaponSet.new wp_1 wp_0) + case + ( + (Dict.get char_data.wp_0 model.weapons), + (Dict.get char_data.wp_1 model.weapons) + ) + of + ((Just wp_0), (Just wp_1)) -> + (Struct.WeaponSet.new wp_0 wp_1) + + _ -> + (Struct.WeaponSet.new + (Data.Weapons.none) + (Data.Weapons.none) + ) ) ) ) diff --git a/src/battlemap/src/Update/HandleServerReply/SetMap.elm b/src/battlemap/src/Update/HandleServerReply/SetMap.elm index f902493..e7c993d 100644 --- a/src/battlemap/src/Update/HandleServerReply/SetMap.elm +++ b/src/battlemap/src/Update/HandleServerReply/SetMap.elm @@ -5,7 +5,7 @@ import Dict import Json.Decode -- Battlemap ------------------------------------------------------------------- -import Data.Tile +import Data.Tiles import Struct.Battlemap import Struct.Model @@ -29,8 +29,8 @@ deserialize_tile map_width index id = (Struct.Tile.new (index % map_width) (index // map_width) - (Data.Tile.get_icon id) - (Data.Tile.get_cost id) + (Data.Tiles.get_icon id) + (Data.Tiles.get_cost id) ) -------------------------------------------------------------------------------- -- cgit v1.2.3-70-g09d2