Skip to content
New issue

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

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

Already on GitHub? # to your account

STCC-140 handling of FormulaElement in sound bricks #167

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion config/default.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Scratch2Catrobat Converter
short_name: S2CC
version: 0.10.0
build_name: Aegean cat
build_number: 1020
build_number: 1023
build_type: S2CC

;-------------------------------------------------------------------------------
Expand Down
34 changes: 19 additions & 15 deletions src/scratchtocatrobat/converter/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2097,26 +2097,30 @@ def _convert_hide_list_block(self):
#[list_name] = self.arguments
assert "IMPLEMENT THIS AS SOON AS CATROBAT SUPPORTS THIS!!"

@_register_handler(_block_name_to_handler_map, "playSound:")
@_register_handler(_block_name_to_handler_map, "playSound:", "doPlaySoundAndWait")
def _convert_sound_block(self):
[sound_name], sound_list = self.arguments, self.sprite.getSoundList()
sound_data = {sound_info.getName(): sound_info for sound_info in sound_list}.get(sound_name)
if not sound_data:
log.warning("Sprite does not contain sound with name={}".format(sound_name))
[sound_parameter], sound_list = self.arguments, self.sprite.getSoundList()
sound_data = {sound_info.getName(): sound_info for sound_info in sound_list}.get(sound_parameter)

# while scratch allows strings and numbers as parameter for the "play sound"-bricks
# pocket code has only the drop down menu for sound selection
# until pocket code does not support custom parameters for these bricks the converter selects the first
# sound in the list, if available
if len(sound_list) == 0:
log.warning("The sound list is empty! No sound will be played with this brick!")
elif isinstance(sound_parameter, catformula.FormulaElement):
log.warning("Pocket code does not support formulas or variables as input for the \"play sound\"-bricks. "\
"Using the first sound in the sound list instead!")
sound_data = sound_list[0]
elif isinstance(sound_parameter, unicode) and not sound_data:
log.warning("Sprite does not contain sound with name=\"{}\". ".format(sound_parameter) + \
"Using the first sound in the sound list instead!")
sound_data = sound_list[0]

play_sound_brick = self.CatrobatClass()
play_sound_brick.setSound(sound_data)
return play_sound_brick

@_register_handler(_block_name_to_handler_map, "doPlaySoundAndWait")
def _convert_sound_and_wait_block(self):
[sound_name], sound_list = self.arguments, self.sprite.getSoundList()
sound_data = {sound_info.getName(): sound_info for sound_info in sound_list}.get(sound_name)
if not sound_data:
log.warning("Sprite does not contain sound with name={}".format(sound_name))
play_sound_and_wait_brick = self.CatrobatClass()
play_sound_and_wait_brick.setSound(sound_data)
return play_sound_and_wait_brick

@_register_handler(_block_name_to_handler_map, "setGraphicEffect:to:")
def _convert_set_graphic_effect_block(self):
[effect_type, value] = self.arguments
Expand Down