summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-03-09 13:20:22 +0100 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-03-09 13:20:22 +0100 |
commit | f70077b581408825ae4810983c8b1704e0a41289 (patch) | |
tree | f4b448c7b539ca7cb4dcba2fb029eaed9ad25526 | |
parent | 3d012b25fac2c249c0ff46538672d2eee04b2707 (diff) |
New JSON decoding works, starting TurnResults...
-rw-r--r-- | src/battlemap/src/Struct/Attack.elm | 34 | ||||
-rw-r--r-- | src/battlemap/src/Struct/Model.elm | 4 | ||||
-rw-r--r-- | src/battlemap/src/Struct/ServerReply.elm | 3 | ||||
-rw-r--r-- | src/battlemap/src/Struct/TurnResult.elm | 43 | ||||
-rw-r--r-- | src/battlemap/src/Update/HandleServerReply.elm | 66 |
5 files changed, 124 insertions, 26 deletions
diff --git a/src/battlemap/src/Struct/Attack.elm b/src/battlemap/src/Struct/Attack.elm new file mode 100644 index 0000000..5159f7d --- /dev/null +++ b/src/battlemap/src/Struct/Attack.elm @@ -0,0 +1,34 @@ +module Struct.Attack exposing (Type, Order, Precision) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type Order = + First + | Counter + | Second + +type Precision = + Hit + | Graze + | Miss + +type alias Type = + { + order : Order, + precision : Precision, + parried : Bool, + damage : Int + } + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm index 2adaeba..13a516d 100644 --- a/src/battlemap/src/Struct/Model.elm +++ b/src/battlemap/src/Struct/Model.elm @@ -54,8 +54,8 @@ new = char_turn = (Struct.CharacterTurn.new) } -add_character : Type -> Struct.Character.Type -> Type -add_character model char = +add_character : Struct.Character.Type -> Type -> Type +add_character char model = {model | characters = (Dict.insert diff --git a/src/battlemap/src/Struct/ServerReply.elm b/src/battlemap/src/Struct/ServerReply.elm index 5849567..8dec96b 100644 --- a/src/battlemap/src/Struct/ServerReply.elm +++ b/src/battlemap/src/Struct/ServerReply.elm @@ -5,9 +5,9 @@ module Struct.ServerReply exposing (Type(..)) -- Battlemap ------------------------------------------------------------------- import Struct.Battlemap import Struct.Character +import Struct.TurnResult import Struct.Model - -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -16,6 +16,7 @@ type Type = Okay | AddCharacter Struct.Character.Type | SetMap Struct.Battlemap.Type + | TurnResults (List Struct.TurnResult.Type) -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- diff --git a/src/battlemap/src/Struct/TurnResult.elm b/src/battlemap/src/Struct/TurnResult.elm new file mode 100644 index 0000000..4b2b059 --- /dev/null +++ b/src/battlemap/src/Struct/TurnResult.elm @@ -0,0 +1,43 @@ +module Struct.TurnResult exposing (Type(..), Attack, Movement, WeaponSwitch) + +-- Elm ------------------------------------------------------------------------- + +-- Battlemap ------------------------------------------------------------------- +import Struct.Direction +import Struct.Location +import Struct.Attack + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +type alias Movement = + { + character_index : Int, + path : (List Struct.Direction.Type), + destination : Struct.Location.Type + } + +type alias Attack = + { + attacker_index : Int, + defender_index : Int, + sequence : (List Struct.Attack.Type) + } + +type alias WeaponSwitch = + { + character_index : Int + } + +type Type = + Moved Movement + | Attacked Attack + | SwitchedWeapon WeaponSwitch + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm index 9b7cd36..7905f6e 100644 --- a/src/battlemap/src/Update/HandleServerReply.elm +++ b/src/battlemap/src/Update/HandleServerReply.elm @@ -4,10 +4,12 @@ module Update.HandleServerReply exposing (apply_to) import Http -- Battlemap ------------------------------------------------------------------- +import Struct.Battlemap +import Struct.Character import Struct.Error import Struct.Event -import Struct.ServerReply import Struct.Model +import Struct.ServerReply -------------------------------------------------------------------------------- -- TYPES ----------------------------------------------------------------------- @@ -16,37 +18,55 @@ import Struct.Model -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- + +add_character : ( + Struct.Character.Type -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) + ) +add_character char current_state = + case current_state of + (_, (Just _)) -> current_state + (model, _) -> + ( + (Struct.Model.add_character + char + model + ), + Nothing + ) + +set_map : ( + Struct.Battlemap.Type -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) -> + (Struct.Model.Type, (Maybe Struct.Error.Type)) + ) +set_map map current_state = + case current_state of + (_, (Just _)) -> current_state + (model, _) -> + ( + {model | battlemap = map}, + Nothing + ) + apply_command : ( Struct.ServerReply.Type -> (Struct.Model.Type, (Maybe Struct.Error.Type)) -> (Struct.Model.Type, (Maybe Struct.Error.Type)) ) apply_command command current_state = - case (command, current_state) of - (_, (_, (Just error))) -> current_state + case command of + (Struct.ServerReply.AddCharacter char) -> + (add_character char current_state) - ( - (Struct.ServerReply.AddCharacter char), - (model, _) - ) -> - current_state + (Struct.ServerReply.SetMap map) -> + (set_map map current_state) - ( - (Struct.ServerReply.SetMap map), - (model, _) - ) -> - current_state + (Struct.ServerReply.TurnResults results) -> current_state + + Struct.ServerReply.Okay -> current_state - (_, (model, _)) -> - ( - model, - (Just - (Struct.Error.new - Struct.Error.Unimplemented - "Unimplemented server command received" - ) - ) - ) -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- |