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-327 changeGraphicEffect and setGraphicEffect conversion fix [TN] #245

Open
wants to merge 3 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
25 changes: 15 additions & 10 deletions src/scratchtocatrobat/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,16 @@ class _ScratchToCatrobat(object):
catbricks.CameraBrick(int(status.lower() != 'off'))
],

"changeGraphicEffect:by:": None,
"changeGraphicEffect:by:": lambda effect_type, value:
catbricks.ChangeBrightnessByNBrick if effect_type == 'BRIGHTNESS' else
catbricks.ChangeTransparencyByNBrick if effect_type == 'GHOST' else
catbricks.ChangeColorByNBrick if effect_type == 'COLOR' else
_placeholder_for_unmapped_blocks_to("changeGraphicEffect:by:", effect_type, value),
"setGraphicEffect:to:": lambda effect_type, value:
catbricks.SetBrightnessBrick(value) if effect_type == 'brightness' else
catbricks.SetTransparencyBrick(value) if effect_type == 'ghost' else
_placeholder_for_unmapped_blocks_to("setGraphicEffect:to:", effect_type, value),
catbricks.SetBrightnessBrick if effect_type == 'BRIGHTNESS' else
catbricks.SetTransparencyBrick if effect_type == 'GHOST' else
catbricks.SetColorBrick if effect_type == 'COLOR' else
_placeholder_for_unmapped_blocks_to("setGraphicEffect:to:", effect_type, value),
"filterReset": catbricks.ClearGraphicEffectBrick,
"changeSizeBy:": catbricks.ChangeSizeByNBrick,
"setSizeTo:": catbricks.SetSizeToBrick,
Expand Down Expand Up @@ -2933,16 +2938,16 @@ def _convert_sound_block(self):
@_register_handler(_block_name_to_handler_map, "setGraphicEffect:to:")
def _convert_set_graphic_effect_block(self):
[effect_type, value] = self.arguments
if effect_type == 'brightness':
if effect_type == 'BRIGHTNESS':
# range Scratch: -100 to 100 (default: 0)
# range Catrobat: 0 to 200% (default: 100%)
formula_elem = self._converted_helper_brick_or_formula_element([value, 100], "+")
return catbricks.SetBrightnessBrick(catrobat.create_formula_with_value(formula_elem))
elif effect_type == 'ghost':
elif effect_type == 'GHOST':
# range Scratch: 0 to 100 (default: 0)
# range Catrobat: 0 to 100% (default: 0%)
return catbricks.SetTransparencyBrick(catrobat.create_formula_with_value(value))
elif effect_type == 'color':
elif effect_type == 'COLOR':
# range Scratch: 0 to 200 (default: 0)
# range Catrobat: 0 to 200% (default: 0%)
return catbricks.SetColorBrick(catrobat.create_formula_with_value(value))
Expand All @@ -2952,16 +2957,16 @@ def _convert_set_graphic_effect_block(self):
@_register_handler(_block_name_to_handler_map, "changeGraphicEffect:by:")
def _convert_change_graphic_effect_block(self):
[effect_type, value] = self.arguments
if effect_type == 'brightness':
if effect_type == 'BRIGHTNESS':
# range Scratch: -100 to 100 (default: 0)
# range Catrobat: 0 to 200% (default: 100%)
# since ChangeBrightnessByNBrick adds increment -> no range-conversion needed
return catbricks.ChangeBrightnessByNBrick(catrobat.create_formula_with_value(value))
elif effect_type == 'ghost':
elif effect_type == 'GHOST':
# range Scratch: 0 to 100 (default: 0)
# range Catrobat: 0 to 100% (default: 0%)
return catbricks.ChangeTransparencyByNBrick(catrobat.create_formula_with_value(value))
elif effect_type == 'color':
elif effect_type == 'COLOR':
# range Scratch: 0 to 200 (default: 0)
# range Catrobat: 0 to 200% (default: 0%)
return catbricks.ChangeColorByNBrick(catrobat.create_formula_with_value(value))
Expand Down
24 changes: 12 additions & 12 deletions src/scratchtocatrobat/converter/test_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def test_can_convert_doplaysoundandwait_block(self):

# setGraphicEffect:to: (brightness)
def test_can_convert_set_graphic_effect_with_float_value_brightness_block(self):
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "brightness", 10.1]
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "BRIGHTNESS", 10.1]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetBrightnessBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.BRIGHTNESS).formulaTree # @UndefinedVariable
Expand All @@ -1117,7 +1117,7 @@ def test_can_convert_set_graphic_effect_with_float_value_brightness_block(self):
def test_can_convert_set_graphic_effect_with_formula_value_brightness_block(self):
expected_left_operand = 10.1
expected_right_operand = 1
scratch_block = ["setGraphicEffect:to:", "brightness", ["+", expected_left_operand,
scratch_block = ["setGraphicEffect:to:", "BRIGHTNESS", ["+", expected_left_operand,
expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetBrightnessBrick)
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def test_can_convert_set_graphic_effect_with_formula_value_brightness_block(self

# setGraphicEffect:to: (ghost)
def test_can_convert_set_graphic_effect_with_float_value_ghost_block(self):
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "ghost", 10.2]
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "GHOST", 10.2]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetTransparencyBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.TRANSPARENCY).formulaTree # @UndefinedVariable
Expand All @@ -1166,7 +1166,7 @@ def test_can_convert_set_graphic_effect_with_float_value_ghost_block(self):
def test_can_convert_set_graphic_effect_with_formula_value_ghost_block(self):
expected_left_operand = 10.2
expected_right_operand = 1
scratch_block = ["setGraphicEffect:to:", "ghost", ["+", expected_left_operand, expected_right_operand]]
scratch_block = ["setGraphicEffect:to:", "GHOST", ["+", expected_left_operand, expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetTransparencyBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.TRANSPARENCY).formulaTree # @UndefinedVariable
Expand All @@ -1189,7 +1189,7 @@ def test_can_convert_set_graphic_effect_with_formula_value_ghost_block(self):

# setGraphicEffect:to: (color)
def test_can_convert_set_graphic_effect_with_float_value_color_block(self):
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "color", 10.2]
scratch_block = _, _, expected_value = ["setGraphicEffect:to:", "COLOR", 10.2]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetColorBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.COLOR).formulaTree # @UndefinedVariable
Expand All @@ -1202,7 +1202,7 @@ def test_can_convert_set_graphic_effect_with_float_value_color_block(self):
def test_can_convert_set_graphic_effect_with_formula_value_color_block(self):
expected_left_operand = 10.2
expected_right_operand = 1
scratch_block = ["setGraphicEffect:to:", "color", ["+", expected_left_operand, expected_right_operand]]
scratch_block = ["setGraphicEffect:to:", "COLOR", ["+", expected_left_operand, expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.SetColorBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.COLOR).formulaTree # @UndefinedVariable
Expand All @@ -1225,7 +1225,7 @@ def test_can_convert_set_graphic_effect_with_formula_value_color_block(self):

# changeGraphicEffect:by: (brightness)
def test_can_convert_change_graphic_effect_with_float_value_brightness_block(self):
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "brightness", 10.1]
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "BRIGHTNESS", 10.1]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeBrightnessByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.BRIGHTNESS_CHANGE).formulaTree # @UndefinedVariable
Expand All @@ -1238,7 +1238,7 @@ def test_can_convert_change_graphic_effect_with_float_value_brightness_block(sel
def test_can_convert_change_graphic_effect_with_formula_value_brightness_block(self):
expected_left_operand = 10.2
expected_right_operand = 1
scratch_block = ["changeGraphicEffect:by:", "brightness", ["+", expected_left_operand, expected_right_operand]]
scratch_block = ["changeGraphicEffect:by:", "BRIGHTNESS", ["+", expected_left_operand, expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeBrightnessByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.BRIGHTNESS_CHANGE).formulaTree # @UndefinedVariable
Expand All @@ -1261,7 +1261,7 @@ def test_can_convert_change_graphic_effect_with_formula_value_brightness_block(s

# changeGraphicEffect:by: (ghost)
def test_can_convert_change_graphic_effect_with_float_value_ghost_block(self):
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "ghost", 10.2]
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "GHOST", 10.2]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeTransparencyByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.TRANSPARENCY_CHANGE).formulaTree # @UndefinedVariable
Expand All @@ -1274,7 +1274,7 @@ def test_can_convert_change_graphic_effect_with_float_value_ghost_block(self):
def test_can_convert_change_graphic_effect_with_formula_value_ghost_block(self):
expected_left_operand = 10.2
expected_right_operand = 1
scratch_block = ["changeGraphicEffect:by:", "ghost", ["+", expected_left_operand, expected_right_operand]]
scratch_block = ["changeGraphicEffect:by:", "GHOST", ["+", expected_left_operand, expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeTransparencyByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.TRANSPARENCY_CHANGE).formulaTree # @UndefinedVariable
Expand All @@ -1297,7 +1297,7 @@ def test_can_convert_change_graphic_effect_with_formula_value_ghost_block(self):

# changeGraphicEffect:by: (color)
def test_can_convert_change_graphic_effect_with_float_value_color_block(self):
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "color", 10.2]
scratch_block = _, _, expected_value = ["changeGraphicEffect:by:", "COLOR", 10.2]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeColorByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.COLOR_CHANGE).formulaTree # @UndefinedVariable
Expand All @@ -1310,7 +1310,7 @@ def test_can_convert_change_graphic_effect_with_float_value_color_block(self):
def test_can_convert_change_graphic_effect_with_formula_value_color_block(self):
expected_left_operand = 10.2
expected_right_operand = 1
scratch_block = ["changeGraphicEffect:by:", "color", ["+", expected_left_operand, expected_right_operand]]
scratch_block = ["changeGraphicEffect:by:", "COLOR", ["+", expected_left_operand, expected_right_operand]]
[catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE)
assert isinstance(catr_brick, catbricks.ChangeColorByNBrick)
formula_tree_value = catr_brick.getFormulaWithBrickField(catbasebrick.BrickField.COLOR_CHANGE).formulaTree # @UndefinedVariable
Expand Down