Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STCC-115 Touching color __, Color __ is touching __ ? [TN] #237

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/scratchtocatrobat/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,21 @@ def _convert_touching(self):
formula_element.value = arguments[0]
return formula_element

@_register_handler(_block_name_to_handler_map, "color:sees:")
def _convert_color_touching_color(self):
colors = self.arguments
color1 = catformula.FormulaElement(catElementType.STRING, colors[0], None)
color2 = catformula.FormulaElement(catElementType.STRING, colors[1], None)
formula_element = catformula.FormulaElement(catElementType.FUNCTION, str(catformula.Functions.COLOR_TOUCHES_COLOR), None, color1, color2)
return formula_element

@_register_handler(_block_name_to_handler_map, "touchingColor:")
def _convert_color_is_touching(self):
color = self.arguments
color_formula = catformula.FormulaElement(catElementType.STRING, color[0], None)
formula_element = catformula.FormulaElement(catElementType.FUNCTION, str(catformula.Functions.COLLIDES_WITH_COLOR), None, color_formula, None)
return formula_element

@_register_handler(_block_name_to_handler_map, "broadcast:")
def _convert_broadcast(self):
message = self.arguments[0]
Expand Down
14 changes: 14 additions & 0 deletions src/scratchtocatrobat/converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,20 @@ def test_can_convert_touching_block_object(self):
assert str(catr_formula_element.getElementType()) == 'COLLISION_FORMULA'
assert catr_formula_element.getValue() == '_some_object_'

def test_can_convert_color_touching_color_block(self):
scratch_block = ['color:sees:', '#3f43fc', '#d808dc']
[catr_formula_element] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_formula_element, catformula.FormulaElement)
assert str(catr_formula_element.getElementType()) == 'FUNCTION'
assert str(catr_formula_element.getValue()) == 'COLOR_TOUCHES_COLOR'

def test_can_convert_touching_color_block(self):
scratch_block = ['touchingColor:', '#3f43fc']
[catr_formula_element] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_formula_element, catformula.FormulaElement)
assert str(catr_formula_element.getElementType()) == 'FUNCTION'
assert str(catr_formula_element.getValue()) == 'COLLIDES_WITH_COLOR'

###############################################################################################################
#
# Brick block tests
Expand Down
2 changes: 1 addition & 1 deletion src/scratchtocatrobat/scratch/scratch3visitor/sensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def visitDistanceto_menu(blockcontext):
def visitColoristouchingcolor(blockcontext):
color = visitGeneric(blockcontext, "COLOR")
color2 = visitGeneric(blockcontext, "COLOR2")
return ["touchingColor:", color, color2]
return ["color:sees:", color, color2]

def visitOf(blockcontext):
block = blockcontext.block
Expand Down