aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-03-09 17:45:29 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-03-09 17:45:29 +0100
commit732c4d1e505776a3e89a43bc9e8f3e4f780c5be1 (patch)
treec156c376beca154c3968e608e42deb29e84b1250
parent8357273cf79511002f561a800b8d773d13b7fffa (diff)
downloadtacticians-client-refactoring.zip
tacticians-client-refactoring.tar.bz2
Hacked together some kind of timeline feature.refactoring
-rw-r--r--src/battlemap/src/Struct/Character.elm4
-rw-r--r--src/battlemap/src/Struct/Model.elm8
-rw-r--r--src/battlemap/src/Struct/UI.elm4
-rw-r--r--src/battlemap/src/Update/HandleServerReply.elm26
-rw-r--r--src/battlemap/src/View/SideBar/TabMenu.elm7
-rw-r--r--src/battlemap/src/View/SideBar/TabMenu/Timeline.elm169
6 files changed, 214 insertions, 4 deletions
diff --git a/src/battlemap/src/Struct/Character.elm b/src/battlemap/src/Struct/Character.elm
index 450c605..a55d8f7 100644
--- a/src/battlemap/src/Struct/Character.elm
+++ b/src/battlemap/src/Struct/Character.elm
@@ -4,6 +4,7 @@ module Struct.Character exposing
Ref,
get_ref,
get_player_id,
+ get_name,
get_icon_id,
get_portrait_id,
get_current_health,
@@ -98,6 +99,9 @@ finish_decoding get_weapon add_char =
get_ref : Type -> Ref
get_ref c = c.id
+get_name : Type -> String
+get_name c = c.name
+
get_player_id : Type -> String
get_player_id c = c.player_id
diff --git a/src/battlemap/src/Struct/Model.elm b/src/battlemap/src/Struct/Model.elm
index 13a516d..4955163 100644
--- a/src/battlemap/src/Struct/Model.elm
+++ b/src/battlemap/src/Struct/Model.elm
@@ -10,6 +10,7 @@ module Struct.Model exposing
-- Elm -------------------------------------------------------------------------
import Dict
+import Array
-- Battlemap -------------------------------------------------------------------
import Data.Weapons
@@ -17,6 +18,7 @@ import Data.Weapons
import Struct.Battlemap
import Struct.Character
import Struct.CharacterTurn
+import Struct.TurnResult
import Struct.Error
import Struct.UI
import Struct.Weapon
@@ -32,7 +34,8 @@ type alias Type =
error: (Maybe Struct.Error.Type),
player_id: String,
ui: Struct.UI.Type,
- char_turn: Struct.CharacterTurn.Type
+ char_turn: Struct.CharacterTurn.Type,
+ timeline: (Array.Array Struct.TurnResult.Type)
}
--------------------------------------------------------------------------------
@@ -51,7 +54,8 @@ new =
error = Nothing,
player_id = "0",
ui = (Struct.UI.default),
- char_turn = (Struct.CharacterTurn.new)
+ char_turn = (Struct.CharacterTurn.new),
+ timeline = (Array.empty)
}
add_character : Struct.Character.Type -> Type -> Type
diff --git a/src/battlemap/src/Struct/UI.elm b/src/battlemap/src/Struct/UI.elm
index abf2e54..3343565 100644
--- a/src/battlemap/src/Struct/UI.elm
+++ b/src/battlemap/src/Struct/UI.elm
@@ -34,6 +34,7 @@ type Tab =
StatusTab
| CharactersTab
| SettingsTab
+ | TimelineTab
type Action =
UsedManualControls
@@ -91,10 +92,11 @@ to_string tab =
StatusTab -> "Status"
CharactersTab -> "Characters"
SettingsTab -> "Settings"
+ TimelineTab -> "Timeline"
get_all_tabs : (List Tab)
get_all_tabs =
- [StatusTab, CharactersTab, SettingsTab]
+ [StatusTab, CharactersTab, SettingsTab, TimelineTab]
-- ManualControls --------------------------------------------------------------
has_manual_controls_enabled : Type -> Bool
diff --git a/src/battlemap/src/Update/HandleServerReply.elm b/src/battlemap/src/Update/HandleServerReply.elm
index 7905f6e..3d66649 100644
--- a/src/battlemap/src/Update/HandleServerReply.elm
+++ b/src/battlemap/src/Update/HandleServerReply.elm
@@ -1,6 +1,8 @@
module Update.HandleServerReply exposing (apply_to)
-- Elm -------------------------------------------------------------------------
+import Array
+
import Http
-- Battlemap -------------------------------------------------------------------
@@ -10,6 +12,7 @@ import Struct.Error
import Struct.Event
import Struct.Model
import Struct.ServerReply
+import Struct.TurnResult
--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
@@ -50,6 +53,26 @@ set_map map current_state =
Nothing
)
+add_to_timeline : (
+ (List Struct.TurnResult.Type) ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type)) ->
+ (Struct.Model.Type, (Maybe Struct.Error.Type))
+ )
+add_to_timeline turn_results current_state =
+ case current_state of
+ (_, (Just _)) -> current_state
+ (model, _) ->
+ (
+ {model |
+ timeline =
+ (Array.append
+ model.timeline
+ (Array.fromList turn_results)
+ )
+ },
+ Nothing
+ )
+
apply_command : (
Struct.ServerReply.Type ->
(Struct.Model.Type, (Maybe Struct.Error.Type)) ->
@@ -63,7 +86,8 @@ apply_command command current_state =
(Struct.ServerReply.SetMap map) ->
(set_map map current_state)
- (Struct.ServerReply.TurnResults results) -> current_state
+ (Struct.ServerReply.TurnResults results) ->
+ (add_to_timeline results current_state)
Struct.ServerReply.Okay -> current_state
diff --git a/src/battlemap/src/View/SideBar/TabMenu.elm b/src/battlemap/src/View/SideBar/TabMenu.elm
index 220e20a..3cca9ea 100644
--- a/src/battlemap/src/View/SideBar/TabMenu.elm
+++ b/src/battlemap/src/View/SideBar/TabMenu.elm
@@ -16,6 +16,7 @@ import Util.Html
import View.SideBar.TabMenu.Characters
import View.SideBar.TabMenu.Settings
import View.SideBar.TabMenu.Status
+import View.SideBar.TabMenu.Timeline
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
@@ -111,6 +112,12 @@ get_html model =
(View.SideBar.TabMenu.Settings.get_html model)
]
+ (Just Struct.UI.TimelineTab) ->
+ [
+ (get_active_tab_selector_html Struct.UI.TimelineTab),
+ (View.SideBar.TabMenu.Timeline.get_html model)
+ ]
+
Nothing -> [(get_inactive_tab_selector_html)]
)
)
diff --git a/src/battlemap/src/View/SideBar/TabMenu/Timeline.elm b/src/battlemap/src/View/SideBar/TabMenu/Timeline.elm
new file mode 100644
index 0000000..df0fe8b
--- /dev/null
+++ b/src/battlemap/src/View/SideBar/TabMenu/Timeline.elm
@@ -0,0 +1,169 @@
+module View.SideBar.TabMenu.Timeline exposing (get_html)
+
+-- Elm -------------------------------------------------------------------------
+import Array
+
+import Dict
+
+import Html
+import Html.Attributes
+--import Html.Events
+import Html.Lazy
+
+-- Battlemap -------------------------------------------------------------------
+import Struct.Event
+import Struct.TurnResult
+import Struct.Character
+import Struct.Model
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_attack_html : (
+ Struct.Model.Type ->
+ Struct.TurnResult.Attack ->
+ (Html.Html Struct.Event.Type)
+ )
+get_attack_html model attack =
+ case
+ (
+ (Dict.get (toString attack.attacker_index) model.characters),
+ (Dict.get (toString attack.defender_index) model.characters)
+ )
+ of
+ ((Just atkchar), (Just defchar)) ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-attack")
+ ]
+ [
+ (Html.text
+ (
+ (Struct.Character.get_name atkchar)
+ ++ " attacked "
+ ++ (Struct.Character.get_name defchar)
+ ++ "!"
+ )
+ )
+ ]
+ )
+
+ _ ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-attack")
+ ]
+ [
+ (Html.text "Error: Attack with unknown characters")
+ ]
+ )
+
+get_movement_html : (
+ Struct.Model.Type ->
+ Struct.TurnResult.Movement ->
+ (Html.Html Struct.Event.Type)
+ )
+get_movement_html model movement =
+ case (Dict.get (toString movement.character_index) model.characters) of
+ (Just char) ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-movement")
+ ]
+ [
+ (Html.text
+ (
+ (Struct.Character.get_name char)
+ ++ " moved to ("
+ ++ (toString movement.destination.x)
+ ++ ", "
+ ++ (toString movement.destination.y)
+ ++ ")."
+ )
+ )
+ ]
+ )
+
+ _ ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-movement")
+ ]
+ [
+ (Html.text "Error: Moving with unknown character")
+ ]
+ )
+
+get_weapon_switch_html : (
+ Struct.Model.Type ->
+ Struct.TurnResult.WeaponSwitch ->
+ (Html.Html Struct.Event.Type)
+ )
+get_weapon_switch_html model weapon_switch =
+ case (Dict.get (toString weapon_switch.character_index) model.characters) of
+ (Just char) ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-weapon-switch")
+ ]
+ [
+ (Html.text
+ (
+ (Struct.Character.get_name char)
+ ++ " switched weapons."
+ )
+ )
+ ]
+ )
+
+ _ ->
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-timeline-weapon-switch")
+ ]
+ [
+ (Html.text "Error: Unknown character switched weapons")
+ ]
+ )
+
+get_turn_result_html : (
+ Struct.Model.Type ->
+ Struct.TurnResult.Type ->
+ (Html.Html Struct.Event.Type)
+ )
+get_turn_result_html model turn_result =
+ case turn_result of
+ (Struct.TurnResult.Moved movement) ->
+ (get_movement_html model movement)
+
+ (Struct.TurnResult.Attacked attack) ->
+ (get_attack_html model attack)
+
+ (Struct.TurnResult.SwitchedWeapon weapon_switch) ->
+ (get_weapon_switch_html model weapon_switch)
+
+true_get_html : (
+ Struct.Model.Type ->
+ (Array.Array Struct.TurnResult.Type) ->
+ (Html.Html Struct.Event.Type)
+ )
+true_get_html model turn_results =
+ (Html.div
+ [
+ (Html.Attributes.class "battlemap-tabmenu-content"),
+ (Html.Attributes.class "battlemap-tabmenu-timeline-tab")
+ ]
+ (Array.toList
+ (Array.map
+ (get_turn_result_html model)
+ turn_results
+ )
+ )
+ )
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)
+get_html model =
+ (Html.Lazy.lazy (true_get_html model) model.timeline)