summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorMichael Ball <cycomachead@gmail.com>2014-05-03 19:15:52 -0700
committerMichael Ball <cycomachead@gmail.com>2014-05-03 19:15:52 -0700
commit01b9417b87688b591fe3df2a55ec367dd72f027d (patch)
tree9bb4d236387b631e4f1ca3fe57152f148d4c9fa4 /objects.js
parent8badce6480d434653326684a953fccc6cf03c5d8 (diff)
parentf9989ad7cfa5e27b4784d8cd464fdc7cbe289942 (diff)
downloadsnap-01b9417b87688b591fe3df2a55ec367dd72f027d.tar.gz
snap-01b9417b87688b591fe3df2a55ec367dd72f027d.zip
Merge pull request #31 from jmoenig/master
Update CS10 Fork
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js107
1 files changed, 97 insertions, 10 deletions
diff --git a/objects.js b/objects.js
index 46a951f..d1e99ff 100644
--- a/objects.js
+++ b/objects.js
@@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-February-11';
+modules.objects = '2014-May-02';
var SpriteMorph;
var StageMorph;
@@ -389,6 +389,12 @@ SpriteMorph.prototype.initBlocks = function () {
},
// Looks - Debugging primitives for development mode
+ reportCostumes: {
+ type: 'reporter',
+ category: 'looks',
+ spec: 'wardrobe'
+ },
+
alert: {
type: 'command',
category: 'looks',
@@ -446,6 +452,13 @@ SpriteMorph.prototype.initBlocks = function () {
spec: 'tempo'
},
+ // Sound - Debugging primitives for development mode
+ reportSounds: {
+ type: 'reporter',
+ category: 'sound',
+ spec: 'jukebox'
+ },
+
// Pen
clear: {
type: 'command',
@@ -1620,6 +1633,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
txt.setColor(this.paletteTextColor);
blocks.push(txt);
blocks.push('-');
+ blocks.push(block('reportCostumes'));
+ blocks.push('-');
blocks.push(block('log'));
blocks.push(block('alert'));
}
@@ -1641,6 +1656,20 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(watcherToggle('getTempo'));
blocks.push(block('getTempo'));
+ // for debugging: ///////////////
+
+ if (this.world().isDevMode) {
+ blocks.push('-');
+ txt = new TextMorph(localize(
+ 'development mode \ndebugging primitives:'
+ ));
+ txt.fontSize = 9;
+ txt.setColor(this.paletteTextColor);
+ blocks.push(txt);
+ blocks.push('-');
+ blocks.push(block('reportSounds'));
+ }
+
} else if (cat === 'pen') {
blocks.push(block('clear'));
@@ -2262,6 +2291,11 @@ SpriteMorph.prototype.doWearPreviousCostume = function () {
};
SpriteMorph.prototype.doSwitchToCostume = function (id) {
+ if (id instanceof Costume) { // allow first-class costumes
+ this.wearCostume(id);
+ return;
+ }
+
var num,
arr = this.costumes.asArray(),
costume;
@@ -2292,6 +2326,10 @@ SpriteMorph.prototype.doSwitchToCostume = function (id) {
this.wearCostume(costume);
};
+SpriteMorph.prototype.reportCostumes = function () {
+ return this.costumes;
+};
+
// SpriteMorph sound management
SpriteMorph.prototype.addSound = function (audio, name) {
@@ -2317,6 +2355,10 @@ SpriteMorph.prototype.playSound = function (name) {
}
};
+SpriteMorph.prototype.reportSounds = function () {
+ return this.sounds;
+};
+
// SpriteMorph user menu
SpriteMorph.prototype.userMenu = function () {
@@ -4353,6 +4395,8 @@ StageMorph.prototype.blockTemplates = function (category) {
txt.setColor(this.paletteTextColor);
blocks.push(txt);
blocks.push('-');
+ blocks.push(block('reportCostumes'));
+ blocks.push('-');
blocks.push(block('log'));
blocks.push(block('alert'));
}
@@ -4374,6 +4418,20 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(watcherToggle('getTempo'));
blocks.push(block('getTempo'));
+ // for debugging: ///////////////
+
+ if (this.world().isDevMode) {
+ blocks.push('-');
+ txt = new TextMorph(localize(
+ 'development mode \ndebugging primitives:'
+ ));
+ txt.fontSize = 9;
+ txt.setColor(this.paletteTextColor);
+ blocks.push(txt);
+ blocks.push('-');
+ blocks.push(block('reportSounds'));
+ }
+
} else if (cat === 'pen') {
blocks.push(block('clear'));
@@ -4832,6 +4890,9 @@ StageMorph.prototype.doWearPreviousCostume
StageMorph.prototype.doSwitchToCostume
= SpriteMorph.prototype.doSwitchToCostume;
+StageMorph.prototype.reportCostumes
+ = SpriteMorph.prototype.reportCostumes;
+
// StageMorph graphic effects
StageMorph.prototype.setEffect
@@ -4873,6 +4934,9 @@ StageMorph.prototype.resumeAllActiveSounds = function () {
});
};
+StageMorph.prototype.reportSounds
+ = SpriteMorph.prototype.reportSounds;
+
// StageMorph non-variable watchers
StageMorph.prototype.toggleWatcher
@@ -4999,6 +5063,12 @@ SpriteBubbleMorph.prototype.dataAsMorph = function (data) {
contents.silentSetWidth(img.width);
contents.silentSetHeight(img.height);
contents.image = img;
+ } else if (data instanceof Costume) {
+ img = data.thumbnail(new Point(40, 40));
+ contents = new Morph();
+ contents.silentSetWidth(img.width);
+ contents.silentSetHeight(img.height);
+ contents.image = img;
} else if (data instanceof HTMLCanvasElement) {
contents = new Morph();
contents.silentSetWidth(data.width);
@@ -5841,6 +5911,12 @@ CellMorph.prototype.drawNew = function () {
this.contentsMorph.silentSetWidth(img.width);
this.contentsMorph.silentSetHeight(img.height);
this.contentsMorph.image = img;
+ } else if (this.contents instanceof Costume) {
+ img = this.contents.thumbnail(new Point(40, 40));
+ this.contentsMorph = new Morph();
+ this.contentsMorph.silentSetWidth(img.width);
+ this.contentsMorph.silentSetHeight(img.height);
+ this.contentsMorph.image = img;
} else if (this.contents instanceof List) {
if (this.isCircular()) {
this.contentsMorph = new TextMorph(
@@ -6374,7 +6450,17 @@ WatcherMorph.prototype.userMenu = function () {
inp.addEventListener(
"change",
function () {
- var file, i;
+ var file;
+
+ function txtOnlyMsg(ftype) {
+ ide.inform(
+ 'Unable to import',
+ 'Snap! can only import "text" files.\n' +
+ 'You selected a file of type "' +
+ ftype +
+ '".'
+ );
+ }
function readText(aFile) {
var frd = new FileReader();
@@ -6384,18 +6470,19 @@ WatcherMorph.prototype.userMenu = function () {
e.target.result
);
};
- frd.readAsText(aFile);
+
+ if (aFile.type.indexOf("text") === 0) {
+ frd.readAsText(aFile);
+ } else {
+ txtOnlyMsg(aFile.type);
+ }
}
document.body.removeChild(inp);
ide.filePicker = null;
if (inp.files.length > 0) {
- for (i = 0; i < inp.files.length; i += 1) {
- file = inp.files[i];
- if (file.type.indexOf("text") === 0) {
- readText(file);
- }
- }
+ file = inp.files[inp.files.length - 1];
+ readText(file);
}
},
false
@@ -6411,7 +6498,7 @@ WatcherMorph.prototype.userMenu = function () {
'export...',
function () {
window.open(
- 'data:text/plain,' +
+ 'data:text/plain;charset=utf-8,' +
encodeURIComponent(this.currentValue.toString())
);
}