aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-27 09:56:52 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-27 09:56:52 +0100
commit64316ecae3184c5a7c52afb2bed839d1e1009331 (patch)
tree9250ef3057ba0a886e80875a3e2da9a4f8ed34ba
parent0a39977b8047382c8e311e40ac2adf3f34c61d7a (diff)
downloadtacticians-client-weapons.zip
tacticians-client-weapons.tar.bz2
Switching weapons seems to work.weapons
-rw-r--r--src/battlemap/src/Send/CharacterTurn.elm33
-rw-r--r--src/battlemap/src/Struct/CharacterTurn.elm71
-rw-r--r--src/battlemap/src/Update/SelectCharacter.elm7
-rw-r--r--src/battlemap/src/Update/SwitchWeapon.elm43
-rw-r--r--src/battlemap/src/View/SideBar.elm9
-rw-r--r--src/battlemap/src/View/SideBar/Targets.elm14
6 files changed, 94 insertions, 83 deletions
diff --git a/src/battlemap/src/Send/CharacterTurn.elm b/src/battlemap/src/Send/CharacterTurn.elm
index 30f778c..df2758f 100644
--- a/src/battlemap/src/Send/CharacterTurn.elm
+++ b/src/battlemap/src/Send/CharacterTurn.elm
@@ -40,15 +40,26 @@ try_encoding model =
(
"p",
(Json.Encode.list
- (List.map
- (
- (Json.Encode.string)
- <<
- (Struct.Direction.to_string)
- )
- (List.reverse
- (Struct.CharacterTurn.get_path model.char_turn)
- )
+ (
+ if
+ (Struct.CharacterTurn.has_switched_weapons
+ model.char_turn
+ )
+ then
+ [(Json.Encode.string "S")]
+ else
+ (List.map
+ (
+ (Json.Encode.string)
+ <<
+ (Struct.Direction.to_string)
+ )
+ (List.reverse
+ (Struct.CharacterTurn.get_path
+ model.char_turn
+ )
+ )
+ )
)
)
),
@@ -57,9 +68,9 @@ try_encoding model =
(Json.Encode.string
(
case
- (Struct.CharacterTurn.get_targets model.char_turn)
+ (Struct.CharacterTurn.get_target model.char_turn)
of
- [a] -> a
+ (Just target_ref) -> target_ref
_ -> "-1"
)
)
diff --git a/src/battlemap/src/Struct/CharacterTurn.elm b/src/battlemap/src/Struct/CharacterTurn.elm
index 5aa5b94..6188913 100644
--- a/src/battlemap/src/Struct/CharacterTurn.elm
+++ b/src/battlemap/src/Struct/CharacterTurn.elm
@@ -2,14 +2,15 @@ module Struct.CharacterTurn exposing
(
Type,
State(..),
- add_target,
- can_select_targets,
+ set_target,
+ can_select_target,
+ set_has_switched_weapons,
+ has_switched_weapons,
get_path,
get_state,
- get_targets,
+ get_target,
lock_path,
new,
- remove_target,
set_active_character,
set_navigator,
try_getting_active_character,
@@ -17,7 +18,6 @@ module Struct.CharacterTurn exposing
)
-- Elm -------------------------------------------------------------------------
-import List
-- Battlemap -------------------------------------------------------------------
import Struct.Character
@@ -38,8 +38,9 @@ type alias Type =
state : State,
active_character : (Maybe Struct.Character.Type),
path : (List Struct.Direction.Type),
- targets : (List Struct.Character.Ref),
- navigator : (Maybe Struct.Navigator.Type)
+ target : (Maybe Struct.Character.Ref),
+ navigator : (Maybe Struct.Navigator.Type),
+ has_switched_weapons : Bool
}
--------------------------------------------------------------------------------
@@ -55,16 +56,16 @@ new =
state = Default,
active_character = Nothing,
path = [],
- targets = [],
- navigator = Nothing
+ target = Nothing,
+ navigator = Nothing,
+ has_switched_weapons = False
}
try_getting_active_character : Type -> (Maybe Struct.Character.Type)
try_getting_active_character ct = ct.active_character
-can_select_targets : Type -> Bool
-can_select_targets ct =
- ((ct.state == MovedCharacter) || ((ct.state == ChoseTarget)))
+can_select_target : Type -> Bool
+can_select_target ct = (ct.state == MovedCharacter)
set_active_character : (
Struct.Character.Type ->
@@ -76,8 +77,9 @@ set_active_character char ct =
state = SelectedCharacter,
active_character = (Just char),
path = [],
- targets = [],
- navigator = Nothing
+ target = Nothing,
+ navigator = Nothing,
+ has_switched_weapons = False
}
get_state : Type -> State
@@ -93,7 +95,7 @@ lock_path ct =
{ct |
state = MovedCharacter,
path = (Struct.Navigator.get_path old_nav),
- targets = [],
+ target = Nothing,
navigator = (Just (Struct.Navigator.lock_path old_nav))
}
@@ -108,34 +110,25 @@ set_navigator navigator ct =
{ct |
state = SelectedCharacter,
path = [],
- targets = [],
+ target = Nothing,
navigator = (Just navigator)
}
-add_target : Struct.Character.Ref -> Type -> Type
-add_target target_ref ct =
+set_has_switched_weapons : Bool -> Type -> Type
+set_has_switched_weapons v ct =
+ {ct |
+ has_switched_weapons = v
+ }
+
+has_switched_weapons : Type -> Bool
+has_switched_weapons ct = ct.has_switched_weapons
+
+set_target : (Maybe Struct.Character.Ref) -> Type -> Type
+set_target target ct =
{ct |
state = ChoseTarget,
- targets = (List.append ct.targets [target_ref])
+ target = target
}
-remove_target : Int -> Type -> Type
-remove_target i ct =
- let
- new_targets = (List.drop i ct.targets)
- in
- case new_targets of
- [] ->
- {ct |
- state = MovedCharacter,
- targets = []
- }
-
- _ ->
- {ct |
- state = ChoseTarget,
- targets = new_targets
- }
-
-get_targets : Type -> (List Struct.Character.Ref)
-get_targets ct = ct.targets
+get_target : Type -> (Maybe Struct.Character.Ref)
+get_target ct = ct.target
diff --git a/src/battlemap/src/Update/SelectCharacter.elm b/src/battlemap/src/Update/SelectCharacter.elm
index 9e14791..0e08a4d 100644
--- a/src/battlemap/src/Update/SelectCharacter.elm
+++ b/src/battlemap/src/Update/SelectCharacter.elm
@@ -29,7 +29,10 @@ attack_character : (
attack_character model target_char_id target_char =
{model |
char_turn =
- (Struct.CharacterTurn.add_target target_char_id model.char_turn),
+ (Struct.CharacterTurn.set_target
+ (Just target_char_id)
+ model.char_turn
+ ),
ui =
(Struct.UI.set_previous_action model.ui Nothing)
}
@@ -88,7 +91,7 @@ can_target_character : (
)
can_target_character model target =
(
- (Struct.CharacterTurn.can_select_targets model.char_turn)
+ (Struct.CharacterTurn.can_select_target model.char_turn)
&&
(
case
diff --git a/src/battlemap/src/Update/SwitchWeapon.elm b/src/battlemap/src/Update/SwitchWeapon.elm
index 7eed323..7921b66 100644
--- a/src/battlemap/src/Update/SwitchWeapon.elm
+++ b/src/battlemap/src/Update/SwitchWeapon.elm
@@ -30,28 +30,31 @@ make_it_so model =
in
{model |
char_turn =
- (Struct.CharacterTurn.lock_path
- (Struct.CharacterTurn.set_navigator
- (Struct.Navigator.new
- (Struct.Character.get_location new_char)
- (Struct.Statistics.get_movement_points
- (Struct.Character.get_statistics new_char)
- )
- (Struct.Weapon.get_attack_range
- (Struct.WeaponSet.get_active_weapon new_weapons)
- )
- (Struct.Weapon.get_defense_range
- (Struct.WeaponSet.get_active_weapon new_weapons)
- )
- (Struct.Battlemap.get_movement_cost_function
- model.battlemap
+ (Struct.CharacterTurn.set_has_switched_weapons
+ True
+ (Struct.CharacterTurn.lock_path
+ (Struct.CharacterTurn.set_navigator
+ (Struct.Navigator.new
(Struct.Character.get_location new_char)
- (Dict.values model.characters)
+ (Struct.Statistics.get_movement_points
+ (Struct.Character.get_statistics new_char)
+ )
+ (Struct.Weapon.get_attack_range
+ (Struct.WeaponSet.get_active_weapon new_weapons)
+ )
+ (Struct.Weapon.get_defense_range
+ (Struct.WeaponSet.get_active_weapon new_weapons)
+ )
+ (Struct.Battlemap.get_movement_cost_function
+ model.battlemap
+ (Struct.Character.get_location new_char)
+ (Dict.values model.characters)
+ )
+ )
+ (Struct.CharacterTurn.set_active_character
+ new_char
+ model.char_turn
)
- )
- (Struct.CharacterTurn.set_active_character
- new_char
- model.char_turn
)
)
)
diff --git a/src/battlemap/src/View/SideBar.elm b/src/battlemap/src/View/SideBar.elm
index d5a8737..206a4a6 100644
--- a/src/battlemap/src/View/SideBar.elm
+++ b/src/battlemap/src/View/SideBar.elm
@@ -29,11 +29,12 @@ get_html model =
[
(View.SideBar.TabMenu.get_html model),
(
- if ((Struct.CharacterTurn.get_targets model.char_turn) == [])
- then
+ case (Struct.CharacterTurn.get_target model.char_turn) of
+ (Just target_ref) ->
+ (View.SideBar.Targets.get_html model target_ref)
+
+ _ ->
(Util.Html.nothing)
- else
- (View.SideBar.Targets.get_html model)
),
(
if (Struct.UI.has_manual_controls_enabled model.ui)
diff --git a/src/battlemap/src/View/SideBar/Targets.elm b/src/battlemap/src/View/SideBar/Targets.elm
index 9594eca..7bb4c36 100644
--- a/src/battlemap/src/View/SideBar/Targets.elm
+++ b/src/battlemap/src/View/SideBar/Targets.elm
@@ -8,7 +8,6 @@ import Html.Attributes
-- Battlemap -------------------------------------------------------------------
import Struct.Character
-import Struct.CharacterTurn
import Struct.Event
import Struct.Model
import Struct.Statistics
@@ -56,14 +55,15 @@ get_target_info_html model char_ref =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)
-get_html model =
+get_html : (
+ Struct.Model.Type ->
+ Struct.Character.Ref ->
+ (Html.Html Struct.Event.Type)
+ )
+get_html model target_ref =
(Html.div
[
(Html.Attributes.class "battlemap-side-bar-targets")
]
- (List.map
- (get_target_info_html model)
- (Struct.CharacterTurn.get_targets model.char_turn)
- )
+ [(get_target_info_html model target_ref)]
)