Skip to content

Commit

Permalink
Merge pull request #13369 from code-dot-org/fix-levelbuilder-playlab-js
Browse files Browse the repository at this point in the history
Fix some bad assumptions in playlab blocks
  • Loading branch information
Hamms committed Feb 23, 2017
2 parents e9cf946 + bd5a0e4 commit b46549b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
16 changes: 16 additions & 0 deletions apps/src/studio/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ exports.install = function (blockly, blockInstallOptions) {
var isK1 = blockInstallOptions.isK1;
var generator = blockly.Generator.get('JavaScript');
blockly.JavaScript = generator;

// Add some defaults; specifically for those values we expect to be
// arrays, so that we can blindly .filter, .map, and .slice them, else
// we will fail horribly for any environment that doesn't define a
// fully-featured skin
skin.activityChoices = valueOr(skin.activityChoices, []);
skin.avatarList = valueOr(skin.avatarList, []);
skin.backgroundChoices = valueOr(skin.backgroundChoices, []);
skin.itemChoices = valueOr(skin.itemChoices, []);
skin.mapChoices = valueOr(skin.mapChoices, []);
skin.projectileChoices = valueOr(skin.projectileChoices, []);
skin.sounds = valueOr(skin.sounds, []);
skin.soundChoices = valueOr(skin.soundChoices, []);
skin.soundChoicesK1 = valueOr(skin.soundChoicesK1, []);
skin.spriteChoices = valueOr(skin.spriteChoices, []);

startAvatars = skin.avatarList.slice(0); // copy avatar list

generator.studio_eventHandlerPrologue = function () {
Expand Down
23 changes: 14 additions & 9 deletions apps/src/studio/paramLists.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,27 @@ exports.getPlaySoundValues = function (withRandom) {
} else {
names = [];
}
names = names.concat(skin.sounds);
if (withRandom) {
// Insert a random value for each sound group before the first sound in the group:
for (var group in skin.soundGroups) {
var insertIndex = names.indexOf(group + skin.soundGroups[group].minSuffix);
if (insertIndex !== -1) {
names.splice(insertIndex, 0, skin.soundGroups[group].randomValue);

if (skin && skin.sounds) {
names = names.concat(skin.sounds);
if (withRandom) {
// Insert a random value for each sound group before the first sound in the group:
for (var group in skin.soundGroups) {
var insertIndex = names.indexOf(group + skin.soundGroups[group].minSuffix);
if (insertIndex !== -1) {
names.splice(insertIndex, 0, skin.soundGroups[group].randomValue);
}
}
}
}
var restrictions = level.paramRestrictions && level.paramRestrictions.playSound;
if (restrictions) {

if (level && level.paramRestrictions && level.paramRestrictions.playSound) {
var restrictions = level.paramRestrictions.playSound;
names = names.filter(function (name) {
return restrictions[name];
});
}

return names;
};

Expand Down

0 comments on commit b46549b

Please sign in to comment.