Skip to content

Commit 8b4d19b

Browse files
committed
Implement costume changes in target interfaces
1 parent f75a571 commit 8b4d19b

File tree

13 files changed

+46
-25
lines changed

13 files changed

+46
-25
lines changed

include/scratchcpp/ispritehandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class LIBSCRATCHCPP_EXPORT ISpriteHandler
1818

1919
virtual void onCloned(Sprite *clone) = 0;
2020

21-
virtual void onCostumeChanged(const char *data) = 0;
21+
virtual void onCostumeChanged(Costume *costume) = 0;
2222

2323
virtual void onVisibleChanged(bool visible) = 0;
2424
virtual void onXChanged(double x) = 0;

include/scratchcpp/istagehandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LIBSCRATCHCPP_EXPORT IStageHandler
1616

1717
virtual void onStageChanged(Stage *stage) = 0;
1818

19-
virtual void onCostumeChanged(const char *data) = 0;
19+
virtual void onCostumeChanged(Costume *costume) = 0;
2020

2121
virtual void onTempoChanged(int tempo) = 0;
2222
virtual void onVideoStateChanged(Stage::VideoState videoState) = 0;

include/scratchcpp/stage.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class LIBSCRATCHCPP_EXPORT Stage : public Target
2929
void setInterface(IStageHandler *newInterface);
3030

3131
bool isStage() const override;
32+
33+
void setCostumeIndex(int newCostumeIndex);
34+
3235
int tempo() const;
3336
void setTempo(int newTempo);
3437

src/scratch/sprite.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ void Sprite::setCostumeIndex(int newCostumeIndex)
246246
}
247247

248248
Target::setCostumeIndex(newCostumeIndex);
249+
250+
if (costume && impl->iface)
251+
impl->iface->onCostumeChanged(costume.get());
249252
}
250253

251254
/*! Returns the direction. */

src/scratch/sprite_p.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ void SpritePrivate::removeClone(Sprite *clone)
3131
}
3232
}
3333

34-
void SpritePrivate::setCostumeData(const char *data)
35-
{
36-
if (iface)
37-
iface->onCostumeChanged(data);
38-
}
39-
4034
void SpritePrivate::getBoundingRect(Rect *out) const
4135
{
4236
assert(out);

src/scratch/sprite_p.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ struct SpritePrivate
1717

1818
void removeClone(Sprite *clone);
1919

20-
void setCostumeData(const char *data);
2120
void getBoundingRect(Rect *out) const;
2221
void getFencedPosition(double inX, double inY, double *outX, double *outY) const;
2322

src/scratch/stage.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ bool Stage::isStage() const
2929
return true;
3030
}
3131

32+
/*! Overrides Target#setCostumeIndex(). */
33+
void Stage::setCostumeIndex(int newCostumeIndex)
34+
{
35+
Target::setCostumeIndex(newCostumeIndex);
36+
auto costume = costumeAt(newCostumeIndex);
37+
38+
if (impl->iface)
39+
impl->iface->onCostumeChanged(costume.get());
40+
}
41+
3242
/*! Returns the tempo. */
3343
int Stage::tempo() const
3444
{

src/scratch/stage_p.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@ using namespace libscratchcpp;
99
StagePrivate::StagePrivate()
1010
{
1111
}
12-
13-
void StagePrivate::setCostumeData(const char *data)
14-
{
15-
if (iface)
16-
iface->onCostumeChanged(data);
17-
}

src/scratch/stage_p.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ struct StagePrivate
1212
StagePrivate();
1313
StagePrivate(const StagePrivate &) = delete;
1414

15-
void setCostumeData(const char *data);
16-
1715
IStageHandler *iface = nullptr;
1816
int tempo = 60;
1917
Stage::VideoState videoState = Stage::VideoState::Off;

test/mocks/spritehandlermock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class SpriteHandlerMock : public ISpriteHandler
1212

1313
MOCK_METHOD(void, onCloned, (Sprite *), (override));
1414

15-
MOCK_METHOD(void, onCostumeChanged, (const char *), (override));
15+
MOCK_METHOD(void, onCostumeChanged, (Costume *), (override));
1616

1717
MOCK_METHOD(void, onVisibleChanged, (bool), (override));
1818
MOCK_METHOD(void, onXChanged, (double), (override));

0 commit comments

Comments
 (0)