Skip to content

Commit

Permalink
Call touchingColor() with mask param from target models
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Sep 10, 2024
1 parent adaf9e0 commit ebc60c8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/spritemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ bool SpriteModel::touchingColor(const libscratchcpp::Value &color) const

bool SpriteModel::touchingColor(const libscratchcpp::Value &color, const libscratchcpp::Value &mask) const
{
return false;
return m_renderedTarget->touchingColor(color, mask);
}

libscratchcpp::Sprite *SpriteModel::sprite() const
Expand Down
2 changes: 1 addition & 1 deletion src/stagemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool StageModel::touchingColor(const libscratchcpp::Value &color) const

bool StageModel::touchingColor(const libscratchcpp::Value &color, const libscratchcpp::Value &mask) const
{
return false;
return m_renderedTarget->touchingColor(color, mask);
}

void StageModel::loadCostume()
Expand Down
16 changes: 11 additions & 5 deletions test/target_models/spritemodel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,18 @@ TEST(SpriteModelTest, TouchingColor)
RenderedTargetMock renderedTarget;
model.setRenderedTarget(&renderedTarget);

Value color = 123;
EXPECT_CALL(renderedTarget, touchingColor(color)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color));
Value color1 = 123, color2 = 456;
EXPECT_CALL(renderedTarget, touchingColor(color1)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color1));

EXPECT_CALL(renderedTarget, touchingColor(color)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color));
EXPECT_CALL(renderedTarget, touchingColor(color1)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color1));

EXPECT_CALL(renderedTarget, touchingColor(color1, color2)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color1, color2));

EXPECT_CALL(renderedTarget, touchingColor(color1, color2)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color1, color2));
}

TEST(SpriteModelTest, RenderedTarget)
Expand Down
16 changes: 11 additions & 5 deletions test/target_models/stagemodel_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,18 @@ TEST(StageModelTest, TouchingColor)
RenderedTargetMock renderedTarget;
model.setRenderedTarget(&renderedTarget);

Value color = 123;
EXPECT_CALL(renderedTarget, touchingColor(color)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color));
Value color1 = 123, color2 = 456;
EXPECT_CALL(renderedTarget, touchingColor(color1)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color1));

EXPECT_CALL(renderedTarget, touchingColor(color)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color));
EXPECT_CALL(renderedTarget, touchingColor(color1)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color1));

EXPECT_CALL(renderedTarget, touchingColor(color1, color2)).WillOnce(Return(false));
ASSERT_FALSE(model.touchingColor(color1, color2));

EXPECT_CALL(renderedTarget, touchingColor(color1, color2)).WillOnce(Return(true));
ASSERT_TRUE(model.touchingColor(color1, color2));
}

TEST(StageModelTest, RenderedTarget)
Expand Down

0 comments on commit ebc60c8

Please sign in to comment.