summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules12
m---------Snapin8r0
-rw-r--r--blocks.js36
-rw-r--r--github.js312
-rw-r--r--gui.js482
-rw-r--r--objects.js179
m---------octokit.js0
-rw-r--r--paint.js7
-rw-r--r--promise-1.0.0.js684
-rwxr-xr-xsnap.html9
-rw-r--r--store.js6
-rw-r--r--threads.js60
-rw-r--r--tools.xml2
m---------vkBeautify0
14 files changed, 1758 insertions, 31 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..c1a2763
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,12 @@
+[submodule "Snapin8r"]
+ path = Snapin8r
+ url = https://github.com/Hardmath123/Snapin8r
+[submodule "octokit.js"]
+ path = octokit.js
+ url = https://github.com/philschatz/octokit.js
+[submodule "vkBeautify"]
+ path = vkBeautify
+ url = https://github.com/vkiryukhin/vkBeautify
+[submodule "diff-merge"]
+ path = diff-merge
+ url = https://github.com/nighca/diff-merge
diff --git a/Snapin8r b/Snapin8r
new file mode 160000
+Subproject c9cebaa147c2c53520212a221efd4061a5dcb19
diff --git a/blocks.js b/blocks.js
index 35f31a4..6210e22 100644
--- a/blocks.js
+++ b/blocks.js
@@ -992,6 +992,8 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
null,
false,
{
+ 'any key': ['any key'],
+ 'number key': ['number key'],
'up arrow': ['up arrow'],
'down arrow': ['down arrow'],
'right arrow': ['right arrow'],
@@ -7772,6 +7774,8 @@ SymbolMorph.prototype.names = [
'pointRight',
'gears',
'file',
+ 'mutedSounds',
+ 'unmutedSounds',
'fullScreen',
'normalScreen',
'smallStage',
@@ -7896,6 +7900,10 @@ SymbolMorph.prototype.symbolCanvasColored = function (aColor) {
return this.drawSymbolGears(canvas, aColor);
case 'file':
return this.drawSymbolFile(canvas, aColor);
+ case 'mutedSounds':
+ return this.drawSymbolMutedSounds(canvas, aColor);
+ case 'unmutedSounds':
+ return this.drawSymbolUnmutedSounds(canvas, aColor);
case 'fullScreen':
return this.drawSymbolFullScreen(canvas, aColor);
case 'normalScreen':
@@ -8098,6 +8106,34 @@ SymbolMorph.prototype.drawSymbolFile = function (canvas, color) {
return canvas;
};
+SymbolMorph.prototype.drawSymbolMutedSounds = function (canvas, color) {
+ // answer a canvas showing a muted sounds toggling symbol
+ var ctx = canvas.getContext('2d'),
+ w = canvas.width,
+ h = canvas.height,
+ w2 = w / 2,
+ h2 = h / 2;
+
+ ctx.fillStyle = color.darker(40).toString();
+ ctx.fillRect(0, 0, w, h);
+
+ return canvas;
+};
+
+SymbolMorph.prototype.drawSymbolUnmutedSounds = function (canvas, color) {
+ // answer a canvas showing a UNmuted sounds toggling symbol
+ var ctx = canvas.getContext('2d'),
+ w = canvas.width,
+ h = canvas.height,
+ w2 = w / 2,
+ h2 = h / 2;
+
+ ctx.fillStyle = color.darker(60).toString();
+ ctx.fillRect(0, 0, w, h);
+
+ return canvas;
+};
+
SymbolMorph.prototype.drawSymbolFullScreen = function (canvas, color) {
// answer a canvas showing two arrows pointing diagonally outwards
var ctx = canvas.getContext('2d'),
diff --git a/github.js b/github.js
new file mode 100644
index 0000000..5294037
--- /dev/null
+++ b/github.js
@@ -0,0 +1,312 @@
+/*
+
+ github.js
+
+ a GitHubBackend backend API for SNAP!
+
+ written by Gubolin, based on cloud.js by Jens Mönig
+
+ Copyright (C) 2014 by Jens Mönig, Gubolin
+
+ This file is part of Snap!.
+
+ Snap! is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of
+ the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+// Global settings /////////////////////////////////////////////////////
+
+/*global modules, localize*/
+
+modules.github = '2014-July-31';
+
+// Global stuff
+
+var GitHubBackend;
+
+var GitHub = new GitHubBackend();
+
+// GitHubBackend /////////////////////////////////////////////////////////////
+
+function GitHubBackend() {
+ this.gh = null;
+ this.username = null;
+ this.password = null; // TODO saved as plain text
+}
+
+GitHubBackend.prototype.clear = function () {
+ this.gh = null;
+ this.username = null;
+ this.password = null;
+};
+
+// GitHubBackend: Snap! API
+
+GitHubBackend.prototype.getProject = function (
+ userName,
+ projectName,
+ callBack,
+ errorCall,
+ commitSha
+) {
+ var myself = this;
+
+ if (myself.gh === null) {
+ myself.gh = new Octokit();
+ }
+
+ var repo = myself.gh.getRepo(userName, projectName);
+ var branch = repo.getBranch(); // master (default)
+ branch.getCommits({}).then(
+ function (commits) {
+ branch.read('snap.xml', false).then(
+ function (sourceContent) {
+ callBack.call(
+ null,
+ sourceContent.content,
+ commits[0].sha
+ );
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+};
+
+GitHubBackend.prototype.login = function (
+ username,
+ password,
+ validateData,
+ callBack,
+ errorCall
+) {
+ var myself = this;
+ var me;
+
+ myself.gh = new Octokit({
+ username: username,
+ password: password
+ });
+
+ if (validateData === true) {
+ me = myself.gh.getUser();
+ if (me !== null) {
+ me.getInfo().then(
+ function() {
+ myself.username = username;
+ myself.password = password;
+
+ callBack.call(myself);
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ } else {
+ errorCall.call(myself, localize('Something went wrong :('), 'GitHub');
+ }
+ } else {
+ myself.username = username;
+ myself.password = password;
+
+ callBack.call(myself);
+ }
+};
+
+GitHubBackend.prototype.saveProject = function (commitMessage, parentCommitSha, lastCommit, ide, callBack, errorCall) {
+ var myself = this,
+ data;
+ var pdata, media;
+ var repoName = ide.projectName.replace(/[^\w-]/g, ''); // TODO validation of project name
+
+ ide.stage.fireStopAllEvent();
+ ide.serializer.isCollectingMedia = true;
+ pdata = ide.serializer.serialize(ide.stage);
+ media = ide.hasChangedMedia ?
+ ide.serializer.mediaXML(ide.projectName) : null;
+ data = '<snapdata>\n' + pdata + '\n' + media + '\n</snapdata>';
+
+ // check if serialized data can be parsed back again
+ try {
+ ide.serializer.parse(pdata);
+ } catch (err) {
+ ide.showMessage('Serialization of program data failed:\n' + err);
+ throw new Error('Serialization of program data failed:\n' + err);
+ }
+ if (media !== null) {
+ try {
+ ide.serializer.parse(media);
+ } catch (err) {
+ ide.showMessage('Serialization of media failed:\n' + err);
+ throw new Error('Serialization of media failed:\n' + err);
+ }
+ }
+ ide.serializer.isCollectingMedia = false;
+ ide.serializer.flushMedia();
+
+ myself.getProjectList(
+ function (projects) {
+ var exists = false;
+
+ projects.forEach(function (project) {
+ if (project.ProjectName.indexOf(repoName) > -1) {
+ exists = true;
+ return;
+ }
+ });
+
+ pushChanges = function () {
+ if (myself.gh !== null) {
+ var repo = myself.gh.getRepo(myself.username, ide.projectName);
+ var branch = repo.getBranch(); // master (default)
+ var message = commitMessage;
+
+ writeChanges = function (code, pcSha) {
+ if (pcSha !== parentCommitSha && data !== code) {
+ var compareResult = window.diff.compare(lastCommit, data, '\n'); // get diff from last push
+ data = window.diff.merge(code, compareResult); // apply it to the latest code
+ console.log(data);
+ }
+
+ var contents = {
+ 'snap.xml': data,
+ 'README.md': ide.projectNotes
+ };
+
+ branch.writeMany(contents, message, pcSha).then(
+ function () {
+ callBack.call();
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ };
+
+ if (parentCommitSha !== null) { // repo was just created
+ myself.getProject(myself.username, ide.projectName,
+ writeChanges,
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ } else {
+ writeChanges(data, parentCommitSha);
+ }
+ }
+ };
+
+ if (exists === false){
+ myself.gh.getUser().createRepo(repoName, { // these should be discussed
+ 'description': 'Snap! Project - http://gubolin.github.io/snap/index.html#github:Username=' + myself.username + '&projectName=' + repoName,
+ 'has_wiki': 'false',
+ 'has_downloads': 'false',
+ 'auto_init': true,
+ 'license_template': 'mit' // discuss
+ }).then(
+ pushChanges,
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ } else {
+ pushChanges();
+ }
+
+ },
+ function (error) {
+ errorCall.call(null, error, 'GitHub');
+ }
+ );
+};
+
+GitHubBackend.prototype.getProjectList = function (callBack, errorCall) {
+ var myself = this;
+
+ if (myself.gh !== null){
+ var user = myself.gh.getUser();
+
+ if (user === null) {
+ myself.message('You are not logged in');
+ return;
+ }
+
+ user.getRepos().then(
+ function (repos) {
+ var snapProjects = [];
+
+ var modCallBack = (function () {
+ var called = 0;
+ return function () {
+ if (++called == repos.length) {
+ callBack.call(myself, snapProjects);
+ }
+ };
+ })();
+
+ if (repos.length === 0) {
+ callBack.call(myself, snapProjects);
+ }
+
+ repos.forEach(function (repo) {
+ if (repo.description.indexOf('Snap! Project') > -1) { // TODO nicer detection
+ var project, ghrepo, branch;
+
+ ghrepo = myself.gh.getRepo(repo.owner.login, repo.name);
+ branch = ghrepo.getBranch(); // master (default)
+
+ branch.read('README.md', false).then(
+ function (notesContent) {
+ project = {
+ 'ProjectName': repo.name,
+ 'Notes': notesContent.content,
+ 'Updated': repo.updated_at.replace(/T/, ' ').replace(/Z/, '') // TODO this could be better
+ };
+
+ snapProjects.push(project);
+ modCallBack();
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ } else {
+ modCallBack();
+ }
+ });
+ },
+ function (error) {
+ errorCall.call(this, error, 'GitHub');
+ }
+ );
+ } else {
+ myself.message('You are not logged in');
+ return;
+ }
+};
+
+GitHubBackend.prototype.logout = function (callBack) {
+ this.clear();
+};
+
+// GitHub: user messages (to be overridden)
+
+GitHubBackend.prototype.message = function (string) {
+ alert(string);
+};
diff --git a/gui.js b/gui.js
index 206b27a..2a2fde2 100644
--- a/gui.js
+++ b/gui.js
@@ -63,7 +63,7 @@ Costume, CostumeEditorMorph, MorphicPreferences, touchScreenSettings,
standardSettings, Sound, BlockMorph, ToggleMorph, InputSlotDialogMorph,
ScriptsMorph, isNil, SymbolMorph, BlockExportDialogMorph,
BlockImportDialogMorph, SnapTranslator, localize, List, InputSlotMorph,
-SnapCloud, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512,
+SnapCloud, GitHub, Uint8Array, HandleMorph, SVG_Costume, fontHeight, hex_sha512,
sb, CommentMorph, CommandBlockMorph, BlockLabelPlaceHolderMorph, Audio,
SpeechBubbleMorph*/
@@ -228,6 +228,7 @@ IDE_Morph.prototype.init = function (isAutoFill) {
this.corral = null;
this.isAutoFill = isAutoFill || true;
+ this.isMuted = false;
this.isAppMode = false;
this.isSmallStage = false;
this.filePicker = null;
@@ -237,6 +238,8 @@ IDE_Morph.prototype.init = function (isAutoFill) {
this.stageRatio = 1; // for IDE animations, e.g. when zooming
this.loadNewProject = false; // flag when starting up translated
+ this.parentCommitSha = null; // for GitHub
+ this.lastCommit = null; // for GitHub
this.shield = null;
// initialize inherited properties:
@@ -244,6 +247,8 @@ IDE_Morph.prototype.init = function (isAutoFill) {
// override inherited properites:
this.color = this.backgroundColor;
+
+ setInterval(this.save, 1000 * 60 * 60 * 5); // every 5 minutes
};
IDE_Morph.prototype.openIn = function (world) {
@@ -252,6 +257,7 @@ IDE_Morph.prototype.openIn = function (world) {
// get persistent user data, if any
if (localStorage) {
usr = localStorage['-snap-user'];
+ ghusr = localStorage['-snap-ghuser'];
if (usr) {
usr = SnapCloud.parseResponse(usr)[0];
if (usr) {
@@ -262,6 +268,13 @@ IDE_Morph.prototype.openIn = function (world) {
}
}
}
+ if (ghusr) {
+ ghusr = SnapCloud.parseResponse(ghusr)[0];
+ if (ghusr) {
+ GitHub.login(ghusr.username, ghusr.password, false,
+ function() {}, myself.githubError());
+ }
+ }
}
this.buildPanes();
@@ -279,6 +292,16 @@ IDE_Morph.prototype.openIn = function (world) {
}, 2000);
};
+ GitHub.message = function (string) {
+ var m = new MenuMorph(null, string),
+ intervalHandle;
+ m.popUpCenteredInWorld(world);
+ intervalHandle = setInterval(function () {
+ m.destroy();
+ clearInterval(intervalHandle);
+ }, 2000);
+ };
+
// prevent non-DialogBoxMorphs from being dropped
// onto the World in user-mode
world.reactToDropOf = function (morph) {
@@ -303,7 +326,8 @@ IDE_Morph.prototype.openIn = function (world) {
}
throw new Error('unable to retrieve ' + url);
} catch (err) {
- return;
+ myself.showMessage('unable to retrieve project');
+ return '';
}
}
@@ -390,6 +414,41 @@ IDE_Morph.prototype.openIn = function (world) {
},
this.cloudError()
);
+ } else if (location.hash.substr(0, 8) === '#github:') {
+ this.shield = new Morph();
+ this.shield.color = this.color;
+ this.shield.setExtent(this.parent.extent());
+ this.parent.add(this.shield);
+ myself.showMessage('Fetching project\nfrom GitHub...');
+
+ dict = SnapCloud.parseDict(location.hash.substr(8));
+
+ GitHub.getProject(
+ dict.Username,
+ dict.projectName,
+ function (code, pcSha) {
+ var msg;
+ myself.nextSteps([
+ function () {
+ msg = myself.showMessage('Opening GitHub project...');
+ },
+ function () {
+ myself.parentCommitSha = pcSha;
+ myself.lastCommit = code;
+ myself.rawOpenCloudDataString(code);
+ myself.hasChangedMedia = true;
+ },
+ function () {
+ myself.shield.destroy();
+ myself.shield = null;
+ msg.destroy();
+ myself.toggleAppMode(true);
+ myself.runScripts();
+ }
+ ]);
+ },
+ this.githubError()
+ );
} else if (location.hash.substr(0, 6) === '#lang:') {
urlLanguage = location.hash.substr(6);
this.setLanguage(urlLanguage);
@@ -474,6 +533,7 @@ IDE_Morph.prototype.createControlBar = function () {
stopButton,
pauseButton,
startButton,
+ muteSoundsButton,
projectButton,
settingsButton,
stageSizeButton,
@@ -563,6 +623,38 @@ IDE_Morph.prototype.createControlBar = function () {
this.controlBar.add(appModeButton);
this.controlBar.appModeButton = appModeButton; // for refreshing
+ //muteSoundsButton
+ button = new ToggleButtonMorph(
+ null, //colors,
+ myself, // the IDE is the target
+ 'toggleMuteSounds',
+ [
+ new SymbolMorph('mutedSounds', 14),
+ new SymbolMorph('unmutedSounds', 14)
+ ],
+ function () { // query
+ return myself.isMuted;
+ }
+ );
+
+ button.corner = 12;
+ button.color = colors[0];
+ button.highlightColor = colors[1];
+ button.pressColor = colors[2];
+ button.labelMinExtent = new Point(36, 18);
+ button.padding = 0;
+ button.labelShadowOffset = new Point(-1, -1);
+ button.labelShadowColor = colors[1];
+ button.labelColor = this.buttonLabelColor;
+ button.contrast = this.buttonContrast;
+ button.drawNew();
+ // button.hint = 'sounds\nmuted & unmuted';
+ button.fixLayout();
+ button.refresh();
+ muteSoundsButton = button;
+ this.controlBar.add(muteSoundsButton);
+ this.controlBar.muteSoundsButton = button; // for refreshing
+
// stopButton
button = new PushButtonMorph(
this,
@@ -727,7 +819,7 @@ IDE_Morph.prototype.createControlBar = function () {
myself.right() - StageMorph.prototype.dimensions.x *
(myself.isSmallStage ? myself.stageRatio : 1)
);
- [stageSizeButton, appModeButton].forEach(
+ [stageSizeButton, appModeButton, muteSoundsButton].forEach(
function (button) {
x += padding;
button.setCenter(myself.controlBar.center());
@@ -1587,7 +1679,12 @@ IDE_Morph.prototype.droppedBinary = function (anArrayBuffer, name) {
myself = this,
suffix = name.substring(name.length - 3);
- if (suffix.toLowerCase() !== 'ypr') {return; }
+ if (suffix.toLowerCase() !== 'ypr') {
+ var zip = new JSZip(anArrayBuffer);
+ myself.droppedText(Snapin8r(zip));
+
+ return;
+ }
function loadYPR(buffer, lbl) {
var reader = new sb.Reader(),
@@ -1990,6 +2087,18 @@ IDE_Morph.prototype.cloudMenu = function () {
'changeCloudPassword'
);
}
+
+ if (!GitHub.username) {
+ menu.addItem(
+ 'Login via GitHub...',
+ 'initializeGitHub'
+ );
+ } else {
+ menu.addItem(
+ localize('Logout') + ' ' + GitHub.username + ' ' + localize('from GitHub'),
+ 'logoutGitHub'
+ );
+ }
if (shiftClicked) {
menu.addLine();
menu.addItem(
@@ -2309,6 +2418,9 @@ IDE_Morph.prototype.projectMenu = function () {
menu.addItem('New', 'createNewProject');
menu.addItem('Open...', 'openProjectsBrowser');
menu.addItem('Save', "save");
+ if (GitHub.username) {
+ menu.addItem('Save with commit message', 'commitProjectToGitHub');
+ }
if (shiftClicked) {
menu.addItem(
'Save to disk',
@@ -2759,8 +2871,10 @@ IDE_Morph.prototype.save = function () {
if (this.projectName) {
if (this.source === 'local') { // as well as 'examples'
this.saveProject(this.projectName);
- } else { // 'cloud'
+ } else if (this.source === 'cloud') { // 'cloud'
this.saveProjectToCloud(this.projectName);
+ } else { // 'github'
+ this.saveProjectToGitHub(this.projectName);
}
} else {
this.saveProjectsBrowser();
@@ -3430,6 +3544,27 @@ IDE_Morph.prototype.toggleStageSize = function (isSmall) {
}
};
+IDE_Morph.prototype.toggleMuteSounds = function (isMuted) {
+ this.isMuted = isNil(isMuted) ? !this.isMuted : isMuted;
+ this.controlBar.muteSoundsButton.refresh();
+
+ /* stage.activeSounds holds all active sounds
+ * a sprite's .activeSounds holds just its own
+ * so you have to use the stage to mute
+ * and the sprite to unmute, because the stage's volume
+ * overrides the sprite's one.
+ */
+
+ if (this.isMuted === false) {
+ this.stage.unmuteAllSounds();
+ this.sprites.asArray().forEach(function (sprt) {
+ sprt.unmuteAllSounds();
+ });
+ } else {
+ this.stage.muteAllSounds();
+ }
+};
+
IDE_Morph.prototype.createNewProject = function () {
var myself = this;
this.confirm(
@@ -3491,6 +3626,12 @@ IDE_Morph.prototype.setLanguage = function (lang, callback) {
IDE_Morph.prototype.reflectLanguage = function (lang, callback) {
var projectData;
SnapTranslator.language = lang;
+ this.world().children.forEach(function (morph) {
+ if (morph instanceof BlockEditorMorph) {
+ morph.updateDefinition(); // save custom blocks
+ // otherwise, initBlocks() will reset the definition
+ }
+ });
if (!this.loadNewProject) {
if (Process.prototype.isCatchingErrors) {
try {
@@ -3723,6 +3864,48 @@ IDE_Morph.prototype.initializeCloud = function () {
);
};
+IDE_Morph.prototype.initializeGitHub = function () {
+ var myself = this,
+ world = this.world();
+ new DialogBoxMorph(
+ null,
+ function (user) {
+ var pw = user.password,
+ str;
+ GitHub.login(
+ user.username,
+ pw,
+ true,
+ function () {
+ if (user.choice) {
+ str = SnapCloud.encodeDict(
+ {
+ username: user.username,
+ password: pw
+ }
+ );
+ localStorage['-snap-ghuser'] = str;
+ }
+ myself.source = 'github';
+ myself.showMessage('now connected.', 2);
+ },
+ myself.githubError()
+ );
+ }
+ ).withKey('cloudlogin').promptCredentials(
+ 'Sign in with your GitHub account',
+ 'login',
+ null,
+ null,
+ null,
+ null,
+ 'stay signed in on this computer\nuntil logging out',
+ world,
+ myself.cloudIcon(),
+ myself.cloudMsg
+ );
+};
+
IDE_Morph.prototype.createCloudAccount = function () {
var myself = this,
world = this.world();
@@ -3850,6 +4033,19 @@ IDE_Morph.prototype.logout = function () {
);
};
+IDE_Morph.prototype.logoutGitHub = function () {
+ var myself = this;
+ delete localStorage['-snap-ghuser'];
+ GitHub.logout(
+ function () {
+ myself.showMessage('disconnected.', 2);
+ },
+ function () {
+ myself.showMessage('disconnected.', 2);
+ }
+ );
+};
+
IDE_Morph.prototype.saveProjectToCloud = function (name) {
var myself = this;
if (name) {
@@ -3863,6 +4059,90 @@ IDE_Morph.prototype.saveProjectToCloud = function (name) {
}
};
+IDE_Morph.prototype.saveProjectToGitHub = function (name, commitMessage) {
+ var myself = this;
+ if (name) {
+ this.showMessage('Comitting project\nto GitHub...');
+ this.setProjectName(name);
+ GitHub.saveProject(
+ commitMessage,
+ this.parentCommitSha,
+ this.lastCommit,
+ this,
+ function () {
+ GitHub.getProject(
+ GitHub.username,
+ name,
+ function (code, pcSha) {
+ myself.source = 'github';
+ myself.parentCommitSha = pcSha;
+ myself.lastCommit = code;
+ myself.droppedText(code);
+ },
+ myself.githubError()
+ );
+ },
+ this.githubError()
+ );
+ }
+};
+
+IDE_Morph.prototype.commitProjectToGitHub = function () {
+ var dialog = new DialogBoxMorph().withKey('commitMessage'),
+ frame = new ScrollFrameMorph(),
+ text = new TextMorph(''),
+ ok = dialog.ok,
+ myself = this,
+ size = 120,
+ world = this.world();
+
+ frame.padding = 6;
+ frame.setWidth(size);
+ frame.acceptsDrops = false;
+ frame.contents.acceptsDrops = false;
+
+ text.setWidth(size - frame.padding * 2);
+ text.setPosition(frame.topLeft().add(frame.padding));
+ text.enableSelecting();
+ text.isEditable = true;
+
+ frame.setHeight(size);
+ frame.fixLayout = nop;
+ frame.edge = InputFieldMorph.prototype.edge;
+ frame.fontSize = InputFieldMorph.prototype.fontSize;
+ frame.typeInPadding = InputFieldMorph.prototype.typeInPadding;
+ frame.contrast = InputFieldMorph.prototype.contrast;
+ frame.drawNew = InputFieldMorph.prototype.drawNew;
+ frame.drawRectBorder = InputFieldMorph.prototype.drawRectBorder;
+
+ frame.addContents(text);
+ text.drawNew();
+
+ dialog.ok = function () {
+ myself.saveProjectToGitHub(
+ myself.projectName,
+ text.text
+ );
+
+ ok.call(this);
+ };
+
+ dialog.justDropped = function () {
+ text.edit();
+ };
+
+ dialog.labelString = 'Commit message';
+ dialog.createLabel();
+ dialog.addBody(frame);
+ frame.drawNew();
+ dialog.addButton('ok', 'OK');
+ dialog.addButton('cancel', 'Cancel');
+ dialog.fixLayout();
+ dialog.drawNew();
+ dialog.popUp(world);
+ dialog.setCenter(world.center());
+ text.edit();
+};
IDE_Morph.prototype.exportProjectMedia = function (name) {
var menu, media;
this.serializer.isCollectingMedia = true;
@@ -4064,6 +4344,42 @@ IDE_Morph.prototype.cloudError = function () {
};
};
+IDE_Morph.prototype.githubError = function () {
+ var myself = this;
+
+ function getURL(url) {
+ try {
+ var request = new XMLHttpRequest();
+ request.open('GET', url, false);
+ request.send();
+ if (request.status === 200) {
+ return request.responseText;
+ }
+ return null;
+ } catch (err) {
+ return null;
+ }
+ }
+
+ return function (responseText, url) {
+ var response = responseText;
+ if (myself.shield) {
+ myself.shield.destroy();
+ myself.shield = null;
+ }
+ if (response.length > 50) {
+ response = response.substring(0, 50) + '...';
+ }
+ new DialogBoxMorph().inform(
+ 'GitHub',
+ (url ? url + '\n' : '')
+ + response,
+ myself.world(),
+ myself.cloudIcon(null, new Color(180, 0, 0))
+ );
+ };
+};
+
IDE_Morph.prototype.cloudIcon = function (height, color) {
var clr = color || DialogBoxMorph.prototype.titleBarColor,
isFlat = MorphicPreferences.isFlat,
@@ -4194,7 +4510,7 @@ ProjectDialogMorph.prototype.init = function (ide, task) {
// additional properties:
this.ide = ide;
this.task = task || 'open'; // String describing what do do (open, save)
- this.source = ide.source || 'local'; // or 'cloud' or 'examples'
+ this.source = ide.source || 'local'; // or 'cloud' or 'github' or 'examples'
this.projectList = []; // [{name: , thumb: , notes:}]
this.handle = null;
@@ -4254,6 +4570,7 @@ ProjectDialogMorph.prototype.buildContents = function () {
}
this.addSourceButton('cloud', localize('Cloud'), 'cloud');
+ this.addSourceButton('github', localize('GitHub'), 'github');
this.addSourceButton('local', localize('Browser'), 'storage');
if (this.task === 'open') {
this.addSourceButton('examples', localize('Examples'), 'poster');
@@ -4502,6 +4819,20 @@ ProjectDialogMorph.prototype.setSource = function (source) {
}
);
return;
+ case 'github':
+ msg = myself.ide.showMessage('Updating\nproject list...');
+ this.projectList = [];
+ GitHub.getProjectList(
+ function (projectList) {
+ myself.installGitHubProjectList(projectList);
+ msg.destroy();
+ },
+ function (err, lbl) {
+ msg.destroy();
+ myself.ide.githubError().call(null, err, lbl);
+ }
+ );
+ return;
case 'examples':
this.projectList = this.getExamplesProjectList();
break;
@@ -4554,7 +4885,7 @@ ProjectDialogMorph.prototype.setSource = function (source) {
}
myself.edit();
};
- } else { // 'examples', 'cloud' is initialized elsewhere
+ } else { // 'examples', 'cloud' and 'github' is initialized elsewhere
this.listField.action = function (item) {
var src, xml;
if (item === undefined) {return; }
@@ -4720,6 +5051,69 @@ ProjectDialogMorph.prototype.installCloudProjectList = function (pl) {
}
};
+ProjectDialogMorph.prototype.installGitHubProjectList = function (pl) {
+ var myself = this;
+ this.projectList = pl || [];
+ this.projectList.sort(function (x, y) {
+ return x.ProjectName < y.ProjectName ? -1 : 1;
+ });
+
+ this.listField.destroy();
+ this.listField = new ListMorph(
+ this.projectList,
+ this.projectList.length > 0 ?
+ function (element) {
+ return element.ProjectName;
+ } : null,
+ [],
+ function () {myself.ok(); }
+ );
+ this.fixListFieldItemColors();
+ this.listField.fixLayout = nop;
+ this.listField.edge = InputFieldMorph.prototype.edge;
+ this.listField.fontSize = InputFieldMorph.prototype.fontSize;
+ this.listField.typeInPadding = InputFieldMorph.prototype.typeInPadding;
+ this.listField.contrast = InputFieldMorph.prototype.contrast;
+ this.listField.drawNew = InputFieldMorph.prototype.drawNew;
+ this.listField.drawRectBorder = InputFieldMorph.prototype.drawRectBorder;
+
+ this.listField.action = function (item) {
+ if (item === undefined) {return; }
+ if (myself.nameField) {
+ myself.nameField.setContents(item.ProjectName || '');
+ }
+ if (myself.task === 'open') {
+ myself.notesText.text = item.Notes || '';
+ myself.notesText.drawNew();
+ myself.notesField.contents.adjustBounds();
+ myself.preview.texture = item.Thumbnail || null;
+ myself.preview.cachedTexture = null;
+ myself.preview.drawNew();
+ (new SpeechBubbleMorph(new TextMorph(
+ localize('last changed') + '\n' + item.Updated,
+ null,
+ null,
+ null,
+ null,
+ 'center'
+ ))).popUp(
+ myself.world(),
+ myself.preview.rightCenter().add(new Point(2, 0))
+ );
+ }
+ myself.buttons.fixLayout();
+ myself.fixLayout();
+ myself.edit();
+ };
+ this.body.add(this.listField);
+ this.deleteButton.show();
+ this.buttons.fixLayout();
+ this.fixLayout();
+ if (this.task === 'open') {
+ this.clearDetails();
+ }
+};
+
ProjectDialogMorph.prototype.clearDetails = function () {
this.notesText.text = '';
this.notesText.drawNew();
@@ -4736,6 +5130,8 @@ ProjectDialogMorph.prototype.openProject = function () {
this.ide.source = this.source;
if (this.source === 'cloud') {
this.openCloudProject(proj);
+ } else if (this.source === 'github') {
+ this.openGitHubProject(proj);
} else if (this.source === 'examples') {
src = this.ide.getURL(
'http://snap.berkeley.edu/snapsource/Examples/' +
@@ -4761,6 +5157,23 @@ ProjectDialogMorph.prototype.openCloudProject = function (project) {
]);
};
+ProjectDialogMorph.prototype.openGitHubProject = function (project, user) {
+ var myself = this;
+
+ if (user == null) { // jshint ignore:line
+ user = GitHub.username;
+ }
+
+ myself.ide.nextSteps([
+ function () {
+ myself.ide.showMessage('Fetching project\nfrom GitHub...');
+ },
+ function () {
+ myself.rawOpenGitHubProject(project, user);
+ }
+ ]);
+};
+
ProjectDialogMorph.prototype.rawOpenCloudProject = function (proj) {
var myself = this;
SnapCloud.reconnect(
@@ -4787,6 +5200,21 @@ ProjectDialogMorph.prototype.rawOpenCloudProject = function (proj) {
this.destroy();
};
+ProjectDialogMorph.prototype.rawOpenGitHubProject = function (proj, user) {
+ var myself = this;
+ GitHub.getProject(
+ user,
+ proj.ProjectName,
+ function (code, pcSha) {
+ myself.ide.source = 'github';
+ myself.ide.parentCommitSha = pcSha;
+ myself.ide.lastCommit = code;
+ myself.ide.droppedText(code);
+ },
+ myself.ide.githubError()
+ );
+ this.destroy();
+};
ProjectDialogMorph.prototype.saveProject = function () {
var name = this.nameField.contents().text.text,
notes = this.notesText.text,
@@ -4813,6 +5241,25 @@ ProjectDialogMorph.prototype.saveProject = function () {
this.ide.setProjectName(name);
myself.saveCloudProject();
}
+ } else if (this.source === 'github') {
+ if (detect(
+ this.projectList,
+ function (item) {return item.ProjectName === name; }
+ )) {
+ this.ide.confirm(
+ localize(
+ 'Are you sure you want to replace'
+ ) + '\n"' + name + '"?',
+ 'Replace Project',
+ function () {
+ myself.ide.setProjectName(name);
+ myself.saveGitHubProject();
+ }
+ );
+ } else {
+ this.ide.setProjectName(name);
+ myself.saveGitHubProject();
+ }
} else { // 'local'
if (detect(
this.projectList,
@@ -4854,13 +5301,32 @@ ProjectDialogMorph.prototype.saveCloudProject = function () {
this.destroy();
};
+ProjectDialogMorph.prototype.saveGitHubProject = function () {
+ var myself = this;
+ this.ide.showMessage('Committing project\nto GitHub...');
+ GitHub.saveProject(
+ null,
+ this.ide.parentCommitSha,
+ this.ide.lastCommit,
+ this.ide,
+ function () {
+ myself.ide.source = 'github';
+ myself.ide.showMessage('saved.', 2);
+ },
+ this.ide.githubError()
+ );
+ this.destroy();
+};
+
ProjectDialogMorph.prototype.deleteProject = function () {
var myself = this,
proj,
idx,
name;
- if (this.source === 'cloud') {
+ if (this.source === 'github') {
+ // TODO: not implemented
+ } else if (this.source === 'cloud') {
proj = this.listField.selected;
if (proj) {
this.ide.confirm(
diff --git a/objects.js b/objects.js
index cb9ad4b..cf4d0ea 100644
--- a/objects.js
+++ b/objects.js
@@ -464,6 +464,23 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sound',
spec: 'stop all sounds'
},
+ doSetVolume: {
+ type: 'command',
+ category: 'sound',
+ spec: 'set volume to %n %',
+ defaults: [100]
+ },
+ doChangeVolume: {
+ type: 'command',
+ category: 'sound',
+ spec: 'change volume by %n',
+ defaults: [-10]
+ },
+ reportVolume: {
+ type: 'reporter',
+ category: 'sound',
+ spec: 'volume'
+ },
doRest: {
type: 'command',
category: 'sound',
@@ -868,6 +885,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sensing',
spec: 'key %key pressed?'
},
+ getKeysPressed: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'keys pressed'
+ },
reportDistanceTo: {
type: 'reporter',
category: 'sensing',
@@ -1376,6 +1398,8 @@ SpriteMorph.prototype.init = function (globals) {
this.version = Date.now(); // for observer optimization
this.isClone = false; // indicate a "temporary" Scratch-style clone
this.cloneOriginName = '';
+ this.volume = 100;
+ this.activeSounds = [];
// sprite nesting properties
this.parts = []; // not serialized, only anchor (name)
@@ -1479,8 +1503,11 @@ SpriteMorph.prototype.appearIn = function (ide) {
// SpriteMorph versioning
SpriteMorph.prototype.setName = function (string) {
- this.name = string || this.name;
- this.version = Date.now();
+ if (string != 'mouse-pointer' && string != 'pen trails'
+ && string != 'edge') { // used by system
+ this.name = string || this.name;
+ this.version = Date.now();
+ }
};
// SpriteMorph rendering
@@ -1852,6 +1879,11 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('doPlaySoundUntilDone'));
blocks.push(block('doStopAllSounds'));
blocks.push('-');
+ blocks.push(block('doSetVolume'));
+ blocks.push(block('doChangeVolume'));
+ blocks.push(watcherToggle('reportVolume'));
+ blocks.push(block('reportVolume'));
+ blocks.push('-');
blocks.push(block('doRest'));
blocks.push('-');
blocks.push(block('doPlayNote'));
@@ -1970,6 +2002,7 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportMouseDown'));
blocks.push('-');
blocks.push(block('reportKeyPressed'));
+ blocks.push(block('getKeysPressed'));
blocks.push('-');
blocks.push(block('reportDistanceTo'));
blocks.push('-');
@@ -2688,7 +2721,8 @@ SpriteMorph.prototype.reportCostumes = function () {
// SpriteMorph sound management
SpriteMorph.prototype.addSound = function (audio, name) {
- this.sounds.add(new Sound(audio, name));
+ var volume = this.volume;
+ this.sounds.add(new Sound(audio, name, volume));
};
SpriteMorph.prototype.playSound = function (name) {
@@ -2699,7 +2733,18 @@ SpriteMorph.prototype.playSound = function (name) {
),
active;
if (sound) {
+ sound.volume = this.volume;
active = sound.play();
+
+ if (stage.muted === true) {
+ active.volume = 0;
+ }
+
+ this.activeSounds.push(active);
+ this.activeSounds = this.activeSounds.filter(function (aud) {
+ return !aud.ended && !aud.terminated;
+ });
+
if (stage) {
stage.activeSounds.push(active);
stage.activeSounds = stage.activeSounds.filter(function (aud) {
@@ -2710,6 +2755,34 @@ SpriteMorph.prototype.playSound = function (name) {
}
};
+SpriteMorph.prototype.doSetVolume = function (val) {
+ var myself = this;
+ myself.volume = Math.min(Math.max(0, val), 100);
+
+ if (myself.parentThatIsA(StageMorph).muted === true) {
+ return;
+ }
+
+ myself.activeSounds.forEach(function (snd) {
+ snd.volume = myself.volume / 100; // 'audio' objects
+ });
+};
+
+SpriteMorph.prototype.doChangeVolume = function (val) {
+ this.doSetVolume(this.volume + val);
+};
+
+SpriteMorph.prototype.reportVolume = function () {
+ return this.volume;
+}
+
+SpriteMorph.prototype.unmuteAllSounds = function () {
+ var stage = this.parentThatIsA(StageMorph);
+ stage.muted = false;
+
+ this.doSetVolume(this.volume);
+};
+
SpriteMorph.prototype.reportSounds = function () {
return this.sounds;
};
@@ -3361,9 +3434,7 @@ Morph.prototype.setPosition = function (aPoint, justMe) {
// override the inherited default to make sure my parts follow
// unless it's justMe
var delta = aPoint.subtract(this.topLeft());
- if ((delta.x !== 0) || (delta.y !== 0)) {
- this.moveBy(delta, justMe);
- }
+ this.moveBy(delta, justMe);
};
SpriteMorph.prototype.forward = function (steps) {
@@ -3596,7 +3667,19 @@ SpriteMorph.prototype.allHatBlocksForKey = function (key) {
return this.scripts.children.filter(function (morph) {
if (morph.selector) {
if (morph.selector === 'receiveKey') {
- return morph.inputs()[0].evaluate()[0] === key;
+ var selectedOption = morph.inputs()[0].evaluate()[0];
+
+ if (selectedOption === 'any key') {
+ return true;
+ }
+ if (selectedOption === 'number key' &&
+ (key >= '0' && key <= '9')) {
+ return true;
+ }
+ if (selectedOption === key) {
+ return true;
+ }
+ return false;
}
}
return false;
@@ -3641,6 +3724,16 @@ SpriteMorph.prototype.getTempo = function () {
return 0;
};
+// SpriteMorph last key
+
+SpriteMorph.prototype.getKeysPressed = function () {
+ var stage = this.parentThatIsA(StageMorph);
+ if (stage) {
+ return stage.getKeysPressed();
+ }
+ return '';
+};
+
// SpriteMorph last message
SpriteMorph.prototype.getLastMessage = function () {
@@ -4395,6 +4488,8 @@ StageMorph.prototype.init = function (globals) {
this.version = Date.now(); // for observers
this.isFastTracked = false;
this.cloneCount = 0;
+ this.volume = 100;
+ this.muted = false;
this.timerStart = Date.now();
this.tempo = 60; // bpm
@@ -4683,6 +4778,16 @@ StageMorph.prototype.getTempo = function () {
return +this.tempo;
};
+// StageMorph keys
+
+StageMorph.prototype.getKeysPressed = function () {
+ var keys = [];
+ for (var key in this.keysPressed) {
+ keys.push(key);
+ }
+ return new List(keys);
+};
+
// StageMorph messages
StageMorph.prototype.getLastMessage = function () {
@@ -4736,7 +4841,7 @@ StageMorph.prototype.step = function () {
world.keyboardReceiver = this;
}
if (world.currentKey === null) {
- this.keyPressed = null;
+ this.keysPressed = {};
}
// manage threads
@@ -4924,7 +5029,7 @@ StageMorph.prototype.fireGreenFlagEvent = function () {
StageMorph.prototype.fireStopAllEvent = function () {
var ide = this.parentThatIsA(IDE_Morph);
- this.threads.resumeAll(this.stage);
+ //this.threads.resumeAll(this.stage); // leads to a strange Note bug
this.keysPressed = {};
this.threads.stopAll();
this.stopAllActiveSounds();
@@ -5080,6 +5185,11 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('doPlaySoundUntilDone'));
blocks.push(block('doStopAllSounds'));
blocks.push('-');
+ blocks.push(block('doSetVolume'));
+ blocks.push(block('doChangeVolume'));
+ blocks.push(watcherToggle('reportVolume'));
+ blocks.push(block('reportVolume'));
+ blocks.push('-');
blocks.push(block('doRest'));
blocks.push('-');
blocks.push(block('doPlayNote'));
@@ -5178,6 +5288,7 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportMouseDown'));
blocks.push('-');
blocks.push(block('reportKeyPressed'));
+ blocks.push(block('getKeysPressed'));
blocks.push('-');
blocks.push(block('doResetTimer'));
blocks.push(watcherToggle('getTimer'));
@@ -5631,6 +5742,15 @@ StageMorph.prototype.addSound
StageMorph.prototype.playSound
= SpriteMorph.prototype.playSound;
+StageMorph.prototype.doSetVolume
+ = SpriteMorph.prototype.doSetVolume;
+
+StageMorph.prototype.doChangeVolume
+ = SpriteMorph.prototype.doChangeVolume;
+
+StageMorph.prototype.reportVolume
+ = SpriteMorph.prototype.reportVolume;
+
StageMorph.prototype.stopAllActiveSounds = function () {
this.activeSounds.forEach(function (audio) {
audio.pause();
@@ -5645,11 +5765,29 @@ StageMorph.prototype.pauseAllActiveSounds = function () {
};
StageMorph.prototype.resumeAllActiveSounds = function () {
+ var newSounds = []; // remove Sounds that have been played so they do not resume
+
this.activeSounds.forEach(function (audio) {
- audio.play();
+ if (audio.ended === false) {
+ newSounds.push(audio);
+ audio.play();
+ }
});
+
+ this.activeSounds = newSounds;
};
+StageMorph.prototype.muteAllSounds = function () {
+ this.muted = true;
+
+ this.activeSounds.forEach(function (audio) {
+ audio.volume = 0;
+ });
+};
+
+StageMorph.prototype.unmuteAllSounds
+ = SpriteMorph.prototype.unmuteAllSounds;
+
StageMorph.prototype.reportSounds
= SpriteMorph.prototype.reportSounds;
@@ -6403,9 +6541,10 @@ CostumeEditorMorph.prototype.mouseMove
// Sound instance creation
-function Sound(audio, name) {
+function Sound(audio, name, volume) {
this.audio = audio; // mandatory
this.name = name || "Sound";
+ this.volume = volume || 100;
}
Sound.prototype.play = function () {
@@ -6413,6 +6552,7 @@ Sound.prototype.play = function () {
// externally (i.e. by the stage)
var aud = document.createElement('audio');
aud.src = this.audio.src;
+ aud.volume = Math.min(Math.max(0, this.volume), 100) / 100;
aud.play();
return aud;
};
@@ -6422,7 +6562,8 @@ Sound.prototype.copy = function () {
cpy;
snd.src = this.audio.src;
- cpy = new Sound(snd, this.name ? copy(this.name) : null);
+ snd.volume = this.volume;
+ cpy = new Sound(snd, this.name ? copy(this.name) : null, this.volume ? copy(this.volume) : null);
return cpy;
};
@@ -6436,8 +6577,9 @@ Sound.prototype.toDataURL = function () {
// Note instance creation
-function Note(pitch) {
+function Note(pitch, volume) {
this.pitch = pitch === 0 ? 0 : pitch || 69;
+ this.volume = volume;
this.setupContext();
this.oscillator = null;
}
@@ -6468,12 +6610,13 @@ Note.prototype.setupContext = function () {
}
Note.prototype.audioContext = new AudioContext();
Note.prototype.gainNode = Note.prototype.audioContext.createGain();
- Note.prototype.gainNode.gain.value = 0.25; // reduce volume by 1/4
};
// Note playing
Note.prototype.play = function () {
+ this.gainNode.gain.value = 0.25 * this.volume / 100; // reduce volume by 1/4
+
this.oscillator = this.audioContext.createOscillator();
if (!this.oscillator.start) {
this.oscillator.start = this.oscillator.noteOn;
@@ -6489,6 +6632,12 @@ Note.prototype.play = function () {
this.oscillator.start(0);
};
+Note.prototype.setVolume = function (volume) {
+ this.stop();
+ this.volume = volume;
+ this.play();
+}
+
Note.prototype.stop = function () {
if (this.oscillator) {
this.oscillator.stop(0);
@@ -6917,7 +7066,7 @@ WatcherMorph.prototype.object = function () {
WatcherMorph.prototype.isGlobal = function (selector) {
return contains(
- ['getLastAnswer', 'getLastMessage', 'getTempo', 'getTimer',
+ ['getLastAnswer', 'getKeysPressed', 'getLastMessage', 'getTempo', 'getTimer',
'reportMouseX', 'reportMouseY', 'reportThreadCount'],
selector
);
diff --git a/octokit.js b/octokit.js
new file mode 160000
+Subproject 579cef9893626da93ab8afbd601e4a3cf0d6d27
diff --git a/paint.js b/paint.js
index 65ae1f6..7e39671 100644
--- a/paint.js
+++ b/paint.js
@@ -657,6 +657,13 @@ PaintCanvasMorph.prototype.drawcrosshair = function (context) {
ctx.strokeStyle = 'black';
ctx.clearRect(0, 0, this.mask.width, this.mask.height);
+ //draw rotation center coordinates near crosshairs
+ ctx.globalAlpha = 1;
+ ctx.fillStyle = "blue";
+ ctx.font = "bold 10px Arial";
+ var coordinates = -Math.floor((this.mask.width/2 - rp.x)) + ', ' + Math.floor((this.mask.height/2 - rp.y));
+ ctx.fillText(coordinates, rp.x + 20, rp.y - 20);
+
// draw crosshairs:
ctx.globalAlpha = 0.5;
diff --git a/promise-1.0.0.js b/promise-1.0.0.js
new file mode 100644
index 0000000..5619cfa
--- /dev/null
+++ b/promise-1.0.0.js
@@ -0,0 +1,684 @@
+(function() {
+var define, requireModule, require, requirejs;
+
+(function() {
+ var registry = {}, seen = {};
+
+ define = function(name, deps, callback) {
+ registry[name] = { deps: deps, callback: callback };
+ };
+
+ requirejs = require = requireModule = function(name) {
+ requirejs._eak_seen = registry;
+
+ if (seen[name]) { return seen[name]; }
+ seen[name] = {};
+
+ if (!registry[name]) {
+ throw new Error("Could not find module " + name);
+ }
+
+ var mod = registry[name],
+ deps = mod.deps,
+ callback = mod.callback,
+ reified = [],
+ exports;
+
+ for (var i=0, l=deps.length; i<l; i++) {
+ if (deps[i] === 'exports') {
+ reified.push(exports = {});
+ } else {
+ reified.push(requireModule(resolve(deps[i])));
+ }
+ }
+
+ var value = callback.apply(this, reified);
+ return seen[name] = exports || value;
+
+ function resolve(child) {
+ if (child.charAt(0) !== '.') { return child; }
+ var parts = child.split("/");
+ var parentBase = name.split("/").slice(0, -1);
+
+ for (var i=0, l=parts.length; i<l; i++) {
+ var part = parts[i];
+
+ if (part === '..') { parentBase.pop(); }
+ else if (part === '.') { continue; }
+ else { parentBase.push(part); }
+ }
+
+ return parentBase.join("/");
+ }
+ };
+})();
+
+define("promise/all",
+ ["./utils","exports"],
+ function(__dependency1__, __exports__) {
+ "use strict";
+ /* global toString */
+
+ var isArray = __dependency1__.isArray;
+ var isFunction = __dependency1__.isFunction;
+
+ /**
+ Returns a promise that is fulfilled when all the given promises have been
+ fulfilled, or rejected if any of them become rejected. The return promise
+ is fulfilled with an array that gives all the values in the order they were
+ passed in the `promises` array argument.
+
+ Example:
+
+ ```javascript
+ var promise1 = RSVP.resolve(1);
+ var promise2 = RSVP.resolve(2);
+ var promise3 = RSVP.resolve(3);
+ var promises = [ promise1, promise2, promise3 ];
+
+ RSVP.all(promises).then(function(array){
+ // The array here would be [ 1, 2, 3 ];
+ });
+ ```
+
+ If any of the `promises` given to `RSVP.all` are rejected, the first promise
+ that is rejected will be given as an argument to the returned promises's
+ rejection handler. For example:
+
+ Example:
+
+ ```javascript
+ var promise1 = RSVP.resolve(1);
+ var promise2 = RSVP.reject(new Error("2"));
+ var promise3 = RSVP.reject(new Error("3"));
+ var promises = [ promise1, promise2, promise3 ];
+
+ RSVP.all(promises).then(function(array){
+ // Code here never runs because there are rejected promises!
+ }, function(error) {
+ // error.message === "2"
+ });
+ ```
+
+ @method all
+ @for RSVP
+ @param {Array} promises
+ @param {String} label
+ @return {Promise} promise that is fulfilled when all `promises` have been
+ fulfilled, or rejected if any of them become rejected.
+ */
+ function all(promises) {
+ /*jshint validthis:true */
+ var Promise = this;
+
+ if (!isArray(promises)) {
+ throw new TypeError('You must pass an array to all.');
+ }
+
+ return new Promise(function(resolve, reject) {
+ var results = [], remaining = promises.length,
+ promise;
+
+ if (remaining === 0) {
+ resolve([]);
+ }
+
+ function resolver(index) {
+ return function(value) {
+ resolveAll(index, value);
+ };
+ }
+
+ function resolveAll(index, value) {
+ results[index] = value;
+ if (--remaining === 0) {
+ resolve(results);
+ }
+ }
+
+ for (var i = 0; i < promises.length; i++) {
+ promise = promises[i];
+
+ if (promise && isFunction(promise.then)) {
+ promise.then(resolver(i), reject);
+ } else {
+ resolveAll(i, promise);
+ }
+ }
+ });
+ }
+
+ __exports__.all = all;
+ });
+define("promise/asap",
+ ["exports"],
+ function(__exports__) {
+ "use strict";
+ var browserGlobal = (typeof window !== 'undefined') ? window : {};
+ var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
+ var local = (typeof global !== 'undefined') ? global : (this === undefined? window:this);
+
+ // node
+ function useNextTick() {
+ return function() {
+ process.nextTick(flush);
+ };
+ }
+
+ function useMutationObserver() {
+ var iterations = 0;
+ var observer = new BrowserMutationObserver(flush);
+ var node = document.createTextNode('');
+ observer.observe(node, { characterData: true });
+
+ return function() {
+ node.data = (iterations = ++iterations % 2);
+ };
+ }
+
+ function useSetTimeout() {
+ return function() {
+ local.setTimeout(flush, 1);
+ };
+ }
+
+ var queue = [];
+ function flush() {
+ for (var i = 0; i < queue.length; i++) {
+ var tuple = queue[i];
+ var callback = tuple[0], arg = tuple[1];
+ callback(arg);
+ }
+ queue = [];
+ }
+
+ var scheduleFlush;
+
+ // Decide what async method to use to triggering processing of queued callbacks:
+ if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') {
+ scheduleFlush = useNextTick();
+ } else if (BrowserMutationObserver) {
+ scheduleFlush = useMutationObserver();
+ } else {
+ scheduleFlush = useSetTimeout();
+ }
+
+ function asap(callback, arg) {
+ var length = queue.push([callback, arg]);
+ if (length === 1) {
+ // If length is 1, that means that we need to schedule an async flush.
+ // If additional callbacks are queued before the queue is flushed, they
+ // will be processed by this flush that we are scheduling.
+ scheduleFlush();
+ }
+ }
+
+ __exports__.asap = asap;
+ });
+define("promise/config",
+ ["exports"],
+ function(__exports__) {
+ "use strict";
+ var config = {
+ instrument: false
+ };
+
+ function configure(name, value) {
+ if (arguments.length === 2) {
+ config[name] = value;
+ } else {
+ return config[name];
+ }
+ }
+
+ __exports__.config = config;
+ __exports__.configure = configure;
+ });
+define("promise/polyfill",
+ ["./promise","./utils","exports"],
+ function(__dependency1__, __dependency2__, __exports__) {
+ "use strict";
+ /*global self*/
+ var RSVPPromise = __dependency1__.Promise;
+ var isFunction = __dependency2__.isFunction;
+
+ function polyfill() {
+ var local;
+
+ if (typeof global !== 'undefined') {
+ local = global;
+ } else if (typeof window !== 'undefined' && window.document) {
+ local = window;
+ } else {
+ local = self;
+ }
+
+ var es6PromiseSupport =
+ "Promise" in local &&
+ // Some of these methods are missing from
+ // Firefox/Chrome experimental implementations
+ "resolve" in local.Promise &&
+ "reject" in local.Promise &&
+ "all" in local.Promise &&
+ "race" in local.Promise &&
+ // Older version of the spec had a resolver object
+ // as the arg rather than a function
+ (function() {
+ var resolve;
+ new local.Promise(function(r) { resolve = r; });
+ return isFunction(resolve);
+ }());
+
+ if (!es6PromiseSupport) {
+ local.Promise = RSVPPromise;
+ }
+ }
+
+ __exports__.polyfill = polyfill;
+ });
+define("promise/promise",
+ ["./config","./utils","./all","./race","./resolve","./reject","./asap","exports"],
+ function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __exports__) {
+ "use strict";
+ var config = __dependency1__.config;
+ var configure = __dependency1__.configure;
+ var objectOrFunction = __dependency2__.objectOrFunction;
+ var isFunction = __dependency2__.isFunction;
+ var now = __dependency2__.now;
+ var all = __dependency3__.all;
+ var race = __dependency4__.race;
+ var staticResolve = __dependency5__.resolve;
+ var staticReject = __dependency6__.reject;
+ var asap = __dependency7__.asap;
+
+ var counter = 0;
+
+ config.async = asap; // default async is asap;
+
+ function Promise(resolver) {
+ if (!isFunction(resolver)) {
+ throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
+ }
+
+ if (!(this instanceof Promise)) {
+ throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
+ }
+
+ this._subscribers = [];
+
+ invokeResolver(resolver, this);
+ }
+
+ function invokeResolver(resolver, promise) {
+ function resolvePromise(value) {
+ resolve(promise, value);
+ }
+
+ function rejectPromise(reason) {
+ reject(promise, reason);
+ }
+
+ try {
+ resolver(resolvePromise, rejectPromise);
+ } catch(e) {
+ rejectPromise(e);
+ }
+ }
+
+ function invokeCallback(settled, promise, callback, detail) {
+ var hasCallback = isFunction(callback),
+ value, error, succeeded, failed;
+
+ if (hasCallback) {
+ try {
+ value = callback(detail);
+ succeeded = true;
+ } catch(e) {
+ failed = true;
+ error = e;
+ }
+ } else {
+ value = detail;
+ succeeded = true;
+ }
+
+ if (handleThenable(promise, value)) {
+ return;
+ } else if (hasCallback && succeeded) {
+ resolve(promise, value);
+ } else if (failed) {
+ reject(promise, error);
+ } else if (settled === FULFILLED) {
+ resolve(promise, value);
+ } else if (settled === REJECTED) {
+ reject(promise, value);
+ }
+ }
+
+ var PENDING = void 0;
+ var SEALED = 0;
+ var FULFILLED = 1;
+ var REJECTED = 2;
+
+ function subscribe(parent, child, onFulfillment, onRejection) {
+ var subscribers = parent._subscribers;
+ var length = subscribers.length;
+
+ subscribers[length] = child;
+ subscribers[length + FULFILLED] = onFulfillment;
+ subscribers[length + REJECTED] = onRejection;
+ }
+
+ function publish(promise, settled) {
+ var child, callback, subscribers = promise._subscribers, detail = promise._detail;
+
+ for (var i = 0; i < subscribers.length; i += 3) {
+ child = subscribers[i];
+ callback = subscribers[i + settled];
+
+ invokeCallback(settled, child, callback, detail);
+ }
+
+ promise._subscribers = null;
+ }
+
+ Promise.prototype = {
+ constructor: Promise,
+
+ _state: undefined,
+ _detail: undefined,
+ _subscribers: undefined,
+
+ then: function(onFulfillment, onRejection) {
+ var promise = this;
+
+ var thenPromise = new this.constructor(function() {});
+
+ if (this._state) {
+ var callbacks = arguments;
+ config.async(function invokePromiseCallback() {
+ invokeCallback(promise._state, thenPromise, callbacks[promise._state - 1], promise._detail);
+ });
+ } else {
+ subscribe(this, thenPromise, onFulfillment, onRejection);
+ }
+
+ return thenPromise;
+ },
+
+ 'catch': function(onRejection) {
+ return this.then(null, onRejection);
+ }
+ };
+
+ Promise.all = all;
+ Promise.race = race;
+ Promise.resolve = staticResolve;
+ Promise.reject = staticReject;
+
+ function handleThenable(promise, value) {
+ var then = null,
+ resolved;
+
+ try {
+ if (promise === value) {
+ throw new TypeError("A promises callback cannot return that same promise.");
+ }
+
+ if (objectOrFunction(value)) {
+ then = value.then;
+
+ if (isFunction(then)) {
+ then.call(value, function(val) {
+ if (resolved) { return true; }
+ resolved = true;
+
+ if (value !== val) {
+ resolve(promise, val);
+ } else {
+ fulfill(promise, val);
+ }
+ }, function(val) {
+ if (resolved) { return true; }
+ resolved = true;
+
+ reject(promise, val);
+ });
+
+ return true;
+ }
+ }
+ } catch (error) {
+ if (resolved) { return true; }
+ reject(promise, error);
+ return true;
+ }
+
+ return false;
+ }
+
+ function resolve(promise, value) {
+ if (promise === value) {
+ fulfill(promise, value);
+ } else if (!handleThenable(promise, value)) {
+ fulfill(promise, value);
+ }
+ }
+
+ function fulfill(promise, value) {
+ if (promise._state !== PENDING) { return; }
+ promise._state = SEALED;
+ promise._detail = value;
+
+ config.async(publishFulfillment, promise);
+ }
+
+ function reject(promise, reason) {
+ if (promise._state !== PENDING) { return; }
+ promise._state = SEALED;
+ promise._detail = reason;
+
+ config.async(publishRejection, promise);
+ }
+
+ function publishFulfillment(promise) {
+ publish(promise, promise._state = FULFILLED);
+ }
+
+ function publishRejection(promise) {
+ publish(promise, promise._state = REJECTED);
+ }
+
+ __exports__.Promise = Promise;
+ });
+define("promise/race",
+ ["./utils","exports"],
+ function(__dependency1__, __exports__) {
+ "use strict";
+ /* global toString */
+ var isArray = __dependency1__.isArray;
+
+ /**
+ `RSVP.race` allows you to watch a series of promises and act as soon as the
+ first promise given to the `promises` argument fulfills or rejects.
+
+ Example:
+
+ ```javascript
+ var promise1 = new RSVP.Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve("promise 1");
+ }, 200);
+ });
+
+ var promise2 = new RSVP.Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve("promise 2");
+ }, 100);
+ });
+
+ RSVP.race([promise1, promise2]).then(function(result){
+ // result === "promise 2" because it was resolved before promise1
+ // was resolved.
+ });
+ ```
+
+ `RSVP.race` is deterministic in that only the state of the first completed
+ promise matters. For example, even if other promises given to the `promises`
+ array argument are resolved, but the first completed promise has become
+ rejected before the other promises became fulfilled, the returned promise
+ will become rejected:
+
+ ```javascript
+ var promise1 = new RSVP.Promise(function(resolve, reject){
+ setTimeout(function(){
+ resolve("promise 1");
+ }, 200);
+ });
+
+ var promise2 = new RSVP.Promise(function(resolve, reject){
+ setTimeout(function(){
+ reject(new Error("promise 2"));
+ }, 100);
+ });
+
+ RSVP.race([promise1, promise2]).then(function(result){
+ // Code here never runs because there are rejected promises!
+ }, function(reason){
+ // reason.message === "promise2" because promise 2 became rejected before
+ // promise 1 became fulfilled
+ });
+ ```
+
+ @method race
+ @for RSVP
+ @param {Array} promises array of promises to observe
+ @param {String} label optional string for describing the promise returned.
+ Useful for tooling.
+ @return {Promise} a promise that becomes fulfilled with the value the first
+ completed promises is resolved with if the first completed promise was
+ fulfilled, or rejected with the reason that the first completed promise
+ was rejected with.
+ */
+ function race(promises) {
+ /*jshint validthis:true */
+ var Promise = this;
+
+ if (!isArray(promises)) {
+ throw new TypeError('You must pass an array to race.');
+ }
+ return new Promise(function(resolve, reject) {
+ var results = [], promise;
+
+ for (var i = 0; i < promises.length; i++) {
+ promise = promises[i];
+
+ if (promise && typeof promise.then === 'function') {
+ promise.then(resolve, reject);
+ } else {
+ resolve(promise);
+ }
+ }
+ });
+ }
+
+ __exports__.race = race;
+ });
+define("promise/reject",
+ ["exports"],
+ function(__exports__) {
+ "use strict";
+ /**
+ `RSVP.reject` returns a promise that will become rejected with the passed
+ `reason`. `RSVP.reject` is essentially shorthand for the following:
+
+ ```javascript
+ var promise = new RSVP.Promise(function(resolve, reject){
+ reject(new Error('WHOOPS'));
+ });
+
+ promise.then(function(value){
+ // Code here doesn't run because the promise is rejected!
+ }, function(reason){
+ // reason.message === 'WHOOPS'
+ });
+ ```
+
+ Instead of writing the above, your code now simply becomes the following:
+
+ ```javascript
+ var promise = RSVP.reject(new Error('WHOOPS'));
+
+ promise.then(function(value){
+ // Code here doesn't run because the promise is rejected!
+ }, function(reason){
+ // reason.message === 'WHOOPS'
+ });
+ ```
+
+ @method reject
+ @for RSVP
+ @param {Any} reason value that the returned promise will be rejected with.
+ @param {String} label optional string for identifying the returned promise.
+ Useful for tooling.
+ @return {Promise} a promise that will become rejected with the given
+ `reason`.
+ */
+ function reject(reason) {
+ /*jshint validthis:true */
+ var Promise = this;
+
+ return new Promise(function (resolve, reject) {
+ reject(reason);
+ });
+ }
+
+ __exports__.reject = reject;
+ });
+define("promise/resolve",
+ ["exports"],
+ function(__exports__) {
+ "use strict";
+ function resolve(value) {
+ /*jshint validthis:true */
+ if (value && typeof value === 'object' && value.constructor === this) {
+ return value;
+ }
+
+ var Promise = this;
+
+ return new Promise(function(resolve) {
+ resolve(value);
+ });
+ }
+
+ __exports__.resolve = resolve;
+ });
+define("promise/utils",
+ ["exports"],
+ function(__exports__) {
+ "use strict";
+ function objectOrFunction(x) {
+ return isFunction(x) || (typeof x === "object" && x !== null);
+ }
+
+ function isFunction(x) {
+ return typeof x === "function";
+ }
+
+ function isArray(x) {
+ return Object.prototype.toString.call(x) === "[object Array]";
+ }
+
+ // Date.now is not available in browsers < IE9
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility
+ var now = Date.now || function() { return new Date().getTime(); };
+
+
+ __exports__.objectOrFunction = objectOrFunction;
+ __exports__.isFunction = isFunction;
+ __exports__.isArray = isArray;
+ __exports__.now = now;
+ });
+requireModule('promise/polyfill').polyfill();
+}()); \ No newline at end of file
diff --git a/snap.html b/snap.html
index e3c54dc..cbed2a3 100755
--- a/snap.html
+++ b/snap.html
@@ -17,13 +17,20 @@
<script type="text/javascript" src="store.js"></script>
<script type="text/javascript" src="locale.js"></script>
<script type="text/javascript" src="cloud.js"></script>
+ <script type="text/javascript" src="promise-1.0.0.js"></script>
+ <script type="text/javascript" src="octokit.js/octokit.js"></script>
+ <script type="text/javascript" src="github.js"></script>
<script type="text/javascript" src="sha512.js"></script>
-
+ <script type="text/javascript" src="Snapin8r/snapin8r.min.js"></script>
+ <script type="text/javascript" src="vkBeautify/vkbeautify.js"></script>
+ <script type="text/javascript" src="diff-merge/dist/diff.js"></script>
<script type="text/javascript">
var world;
window.onload = function () {
world = new WorldMorph(document.getElementById('world'));
world.worldCanvas.focus();
+ new IDE_Morph().openIn(world);
+ setInterval(loop, 10);
var ide = new IDE_Morph()
ide.openIn(world);
setInterval(loop, 1);
diff --git a/store.js b/store.js
index 056767f..7db27a6 100644
--- a/store.js
+++ b/store.js
@@ -97,7 +97,7 @@ XML_Serializer.prototype.serialize = function (object) {
this.flushMedia();
xml = this.store(object);
this.flush();
- return xml;
+ return vkbeautify.xml(xml);
};
XML_Serializer.prototype.store = function (object, mediaID) {
@@ -135,7 +135,7 @@ XML_Serializer.prototype.mediaXML = function () {
);
xml = xml + str;
});
- return xml + '</media>';
+ return vkbeautify.xml(xml + '</media>');
};
XML_Serializer.prototype.add = function (object) {
@@ -1032,7 +1032,7 @@ SnapSerializer.prototype.obsoleteBlock = function (isReporter) {
: new CommandBlockMorph();
block.selector = 'nop';
block.color = new Color(200, 0, 20);
- block.setSpec('Obsolete!');
+ block.setSpec(localize('Obsolete!'));
block.isDraggable = true;
return block;
};
diff --git a/threads.js b/threads.js
index 06454e3..6f5f35c 100644
--- a/threads.js
+++ b/threads.js
@@ -128,6 +128,15 @@ function snapEquals(a, b) {
return x === y;
}
+// stricter alternative to parseFloat
+// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseFloat/
+function filterFloat(value) {
+ if(/^(\-|\+)?([0-9]+(\.[0-9]+)?|Infinity)$/
+ .test(value))
+ return Number(value);
+ return NaN;
+}
+
// ThreadManager ///////////////////////////////////////////////////////
function ThreadManager() {
@@ -441,11 +450,20 @@ Process.prototype.pause = function () {
if (this.context && this.context.startTime) {
this.pauseOffset = Date.now() - this.context.startTime;
}
+ if (this.context.activeNote) {
+ this.context.activeNote.stop();
+ }
};
Process.prototype.resume = function () {
this.isPaused = false;
this.pauseOffset = null;
+ if (this.context.activeNote) {
+ if (this.context.activeNote.oscillator === null) {
+ // prevents Note from resuming twice
+ this.context.activeNote.play();
+ }
+ }
};
Process.prototype.pauseStep = function () {
@@ -735,6 +753,13 @@ Process.prototype.expectReport = function () {
// Process Exception Handling
+Process.prototype.checkIfList = function (maybeList) {
+ if (!(maybeList instanceof List)) {
+ maybeList = new List();
+ }
+ return maybeList;
+};
+
Process.prototype.handleError = function (error, element) {
var m = element;
this.stop();
@@ -1306,15 +1331,19 @@ Process.prototype.reportCONS = function (car, cdr) {
};
Process.prototype.reportCDR = function (list) {
+ list = this.checkIfList(list);
return list.cdr();
};
Process.prototype.doAddToList = function (element, list) {
+ list = this.checkIfList(list);
list.add(element);
};
Process.prototype.doDeleteFromList = function (index, list) {
var idx = index;
+ list = this.checkIfList(list);
+
if (this.inputOption(index) === 'all') {
return list.clear();
}
@@ -1329,6 +1358,8 @@ Process.prototype.doDeleteFromList = function (index, list) {
Process.prototype.doInsertInList = function (element, index, list) {
var idx = index;
+ list = this.checkIfList(list);
+
if (index === '') {
return null;
}
@@ -1343,6 +1374,8 @@ Process.prototype.doInsertInList = function (element, index, list) {
Process.prototype.doReplaceInList = function (index, list, element) {
var idx = index;
+ list = this.checkIfList(list);
+
if (index === '') {
return null;
}
@@ -1357,6 +1390,8 @@ Process.prototype.doReplaceInList = function (index, list, element) {
Process.prototype.reportListItem = function (index, list) {
var idx = index;
+ list = this.checkIfList(list);
+
if (index === '') {
return '';
}
@@ -1370,10 +1405,12 @@ Process.prototype.reportListItem = function (index, list) {
};
Process.prototype.reportListLength = function (list) {
+ list = this.checkIfList(list);
return list.length();
};
Process.prototype.reportListContainsItem = function (list, element) {
+ list = this.checkIfList(list);
return list.contains(element);
};
@@ -1429,7 +1466,7 @@ Process.prototype.doStopAll = function () {
if (this.homeContext.receiver) {
stage = this.homeContext.receiver.parentThatIsA(StageMorph);
if (stage) {
- stage.threads.resumeAll(stage);
+ //stage.threads.resumeAll(stage); // leads to a strange Note bug
stage.keysPressed = {};
stage.threads.stopAll();
stage.stopAllActiveSounds();
@@ -1632,6 +1669,8 @@ Process.prototype.reportMap = function (reporter, list) {
// documented in each of the variants' code (linked or arrayed) below
var next;
+ list = this.checkIfList(list);
+
if (list.isLinked) {
// this.context.inputs:
// [0] - reporter
@@ -1920,13 +1959,14 @@ Process.prototype.reportIsA = function (thing, typeString) {
Process.prototype.reportTypeOf = function (thing) {
// answer a string denoting the argument's type
var exp;
+
if (thing === null || (thing === undefined)) {
return 'nothing';
}
if (thing === true || (thing === false)) {
return 'Boolean';
}
- if (!isNaN(parseFloat(thing))) {
+ if (!isNaN(filterFloat(thing))) {
return 'number';
}
if (isString(thing)) {
@@ -2993,18 +3033,32 @@ Process.prototype.doPlayNote = function (pitch, beats) {
Process.prototype.doPlayNoteForSecs = function (pitch, secs) {
// interpolated
+ var receiver = this.homeContext.receiver;
+ var volume = receiver.volume;
+ var muted = receiver.parentThatIsA(StageMorph).muted;
+
+ if (muted === true) {
+ volume = 0;
+ }
+
if (!this.context.startTime) {
this.context.startTime = Date.now();
- this.context.activeNote = new Note(pitch);
+ this.context.activeNote = new Note(pitch, volume);
this.context.activeNote.play();
}
+
if ((Date.now() - this.context.startTime) >= (secs * 1000)) {
if (this.context.activeNote) {
this.context.activeNote.stop();
this.context.activeNote = null;
}
return null;
+ } else if (this.context.activeNote) {
+ if (this.context.activeNote.volume !== volume) {
+ this.context.activeNote.setVolume(volume);
+ }
}
+
this.pushContext('doYield');
this.pushContext();
};
diff --git a/tools.xml b/tools.xml
index e05d7bb..1f93675 100644
--- a/tools.xml
+++ b/tools.xml
@@ -1 +1 @@
-<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="map %&apos;function&apos; over %&apos;lists&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%repRing"></input><input type="%mult%l"></input></inputs><script><block s="doWarp"><script><block s="doDeclareVariables"><list><l>mapone</l><l>mapmany</l></list></block><block s="doSetVar"><l>mapone</l><block s="reifyScript"><script><block s="doIf"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doReport"><block s="reportCONS"><block s="evaluate"><block var="function"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><block s="evaluate"><block var="mapone"/><list><block s="reportCDR"><block var="data"/></block></list></block></block></block></script><list><l>data</l></list></block></block><block s="doSetVar"><l>mapmany</l><block s="reifyScript"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportListItem"><l>1</l><block var="data lists"/></block></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doReport"><block s="reportCONS"><block s="evaluate"><block var="function"/><custom-block s="map %repRing over %mult%l"><block s="reifyReporter"><autolambda><block s="reportListItem"><l>1</l><l/></block></autolambda><list></list></block><list><block var="data lists"/></list></custom-block></block><block s="evaluate"><block var="mapmany"/><list><custom-block s="map %repRing over %mult%l"><block s="reifyReporter"><autolambda><block s="reportCDR"><l/></block></autolambda><list></list></block><list><block var="data lists"/></list></custom-block></list></block></block></block></script><list><l>data lists</l></list></block></block><block s="doIfElse"><custom-block s="empty? %l"><block s="reportCDR"><block var="lists"/></block></custom-block><script><block s="doReport"><block s="evaluate"><block var="mapone"/><list><block s="reportListItem"><l>1</l><block var="lists"/></block></list></block></block></script><script><block s="doReport"><block s="evaluate"><block var="mapmany"/><list><block var="lists"/></list></block></block></script></block></script></block></script></block-definition><block-definition s="empty? %&apos;data&apos;" type="predicate" category="lists"><header></header><code></code><inputs><input type="%l"></input></inputs><script><block s="doReport"><block s="reportEquals"><block var="data"/><block s="reportNewList"><list></list></block></block></block></script></block-definition><block-definition s="keep items such that %&apos;pred&apos; from %&apos;data&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%predRing"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doIfElse"><block s="evaluate"><block var="pred"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><script><block s="doReport"><block s="reportCONS"><block s="reportListItem"><l>1</l><block var="data"/></block><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></block></script><script><block s="doReport"><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></script></block></script></block></script></block-definition><block-definition s="combine with %&apos;function&apos; items of %&apos;data&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%repRing"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportCDR"><block var="data"/></block></custom-block><script><block s="doReport"><block s="reportListItem"><l>1</l><block var="data"/></block></block></script></block><block s="doReport"><block s="evaluate"><block var="function"/><list><block s="reportListItem"><l>1</l><block var="data"/></block><custom-block s="combine with %repRing items of %l"><block var="function"/><block s="reportCDR"><block var="data"/></block></custom-block></list></block></block></script></block></script></block-definition><block-definition s="if %&apos;test&apos; then %&apos;true&apos; else %&apos;false&apos;" type="reporter" category="control"><header></header><code></code><inputs><input type="%b"></input><input type="%anyUE"></input><input type="%anyUE"></input></inputs><script><block s="doIfElse"><block var="test"/><script><block s="doReport"><block s="evaluate"><block var="true"/><list></list></block></block></script><script><block s="doReport"><block s="evaluate"><block var="false"/><list></list></block></block></script></block></script></block-definition><block-definition s="for %&apos;i&apos; = %&apos;start&apos; to %&apos;end&apos; %&apos;action&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%n">1</input><input type="%n">10</input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>step</l><l>tester</l></list></block><block s="doIfElse"><block s="reportGreaterThan"><block var="start"/><block var="end"/></block><script><block s="doSetVar"><l>step</l><l>-1</l></block><block s="doSetVar"><l>tester</l><block s="reifyReporter"><autolambda><block s="reportLessThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script><script><block s="doSetVar"><l>step</l><l>1</l></block><block s="doSetVar"><l>tester</l><block s="reifyReporter"><autolambda><block s="reportGreaterThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script></block><block s="doSetVar"><l>i</l><block var="start"/></block><block s="doUntil"><block s="evaluate"><block var="tester"/><list></list></block><script><block s="doRun"><block var="action"/><list></list></block><block s="doChangeVar"><l>i</l><block var="step"/></block></script></block></script></block-definition><block-definition s="join words %&apos;words&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%mult%txt"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportCDR"><block var="words"/></block></custom-block><script><block s="doReport"><block s="reportListItem"><l>1</l><block var="words"/></block></block></script></block><block s="doReport"><block s="reportJoinWords"><list><block s="reportListItem"><l>1</l><block var="words"/></block><block s="reportJoinWords"><list><l> </l><block s="evaluate"><block s="reifyReporter"><autolambda><custom-block s="join words %mult%txt"><block s="reportCDR"><block var="words"/></block></custom-block></autolambda><list></list></block><list></list></block></list></block></list></block></block></script></block></script></block-definition><block-definition s="list $arrowRight sentence %&apos;data&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doReport"><custom-block s="combine with %repRing items of %l"><block s="reifyReporter"><autolambda><custom-block s="join words %mult%txt"><list><l></l><l></l></list></custom-block></autolambda><list></list></block><block var="data"/></custom-block></block></script></block></script></block-definition><block-definition s="sentence $arrowRight list %&apos;text&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doWarp"><script><block s="doReport"><block s="reportTextSplit"><block var="text"/><l><option>whitespace</option></l></block></block></script></block></script></block-definition><block-definition s="catch %&apos;tag&apos; %&apos;action&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doRun"><block var="action"/><list></list></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;cont&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s">catchtag</input></inputs><script><block s="doRun"><block var="cont"/><list></list></block></script></block-definition><block-definition s="catch %&apos;tag&apos; %&apos;value&apos;" type="reporter" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doReport"><block s="evaluate"><block var="value"/><list></list></block></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;tag&apos; %&apos;value&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s">catchtag</input><input type="%s"></input></inputs><script><block s="doRun"><block var="tag"/><list><block var="value"/></list></block></script></block-definition><block-definition s="for each %&apos;item&apos; of %&apos;data&apos; %&apos;action&apos;" type="command" category="lists"><header></header><code></code><inputs><input type="%upvar"></input><input type="%l"></input><input type="%cs"></input></inputs><script><block s="doUntil"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doSetVar"><l>item</l><block s="reportListItem"><l>1</l><block var="data"/></block></block><block s="doRun"><block var="action"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><block s="doSetVar"><l>data</l><block s="reportCDR"><block var="data"/></block></block></script></block></script></block-definition><block-definition s="if %&apos;test&apos; do %&apos;action&apos; and pause all $pause-1-255-220-0" type="command" category="control"><header></header><code></code><inputs><input type="%boolUE"></input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>breakpoint</l></list></block><block s="doIf"><block s="evaluate"><block var="test"/><list></list></block><script><block s="doSetVar"><l>breakpoint</l><block var="test"/></block><block s="doShowVar"><l>breakpoint</l></block><block s="doRun"><block var="action"/><list></list></block><block s="doPauseAll"></block><block s="doHideVar"><l></l></block></script></block></script></block-definition><block-definition s="word $arrowRight list %&apos;word&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doWarp"><script><block s="doReport"><block s="reportTextSplit"><block var="word"/><l><option>letter</option></l></block></block></script></block></script></block-definition><block-definition s="ignore %&apos;x&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s"></input></inputs></block-definition></blocks> \ No newline at end of file
+<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="map %&apos;function&apos; over %&apos;lists&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%repRing"></input><input type="%mult%l"></input></inputs><script><block s="doWarp"><script><block s="doDeclareVariables"><list><l>mapone</l><l>mapmany</l></list></block><block s="doSetVar"><l>mapone</l><block s="reifyScript"><script><block s="doIf"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doReport"><block s="reportCONS"><block s="evaluate"><block var="function"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><block s="evaluate"><block var="mapone"/><list><block s="reportCDR"><block var="data"/></block></list></block></block></block></script><list><l>data</l></list></block></block><block s="doSetVar"><l>mapmany</l><block s="reifyScript"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportListItem"><l>1</l><block var="data lists"/></block></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doReport"><block s="reportCONS"><block s="evaluate"><block var="function"/><custom-block s="map %repRing over %mult%l"><block s="reifyReporter"><autolambda><block s="reportListItem"><l>1</l><l/></block></autolambda><list></list></block><list><block var="data lists"/></list></custom-block></block><block s="evaluate"><block var="mapmany"/><list><custom-block s="map %repRing over %mult%l"><block s="reifyReporter"><autolambda><block s="reportCDR"><l/></block></autolambda><list></list></block><list><block var="data lists"/></list></custom-block></list></block></block></block></script><list><l>data lists</l></list></block></block><block s="doIfElse"><custom-block s="empty? %l"><block s="reportCDR"><block var="lists"/></block></custom-block><script><block s="doReport"><block s="evaluate"><block var="mapone"/><list><block s="reportListItem"><l>1</l><block var="lists"/></block></list></block></block></script><script><block s="doReport"><block s="evaluate"><block var="mapmany"/><list><block var="lists"/></list></block></block></script></block></script></block></script></block-definition><block-definition s="empty? %&apos;data&apos;" type="predicate" category="lists"><header></header><code></code><inputs><input type="%l"></input></inputs><script><block s="doReport"><block s="reportEquals"><block var="data"/><block s="reportNewList"><list></list></block></block></block></script></block-definition><block-definition s="keep items such that %&apos;pred&apos; from %&apos;data&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%predRing"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doReport"><block s="reportNewList"><list></list></block></block></script></block><block s="doIfElse"><block s="evaluate"><block var="pred"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><script><block s="doReport"><block s="reportCONS"><block s="reportListItem"><l>1</l><block var="data"/></block><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></block></script><script><block s="doReport"><custom-block s="keep items such that %predRing from %l"><block var="pred"/><block s="reportCDR"><block var="data"/></block></custom-block></block></script></block></script></block></script></block-definition><block-definition s="combine with %&apos;function&apos; items of %&apos;data&apos;" type="reporter" category="lists"><header></header><code></code><inputs><input type="%repRing"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportCDR"><block var="data"/></block></custom-block><script><block s="doReport"><block s="reportListItem"><l>1</l><block var="data"/></block></block></script></block><block s="doReport"><block s="evaluate"><block var="function"/><list><block s="reportListItem"><l>1</l><block var="data"/></block><custom-block s="combine with %repRing items of %l"><block var="function"/><block s="reportCDR"><block var="data"/></block></custom-block></list></block></block></script></block></script></block-definition><block-definition s="if %&apos;test&apos; then %&apos;true&apos; else %&apos;false&apos;" type="reporter" category="control"><header></header><code></code><inputs><input type="%b"></input><input type="%anyUE"></input><input type="%anyUE"></input></inputs><script><block s="doIfElse"><block var="test"/><script><block s="doReport"><block s="evaluate"><block var="true"/><list></list></block></block></script><script><block s="doReport"><block s="evaluate"><block var="false"/><list></list></block></block></script></block></script></block-definition><block-definition s="for %&apos;i&apos; = %&apos;start&apos; to %&apos;end&apos; %&apos;action&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%n">1</input><input type="%n">10</input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>step</l><l>tester</l></list></block><block s="doIfElse"><block s="reportGreaterThan"><block var="start"/><block var="end"/></block><script><block s="doSetVar"><l>step</l><l>-1</l></block><block s="doSetVar"><l>tester</l><block s="reifyReporter"><autolambda><block s="reportLessThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script><script><block s="doSetVar"><l>step</l><l>1</l></block><block s="doSetVar"><l>tester</l><block s="reifyReporter"><autolambda><block s="reportGreaterThan"><block var="i"/><block var="end"/></block></autolambda><list></list></block></block></script></block><block s="doSetVar"><l>i</l><block var="start"/></block><block s="doUntil"><block s="evaluate"><block var="tester"/><list></list></block><script><block s="doRun"><block var="action"/><list></list></block><block s="doChangeVar"><l>i</l><block var="step"/></block></script></block></script></block-definition><block-definition s="join words %&apos;words&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%mult%txt"></input></inputs><script><block s="doWarp"><script><block s="doIf"><custom-block s="empty? %l"><block s="reportCDR"><block var="words"/></block></custom-block><script><block s="doReport"><block s="reportListItem"><l>1</l><block var="words"/></block></block></script></block><block s="doReport"><block s="reportJoinWords"><list><block s="reportListItem"><l>1</l><block var="words"/></block><block s="reportJoinWords"><list><l> </l><block s="evaluate"><block s="reifyReporter"><autolambda><custom-block s="join words %mult%txt"><block s="reportCDR"><block var="words"/></block></custom-block></autolambda><list></list></block><list></list></block></list></block></list></block></block></script></block></script></block-definition><block-definition s="list $arrowRight sentence %&apos;data&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doReport"><custom-block s="combine with %repRing items of %l"><block s="reifyReporter"><autolambda><custom-block s="join words %mult%txt"><list><l></l><l></l></list></custom-block></autolambda><list></list></block><block var="data"/></custom-block></block></script></block></script></block-definition><block-definition s="sentence $arrowRight list %&apos;text&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doWarp"><script><block s="doReport"><block s="reportTextSplit"><block var="text"/><l><option>whitespace</option></l></block></block></script></block></script></block-definition><block-definition s="catch %&apos;tag&apos; %&apos;action&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%cs"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doRun"><block var="action"/><list></list></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;cont&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s">catchtag</input></inputs><script><block s="doRun"><block var="cont"/><list></list></block></script></block-definition><block-definition s="catch %&apos;tag&apos; %&apos;value&apos;" type="reporter" category="control"><header></header><code></code><inputs><input type="%upvar"></input><input type="%anyUE"></input></inputs><script><block s="doCallCC"><block s="reifyScript"><script><block s="doSetVar"><l>tag</l><block var="cont"/></block><block s="doReport"><block s="evaluate"><block var="value"/><list></list></block></block></script><list><l>cont</l></list></block></block></script></block-definition><block-definition s="throw %&apos;tag&apos; %&apos;value&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s">catchtag</input><input type="%s"></input></inputs><script><block s="doRun"><block var="tag"/><list><block var="value"/></list></block></script></block-definition><block-definition s="for each %&apos;item&apos; of %&apos;data&apos; %&apos;action&apos;" type="command" category="lists"><header></header><code></code><inputs><input type="%upvar"></input><input type="%l"></input><input type="%cs"></input></inputs><script><block s="doUntil"><custom-block s="empty? %l"><block var="data"/></custom-block><script><block s="doSetVar"><l>item</l><block s="reportListItem"><l>1</l><block var="data"/></block></block><block s="doRun"><block var="action"/><list><block s="reportListItem"><l>1</l><block var="data"/></block></list></block><block s="doSetVar"><l>data</l><block s="reportCDR"><block var="data"/></block></block></script></block></script></block-definition><block-definition s="if %&apos;test&apos; do %&apos;action&apos; and pause all $pause-1-255-220-0" type="command" category="control"><header></header><code></code><inputs><input type="%boolUE"></input><input type="%cs"></input></inputs><script><block s="doDeclareVariables"><list><l>breakpoint</l></list></block><block s="doIf"><block s="evaluate"><block var="test"/><list></list></block><script><block s="doSetVar"><l>breakpoint</l><block var="test"/></block><block s="doShowVar"><l>breakpoint</l></block><block s="doRun"><block var="action"/><list></list></block><block s="doPauseAll"></block><block s="doHideVar"><l></l></block></script></block></script></block-definition><block-definition s="word $arrowRight list %&apos;word&apos;" type="reporter" category="operators"><header></header><code></code><inputs><input type="%txt"></input></inputs><script><block s="doWarp"><script><block s="doReport"><block s="reportTextSplit"><block var="word"/><l><option>letter</option></l></block></block></script></block></script></block-definition><block-definition s="ignore %&apos;x&apos;" type="command" category="control"><header></header><code></code><inputs><input type="%s"></input></inputs></block-definition><block-definition s="ask for %&apos;reporter&apos; from %&apos;sprite&apos;" type="reporter" category="sensing"><header></header><code></code><inputs><input type="%repRing"></input><input type="%txt"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportAttributeOf"><block var="reporter"/><block var="sprite"/></block><list></list></block></block></script></block-definition><block-definition s="tell %&apos;sprite&apos; to %&apos;commands&apos;" type="command" category="sensing"><header></header><code></code><inputs><input type="%txt"></input><input type="%cs"></input></inputs><script><block s="doRun"><block s="reportAttributeOf"><block var="commands"/><block var="sprite"/></block><list></list></block></script></block-definition></blocks> \ No newline at end of file
diff --git a/vkBeautify b/vkBeautify
new file mode 160000
+Subproject ecfc3b9e2b911ad8ebd49600c4089aca30619f2