diff --git a/src/scratchtocatrobat/converter/converter.py b/src/scratchtocatrobat/converter/converter.py index d9ccff37..91de09fc 100644 --- a/src/scratchtocatrobat/converter/converter.py +++ b/src/scratchtocatrobat/converter/converter.py @@ -3057,20 +3057,20 @@ def _convert_create_clone_of_block(self): def _convert_time_and_date_block(self): [time_or_date] = self.arguments switcher = { - "second": str(catformula.Sensors.TIME_SECOND), - "minute": str(catformula.Sensors.TIME_MINUTE), - "hour": str(catformula.Sensors.TIME_HOUR), - "day of week": str(catformula.Sensors.DATE_WEEKDAY), - "date": str(catformula.Sensors.DATE_DAY), - "month": str(catformula.Sensors.DATE_MONTH), - "year": str(catformula.Sensors.DATE_YEAR) + "SECOND": str(catformula.Sensors.TIME_SECOND), + "MINUTE": str(catformula.Sensors.TIME_MINUTE), + "HOUR": str(catformula.Sensors.TIME_HOUR), + "DAYOFWEEK": str(catformula.Sensors.DATE_WEEKDAY), + "DATE": str(catformula.Sensors.DATE_DAY), + "MONTH": str(catformula.Sensors.DATE_MONTH), + "YEAR": str(catformula.Sensors.DATE_YEAR) } converted_time_or_date = switcher.get(time_or_date, "ERROR") if converted_time_or_date == "ERROR": return catbricks.NoteBrick("Can't convert Time-And-Date Block.") time_formula = catformula.FormulaElement(catformula.FormulaElement.ElementType.SENSOR, converted_time_or_date, None) - if time_or_date == "day of week": + if time_or_date == "DAYOFWEEK": time_formula = self._converted_helper_brick_or_formula_element([time_formula, 1], "+") return time_formula diff --git a/src/scratchtocatrobat/converter/test_converter.py b/src/scratchtocatrobat/converter/test_converter.py index 56afa664..0dcc9200 100644 --- a/src/scratchtocatrobat/converter/test_converter.py +++ b/src/scratchtocatrobat/converter/test_converter.py @@ -1945,28 +1945,28 @@ def test_can_convert_delete_clone_block(self): # timeAndDate def test_can_convert_time_and_date_block_second(self): - scratch_block = ["timeAndDate", "second"] + scratch_block = ["timeAndDate", "SECOND"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.TIME_SECOND) # timeAndDate def test_can_convert_time_and_date_block_minute(self): - scratch_block = ["timeAndDate", "minute"] + scratch_block = ["timeAndDate", "MINUTE"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.TIME_MINUTE) # timeAndDate def test_can_convert_time_and_date_block_hour(self): - scratch_block = ["timeAndDate", "hour"] + scratch_block = ["timeAndDate", "HOUR"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.TIME_HOUR) # timeAndDate def test_can_convert_time_and_date_block_weekday(self): - scratch_block = ["timeAndDate", "day of week"] + scratch_block = ["timeAndDate", "DAYOFWEEK"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Operators.PLUS) @@ -1975,21 +1975,21 @@ def test_can_convert_time_and_date_block_weekday(self): # timeAndDate def test_can_convert_time_and_date_block_date(self): - scratch_block = ["timeAndDate", "date"] + scratch_block = ["timeAndDate", "DATE"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.DATE_DAY) # timeAndDate def test_can_convert_time_and_date_block_month(self): - scratch_block = ["timeAndDate", "month"] + scratch_block = ["timeAndDate", "MONTH"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.DATE_MONTH) # timeAndDate def test_can_convert_time_and_date_block_year(self): - scratch_block = ["timeAndDate", "year"] + scratch_block = ["timeAndDate", "YEAR"] [catr_brick] = self.block_converter._catrobat_bricks_from(scratch_block, DUMMY_CATR_SPRITE) assert isinstance(catr_brick, catformula.FormulaElement) assert catr_brick.getValue() == str(catformula.Sensors.DATE_YEAR) diff --git a/src/scratchtocatrobat/scratch/scratch3.py b/src/scratchtocatrobat/scratch/scratch3.py index ff543f5d..bebc4ab1 100644 --- a/src/scratchtocatrobat/scratch/scratch3.py +++ b/src/scratchtocatrobat/scratch/scratch3.py @@ -130,7 +130,7 @@ def parse_monitor(monitor): "motion_xposition": "x position", "motion_yposition": "y position" } - MONITOR_CURRENT_MAPPING = { + MONITOR_LABEL_CURRENT_MAPPING = { "YEAR": "year", "MONTH": "month", "DATE": "date", @@ -141,7 +141,7 @@ def parse_monitor(monitor): } MONITOR_PARAM_MAPPING = { "data_variable": lambda param: param["VARIABLE"], - "sensing_current": lambda param: MONITOR_CURRENT_MAPPING[param["CURRENTMENU"]] + "sensing_current": lambda param: param["CURRENTMENU"] } if not monitor["mode"] in MONITOR_MODE_MAPPING: log.warn("Monitor with unknown mode will not be created.") @@ -175,7 +175,9 @@ def parse_monitor(monitor): return None target = monitor.get("spriteName", None) param = (MONITOR_PARAM_MAPPING[monitor["opcode"]](monitor["params"]) if monitor["opcode"] in MONITOR_PARAM_MAPPING else None) - if monitor["opcode"] in ["data_variable", "sensing_current"]: + if monitor["opcode"] == "sensing_current": + label = MONITOR_LABEL_CURRENT_MAPPING[param] + elif monitor["opcode"] == "data_variable": label = param else: label = MONITOR_LABEL_MAPPING[monitor["opcode"]] diff --git a/src/scratchtocatrobat/scratch/scratch3visitor/sensing.py b/src/scratchtocatrobat/scratch/scratch3visitor/sensing.py index 73c184a2..45c50191 100644 --- a/src/scratchtocatrobat/scratch/scratch3visitor/sensing.py +++ b/src/scratchtocatrobat/scratch/scratch3visitor/sensing.py @@ -58,8 +58,7 @@ def visitTouchingobject(blockcontext): def visitCurrent(blockcontext): block = blockcontext.block - time = visitGeneric(blockcontext, "CURRENTMENU") - return ["timeAndDate", time] + return ["timeAndDate", block.fields["CURRENTMENU"][0]] def visitCurrent_menu(blockcontext): block = blockcontext.block diff --git a/src/scratchtocatrobat/scratch/scratch3visitor/test_scratch3.py b/src/scratchtocatrobat/scratch/scratch3visitor/test_scratch3.py index 7f7ab719..37518cd4 100644 --- a/src/scratchtocatrobat/scratch/scratch3visitor/test_scratch3.py +++ b/src/scratchtocatrobat/scratch/scratch3visitor/test_scratch3.py @@ -696,12 +696,8 @@ def test_visitColoristouchingcolor(self): def test_visitCurrent(self): context = create_block_context(opcodes.SENSING_CURRENT) - - menublock = createScratch3Block(context, opcodes.SENSING_CURRENT_MENU) - addFieldOfType(menublock, MenuTypes.CURRENT_MENU, AbstractType.YEAR) - addInputOfType(context.block, MenuTypes.CURRENT_MENU, LiteralType.SHADOW_BLOCK, menublock.name) + addFieldOfType(context.block, MenuTypes.CURRENT_MENU, AbstractType.YEAR) converted_block = visitBlock(context) - assert converted_block[0] == opcodes.opcode_map[opcodes.SENSING_CURRENT] assert converted_block[1] == AbstractInput.YEAR