summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-12-16 14:08:35 +0100
committernsensfel <SpamShield0@noot-noot.org>2019-12-16 14:08:35 +0100
commit2542493b58b23106a398ca048d4c238d442573fd (patch)
tree738cf4a49a8193224e525cf2f64899bf935ffb1b
parent1b44ddcad67726aac12025991dbd7f2c72267cec (diff)
Don't re-compute effects on every display.
-rw-r--r--src/battle/src/Struct/Character.elm57
-rw-r--r--src/battle/src/Update/HandleServerReply.elm1
-rw-r--r--src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm (renamed from src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm)2
-rw-r--r--src/battle/src/View/Character.elm200
-rw-r--r--src/battle/src/View/Map/Character.elm125
5 files changed, 85 insertions, 300 deletions
diff --git a/src/battle/src/Struct/Character.elm b/src/battle/src/Struct/Character.elm
index 54a3a8c..8f452c4 100644
--- a/src/battle/src/Struct/Character.elm
+++ b/src/battle/src/Struct/Character.elm
@@ -21,6 +21,11 @@ module Struct.Character exposing
set_base_character,
get_melee_attack_range,
refresh_omnimods,
+ add_extra_display_effect,
+ remove_extra_display_effect,
+ get_extra_display_effects,
+ get_extra_display_effects_list,
+ reset_extra_display_effects,
decoder,
resolve
)
@@ -60,7 +65,8 @@ type alias Type =
player_ix : Int,
enabled : Bool,
defeated : Bool,
- base : BattleCharacters.Struct.Character.Type
+ base : BattleCharacters.Struct.Character.Type,
+ extra_display_effects : (Set.Set String)
}
type alias Unresolved =
@@ -236,6 +242,52 @@ set_enabled enabled char = {char | enabled = enabled}
set_defeated : Bool -> Type -> Type
set_defeated defeated char = {char | defeated = defeated}
+add_extra_display_effect : String -> Type -> Type
+add_extra_display_effect effect_name char =
+ {char |
+ extra_display_effects =
+ (Set.insert effect_name char.extra_display_effects)
+ }
+
+remove_extra_display_effect : String -> Type -> Type
+remove_extra_display_effect effect_name char =
+ {char |
+ extra_display_effects =
+ (Set.remove effect_name char.extra_display_effects)
+ }
+
+get_extra_display_effects : Type -> (Set.Set String)
+get_extra_display_effects char = char.extra_display_effects
+
+get_extra_display_effects_list : Type -> (Set.Set String)
+get_extra_display_effects_list char = (Set.toList char.extra_display_effects)
+
+reset_extra_display_effects : Int -> Type -> Type
+reset_extra_display_effects viewer_ix char =
+ {char |
+ extra_display_effects =
+ (Set.fromList
+ [
+ (
+ if (viewer_ix == char.player_ix)
+ then "ally"
+ else "enemy"
+ ),
+ ("team-" ++ char.player_ix),
+ (
+ if (char.enabled)
+ then "enabled"
+ else "disabled"
+ ),
+ (
+ if (is_alive)
+ then "alive"
+ else "dead"
+ )
+ ]
+ )
+ }
+
decoder : (Json.Decode.Decoder Unresolved)
decoder =
(Json.Decode.succeed
@@ -284,5 +336,6 @@ resolve location_omnimod_resolver equipment_resolver ref =
(equipment_resolver)
(location_omnimod_resolver ref.location)
ref.base
- )
+ ),
+ extra_display_effects = (Set.empty)
}
diff --git a/src/battle/src/Update/HandleServerReply.elm b/src/battle/src/Update/HandleServerReply.elm
index 31dc97a..c72d165 100644
--- a/src/battle/src/Update/HandleServerReply.elm
+++ b/src/battle/src/Update/HandleServerReply.elm
@@ -39,7 +39,6 @@ import Struct.Model
import Struct.Player
import Struct.ServerReply
import Struct.TurnResult
-import Struct.TurnResultAnimator
import Struct.UI
import Update.Puppeteer
diff --git a/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm b/src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm
index 6c91c9c..a83cc91 100644
--- a/src/battle/src/Update/Puppeteer/RefreshCharactersOfPlayer.elm
+++ b/src/battle/src/Update/Puppeteer/RefreshCharactersOf.elm
@@ -1,4 +1,4 @@
-module Update.Puppeteer.RefreshCharactersOfPlayer exposing (forward, backward)
+module Update.Puppeteer.RefreshCharactersOf exposing (forward, backward)
-- Elm -------------------------------------------------------------------------
import Array
diff --git a/src/battle/src/View/Character.elm b/src/battle/src/View/Character.elm
index dc256c6..3a3f820 100644
--- a/src/battle/src/View/Character.elm
+++ b/src/battle/src/View/Character.elm
@@ -1,217 +1,43 @@
-module View.Character exposing
- (
- get_portrait_html,
- get_icon_html
- )
+module View.Character exposing (get_portrait_html)
-- Elm -------------------------------------------------------------------------
import Html
import Html.Attributes
import Html.Events
--- Shared ----------------------------------------------------------------------
-import Util.Html
-
-- Battle Characters -----------------------------------------------------------
-import BattleCharacters.Struct.Character
-import BattleCharacters.Struct.Equipment
-import BattleCharacters.Struct.Portrait
-
import BattleCharacters.View.Portrait
-- Local Module ----------------------------------------------------------------
-import Constants.UI
-
import Struct.Character
-import Struct.CharacterTurn
import Struct.Event
-import Struct.Model
-import Struct.UI
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_activation_level_class : (
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_activation_level_class char =
- if (Struct.Character.is_enabled char)
- then
- (Html.Attributes.class "character-icon-enabled")
- else
- (Html.Attributes.class "character-icon-disabled")
-
-get_alliance_class : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_alliance_class model char =
- if
- (
- (Struct.Character.get_player_index char) == model.player_i
- ==
- (Struct.Battle.get_own_player_index model.battle)
- )
- then (Html.Attributes.class "character-ally")
- else (Html.Attributes.class "character-enemy")
-
-get_position_style : (
- Struct.Character.Type ->
- (List (Html.Attribute Struct.Event.Type))
- )
-get_position_style char =
- let char_loc = (Struct.Character.get_location char) in
- [
- (Html.Attributes.style
- "top"
- ((String.fromInt (char_loc.y * Constants.UI.tile_size)) ++ "px")
- ),
- (Html.Attributes.style
- "left"
- ((String.fromInt (char_loc.x * Constants.UI.tile_size)) ++ "px")
- )
- ]
-
-get_focus_class : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_focus_class model char =
- if
- (
- (Struct.UI.get_previous_action model.ui)
- ==
- (Just (Struct.UI.SelectedCharacter (Struct.Character.get_index char)))
- )
- then
- (Html.Attributes.class "character-selected")
- else
- if
- (
- (Struct.CharacterTurn.try_getting_target model.char_turn)
- ==
- (Just (Struct.Character.get_index char))
- )
- then
- (Html.Attributes.class "character-targeted")
- else
- (Html.Attributes.class "")
-
-get_icon_body_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
-get_icon_body_html char =
- (Html.div
- [
- (Html.Attributes.class "character-icon-body"),
- (Html.Attributes.class
- (
- "asset-character-team-body-"
- ++ (String.fromInt (Struct.Character.get_player_index char))
- )
- )
- ]
- [
- ]
- )
-
-get_icon_head_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
-get_icon_head_html char =
- (Html.div
- [
- (Html.Attributes.class "character-icon-head"),
- (Html.Attributes.class
- (
- "asset-character-icon-"
- ++
- (BattleCharacters.Struct.Portrait.get_icon_id
- (BattleCharacters.Struct.Equipment.get_portrait
- (BattleCharacters.Struct.Character.get_equipment
- (Struct.Character.get_base_character char)
- )
- )
- )
- )
- )
- ]
- [
- ]
- )
-
-get_icon_actual_html : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Html Struct.Event.Type)
- )
-get_icon_actual_html model char =
- (Html.div
- (
- [
- (Html.Attributes.class "tiled"),
- (Html.Attributes.class "character-icon"),
- (get_activation_level_class char),
- (get_alliance_class model char),
- (get_focus_class model char),
- (Html.Attributes.class "clickable"),
- (Html.Events.onClick
- (Struct.Event.CharacterSelected
- (Struct.Character.get_index char)
- )
- )
- ]
- ++ (get_position_style char)
- )
- [
- (get_icon_body_html char),
- (get_icon_head_html char)
- ]
- )
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_portrait_html : (
- Int ->
- Struct.Character.Type ->
- (Html.Html Struct.Event.Type)
- )
-get_portrait_html viewer_ix char =
+get_portrait_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
+get_portrait_html char =
(BattleCharacters.View.Portrait.get_html
[
- (Html.Attributes.class
- (
- if ((Struct.Character.get_player_index char) == viewer_ix)
- then
- "character-ally"
- else
- "character-enemy"
- )
- ),
- (Html.Attributes.class
- (
- "character-portrait-team-"
- ++
- (String.fromInt (Struct.Character.get_player_index char))
- )
- ),
(Html.Events.onClick
(Struct.Event.LookingForCharacter (Struct.Character.get_index char))
)
+ |
+ (List.map
+ (
+ \effect_name ->
+ (Html.Attributes.class
+ ("character-portrait-effect-" ++ effect_name)
+ )
+ )
+ (Struct.Character.get_extra_display_effects_list char)
+ )
]
(BattleCharacters.Struct.Character.get_equipment
(Struct.Character.get_base_character char)
)
)
-
-get_icon_html : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Html Struct.Event.Type)
- )
-get_icon_html model char =
- if (Struct.Character.is_alive char)
- then
- (get_icon_actual_html model char)
- else
- (Util.Html.nothing)
diff --git a/src/battle/src/View/Map/Character.elm b/src/battle/src/View/Map/Character.elm
index b20c29a..a62d197 100644
--- a/src/battle/src/View/Map/Character.elm
+++ b/src/battle/src/View/Map/Character.elm
@@ -20,7 +20,6 @@ import Struct.Battle
import Struct.Character
import Struct.CharacterTurn
import Struct.Event
-import Struct.Model
import Struct.TurnResult
import Struct.TurnResultAnimator
import Struct.UI
@@ -28,68 +27,6 @@ import Struct.UI
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_animation_class : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_animation_class model char =
- case model.animator of
- Nothing -> (Html.Attributes.class "")
- (Just animator) ->
- case (Struct.TurnResultAnimator.get_current_animation animator) of
- (Struct.TurnResultAnimator.Focus char_index) ->
- if ((Struct.Character.get_index char) /= char_index)
- then
- (Html.Attributes.class "")
- else
- (Html.Attributes.class "character-selected")
-
- (Struct.TurnResultAnimator.TurnResult current_action) ->
- if
- (
- (Struct.TurnResult.get_actor_index current_action)
- /=
- (Struct.Character.get_index char)
- )
- then
- (Html.Attributes.class "")
- else
- case current_action of
- (Struct.TurnResult.Moved _) ->
- (Html.Attributes.class
- "animated-character-icon"
- )
-
- _ -> (Html.Attributes.class "")
- _ -> (Html.Attributes.class "")
-
-get_activation_level_class : (
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_activation_level_class char =
- if (Struct.Character.is_enabled char)
- then
- (Html.Attributes.class "character-icon-enabled")
- else
- (Html.Attributes.class "character-icon-disabled")
-
-get_alliance_class : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_alliance_class model char =
- if
- (
- (Struct.Character.get_player_index char)
- ==
- (Struct.Battle.get_own_player_index model.battle)
- )
- then (Html.Attributes.class "character-ally")
- else (Html.Attributes.class "character-enemy")
-
get_position_style : (
Struct.Character.Type ->
(List (Html.Attribute Struct.Event.Type))
@@ -107,32 +44,6 @@ get_position_style char =
)
]
-get_focus_class : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Attribute Struct.Event.Type)
- )
-get_focus_class model char =
- if
- (
- (Struct.UI.get_previous_action model.ui)
- ==
- (Just (Struct.UI.SelectedCharacter (Struct.Character.get_index char)))
- )
- then
- (Html.Attributes.class "character-selected")
- else
- if
- (
- (Struct.CharacterTurn.try_getting_target model.char_turn)
- ==
- (Just (Struct.Character.get_index char))
- )
- then
- (Html.Attributes.class "character-targeted")
- else
- (Html.Attributes.class "")
-
get_body_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
get_body_html char =
(Html.div
@@ -195,21 +106,13 @@ get_banner_html char =
_ -> (Util.Html.nothing)
-get_actual_html : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Html Struct.Event.Type)
- )
-get_actual_html model char =
+get_actual_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
+get_actual_html char =
(Html.div
(
[
(Html.Attributes.class "tiled"),
(Html.Attributes.class "character-icon"),
- (get_animation_class model char),
- (get_activation_level_class char),
- (get_alliance_class model char),
- (get_focus_class model char),
(Html.Attributes.class "clickable"),
(Html.Events.onClick
(Struct.Event.CharacterSelected
@@ -218,6 +121,16 @@ get_actual_html model char =
)
]
++
+ (List.map
+ (
+ \effect_name ->
+ (Html.Attributes.class
+ ("character-icon-effect-" ++ effect_name)
+ )
+ )
+ (Struct.Character.get_extra_display_effects_list char)
+ )
+ ++
(get_position_style char)
)
[
@@ -230,14 +143,8 @@ get_actual_html model char =
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
-get_html : (
- Struct.Model.Type ->
- Struct.Character.Type ->
- (Html.Html Struct.Event.Type)
- )
-get_html model char =
+get_html : Struct.Character.Type -> (Html.Html Struct.Event.Type)
+get_html char =
if (Struct.Character.is_alive char)
- then
- (get_actual_html model char)
- else
- (Util.Html.nothing)
+ then (get_actual_html char)
+ else (Util.Html.nothing)