11#include " PulseAction.h"
22#include " GameLayer.h"
33
4- std::shared_ptr<PulseAction> PulseAction::create (float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly)
4+ std::shared_ptr<PulseAction> PulseAction::create (
5+ float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly)
56{
67 std::shared_ptr<PulseAction> ptr (new PulseAction);
78
8- if (ptr->init (fadein, hold, fadeout, target, from, to, original , pulsetype, mainOnly, detailOnly))
9+ if (ptr->init (fadein, hold, fadeout, target, to , pulsetype, mainOnly, detailOnly))
910 return ptr;
1011
1112 return nullptr ;
1213}
1314
14- bool PulseAction::init (float fadein, float hold, float fadeout, int target, sf::Color from, sf::Color to, sf::Color original, int pulsetype, bool mainOnly, bool detailOnly)
15+ bool PulseAction::init (
16+ float fadein, float hold, float fadeout, int target, sf::Color to, int pulsetype, bool mainOnly, bool detailOnly)
1517{
1618 this ->duration = fadein + hold + fadeout;
1719 this ->fadein = fadein / duration;
1820 this ->hold = hold / duration;
1921 this ->fadeout = fadeout / duration;
20- this ->from = from;
2122 this ->to = to;
22- this ->original = original;
2323 this ->target = target;
2424 this ->pulsetype = pulsetype;
2525 this ->mainOnly = mainOnly;
2626 this ->detailOnly = detailOnly;
2727
28- this ->deltar = static_cast <float >(to.r - from.r );
29- this ->deltag = static_cast <float >(to.g - from.g );
30- this ->deltab = static_cast <float >(to.b - from.b );
31-
32- this ->deltar2 = static_cast <float >(original.r - to.r );
33- this ->deltag2 = static_cast <float >(original.g - to.g );
34- this ->deltab2 = static_cast <float >(original.b - to.b );
3528 return true ;
3629}
3730
3831void PulseAction::applyToSpriteIn (Sprite* spr, float fadetime)
3932{
40- if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly || spr->channelType == 0 )
33+ if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly ||
34+ spr->channelType == 0 )
4135 return ;
42- auto channelcolor = spr->channel ->getColor ();
43- auto r1 = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (1 - fadetime));
44- auto g1 = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (1 - fadetime));
45- auto b1 = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (1 - fadetime));
46- spr->setColor ({ r1, g1, b1 });
36+
37+ sf::Color channelcolor = spr->channel ->getColor ();
38+ sf::Uint8 r1 = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (1 .f - fadetime));
39+ sf::Uint8 g1 = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (1 .f - fadetime));
40+ sf::Uint8 b1 = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (1 .f - fadetime));
41+ spr->setColor ({r1, g1, b1});
4742}
4843
4944void PulseAction::applyToSpriteOut (Sprite* spr, float fadetime)
5045{
51- if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly || spr->channelType == 0 )
46+ if (spr->channel == nullptr || spr->channelType == 1 && detailOnly || spr->channelType == 2 && mainOnly ||
47+ spr->channelType == 0 )
5248 return ;
53- auto channelcolor = spr->channel ->getColor ();
54- auto r1 = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (fadetime));
55- auto g1 = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (fadetime));
56- auto b1 = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (fadetime));
57- spr->setColor ({ r1, g1, b1 });
49+
50+ sf::Color channelcolor = spr->channel ->getColor ();
51+ sf::Uint8 r1 = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (fadetime));
52+ sf::Uint8 g1 = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (fadetime));
53+ sf::Uint8 b1 = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (fadetime));
54+ spr->setColor ({r1, g1, b1});
5855}
5956
6057void PulseAction::update (float time)
@@ -67,10 +64,13 @@ void PulseAction::update(float time)
6764 if (fadein == 0 )
6865 fadetime = 1 .f ;
6966 std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels [target];
70- sf::Uint8 r = static_cast <sf::Uint8>(to.r - deltar * (1 - fadetime));
71- sf::Uint8 g = static_cast <sf::Uint8>(to.g - deltag * (1 - fadetime));
72- sf::Uint8 b = static_cast <sf::Uint8>(to.b - deltab * (1 - fadetime));
73- channel->setColor ({ r, g, b, channel->getColor ().a }, true );
67+ sf::Color channelcolor = channel->getNonPulseColor ();
68+
69+ sf::Uint8 r = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (1 .f - fadetime));
70+ sf::Uint8 g = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (1 .f - fadetime));
71+ sf::Uint8 b = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (1 .f - fadetime));
72+
73+ channel->setColor ({r, g, b, channel->getColor ().a }, true );
7474 channel->setDirtyRecusively ();
7575 }
7676 else if (time >= fadein + hold)
@@ -80,10 +80,20 @@ void PulseAction::update(float time)
8080 fadetime = 1 .f ;
8181
8282 std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels [target];
83- sf::Uint8 r = static_cast <sf::Uint8>(original.r - deltar2 * (1 - fadetime));
84- sf::Uint8 g = static_cast <sf::Uint8>(original.g - deltag2 * (1 - fadetime));
85- sf::Uint8 b = static_cast <sf::Uint8>(original.b - deltab2 * (1 - fadetime));
86- channel->setColor ({ r, g, b, channel->getColor ().a }, true );
83+ sf::Color channelcolor = channel->getNonPulseColor ();
84+
85+ sf::Uint8 r = static_cast <sf::Uint8>(to.r - (float )(to.r - channelcolor.r ) * (fadetime));
86+ sf::Uint8 g = static_cast <sf::Uint8>(to.g - (float )(to.g - channelcolor.g ) * (fadetime));
87+ sf::Uint8 b = static_cast <sf::Uint8>(to.b - (float )(to.b - channelcolor.b ) * (fadetime));
88+
89+ channel->setColor ({r, g, b, channel->getColor ().a }, true );
90+ channel->setDirtyRecusively ();
91+ }
92+ else
93+ {
94+ std::shared_ptr<ColorChannel> channel = GameLayer::instance->colorChannels [target];
95+
96+ channel->setColor ({to.r , to.g , to.b , channel->getColor ().a }, true );
8797 channel->setDirtyRecusively ();
8898 }
8999 }
@@ -98,7 +108,7 @@ void PulseAction::update(float time)
98108
99109 for (int i = GameLayer::instance->prevSection ; i < GameLayer::instance->nextSection + 1 ; i++)
100110 {
101- for (auto &pair : group->objectsInSections [i])
111+ for (auto & pair : group->objectsInSections [i])
102112 {
103113 GameObject* obj = pair.second ;
104114 applyToSpriteIn (obj, fadetime);
@@ -115,7 +125,7 @@ void PulseAction::update(float time)
115125 std::shared_ptr<Group> group = GameLayer::instance->groups [target];
116126 for (int i = GameLayer::instance->prevSection ; i < GameLayer::instance->nextSection + 1 ; i++)
117127 {
118- for (auto &pair : group->objectsInSections [i])
128+ for (auto & pair : group->objectsInSections [i])
119129 {
120130 GameObject* obj = pair.second ;
121131 applyToSpriteOut (obj, fadetime);
@@ -129,7 +139,7 @@ void PulseAction::update(float time)
129139 std::shared_ptr<Group> group = GameLayer::instance->groups [target];
130140 for (int i = GameLayer::instance->prevSection ; i < GameLayer::instance->nextSection + 1 ; i++)
131141 {
132- for (auto &pair : group->objectsInSections [i])
142+ for (auto & pair : group->objectsInSections [i])
133143 {
134144 GameObject* obj = pair.second ;
135145 applyToSpriteIn (obj, fadein + hold);
0 commit comments