summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/battlemap/src/Struct/CharacterTurn.elm21
-rw-r--r--src/battlemap/src/Update/SelectCharacter.elm128
2 files changed, 104 insertions, 45 deletions
diff --git a/src/battlemap/src/Struct/CharacterTurn.elm b/src/battlemap/src/Struct/CharacterTurn.elm
index c4dcecd..48703fe 100644
--- a/src/battlemap/src/Struct/CharacterTurn.elm
+++ b/src/battlemap/src/Struct/CharacterTurn.elm
@@ -2,17 +2,18 @@ module Struct.CharacterTurn exposing
(
Type,
State(..),
- new,
- try_getting_controlled_character,
- set_controlled_character,
- get_state,
+ add_target,
+ can_select_targets,
get_path,
+ get_state,
+ get_targets,
lock_path,
- try_getting_navigator,
- set_navigator,
- add_target,
+ new,
remove_target,
- get_targets
+ set_controlled_character,
+ set_navigator,
+ try_getting_controlled_character,
+ try_getting_navigator
)
-- Elm -------------------------------------------------------------------------
@@ -64,6 +65,10 @@ try_getting_controlled_character : Type -> (Maybe Struct.Character.Ref)
try_getting_controlled_character ct = ct.controlled_character
+can_select_targets : Type -> Bool
+can_select_targets ct =
+ ((ct.state == MovedCharacter) || ((ct.state == ChoseTarget)))
+
set_controlled_character : (
Type ->
Struct.Character.Type ->
diff --git a/src/battlemap/src/Update/SelectCharacter.elm b/src/battlemap/src/Update/SelectCharacter.elm
index e8dd734..fe5521c 100644
--- a/src/battlemap/src/Update/SelectCharacter.elm
+++ b/src/battlemap/src/Update/SelectCharacter.elm
@@ -10,9 +10,10 @@ import Struct.CharacterTurn
import Struct.Direction
import Struct.Error
import Struct.Event
-import Struct.UI
+import Struct.Location
import Struct.Model
import Struct.Navigator
+import Struct.UI
import Update.RequestDirection
@@ -34,13 +35,13 @@ attack_character model main_char_id target_char_id target_char =
(Struct.UI.set_previous_action model.ui Nothing)
}
-select_character : (
+ctrl_or_focus_character : (
Struct.Model.Type ->
Struct.Character.Ref ->
Struct.Character.Type ->
Struct.Model.Type
)
-select_character model target_char_id target_char =
+ctrl_or_focus_character model target_char_id target_char =
if (Struct.Character.is_enabled target_char)
then
{model |
@@ -72,30 +73,54 @@ select_character model target_char_id target_char =
)
}
---------------------------------------------------------------------------------
--- EXPORTED --------------------------------------------------------------------
---------------------------------------------------------------------------------
-apply_to : (
+can_target_character : (
Struct.Model.Type ->
- Struct.Character.Ref ->
- (Struct.Model.Type, (Cmd Struct.Event.Type))
+ Struct.Character.Type ->
+ Bool
)
-apply_to model target_char_id =
- if
+can_target_character model target =
(
- (Struct.UI.get_previous_action model.ui)
- ==
- (Just (Struct.UI.SelectedCharacter target_char_id))
+ (Struct.CharacterTurn.can_select_targets model.char_turn)
+ &&
+ (
+ case
+ (Struct.CharacterTurn.try_getting_navigator
+ model.char_turn
+ )
+ of
+ (Just nav) ->
+ case
+ (Struct.Navigator.try_getting_path_to
+ nav
+ (Struct.Location.get_ref
+ (Struct.Character.get_location target)
+ )
+ )
+ of
+ (Just _) -> True
+ _ -> False
+
+ _ ->
+ False
+ )
)
- then
- case (Dict.get target_char_id model.characters) of
- (Just target_char) ->
- case
- (Struct.CharacterTurn.try_getting_controlled_character
- model.char_turn
- )
- of
- (Just main_char_id) ->
+
+double_clicked_character : (
+ Struct.Model.Type ->
+ Struct.Character.Ref ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+double_clicked_character model target_char_id =
+ case (Dict.get target_char_id model.characters) of
+ (Just target_char) ->
+ case
+ (Struct.CharacterTurn.try_getting_controlled_character
+ model.char_turn
+ )
+ of
+ (Just main_char_id) ->
+ if (can_target_character model target_char)
+ then
(
(attack_character
model
@@ -105,24 +130,53 @@ apply_to model target_char_id =
),
Cmd.none
)
-
- _ ->
+ else
(
- (select_character model target_char_id target_char),
+ (Struct.Model.invalidate
+ model
+ (Struct.Error.new
+ Struct.Error.IllegalAction
+ "Has not yet moved or target is out of range."
+ )
+ ),
Cmd.none
)
- Nothing ->
- (
- (Struct.Model.invalidate
- model
- (Struct.Error.new
- Struct.Error.Programming
- "SelectCharacter: Unknown char selected."
- )
- ),
- Cmd.none
- )
+ _ ->
+ (
+ (ctrl_or_focus_character model target_char_id target_char),
+ Cmd.none
+ )
+
+ Nothing ->
+ (
+ (Struct.Model.invalidate
+ model
+ (Struct.Error.new
+ Struct.Error.Programming
+ "SelectCharacter: Unknown char selected."
+ )
+ ),
+ Cmd.none
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+apply_to : (
+ Struct.Model.Type ->
+ Struct.Character.Ref ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+apply_to model target_char_id =
+ if
+ (
+ (Struct.UI.get_previous_action model.ui)
+ ==
+ (Just (Struct.UI.SelectedCharacter target_char_id))
+ )
+ then
+ (double_clicked_character model target_char_id)
else
(
{model |