summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js123
1 files changed, 112 insertions, 11 deletions
diff --git a/objects.js b/objects.js
index af482b1..b506195 100644
--- a/objects.js
+++ b/objects.js
@@ -124,7 +124,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.objects = '2014-January-09';
+modules.objects = '2014-April-30';
var SpriteMorph;
var StageMorph;
@@ -186,6 +186,7 @@ SpriteMorph.prototype.sliderColor
SpriteMorph.prototype.isCachingPrimitives = true;
SpriteMorph.prototype.enableNesting = true;
+SpriteMorph.prototype.useFlatLineEnds = false;
SpriteMorph.prototype.highlightColor = new Color(250, 200, 130);
SpriteMorph.prototype.highlightBorder = 8;
@@ -388,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',
@@ -445,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',
@@ -803,6 +817,11 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sensing',
spec: 'set turbo mode to %b'
},
+ reportDate: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'current %dates'
+ },
// Operators
reifyScript: {
@@ -1614,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'));
}
@@ -1635,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'));
@@ -1739,6 +1774,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsFastTracking'));
blocks.push(block('doSetFastTracking'));
+ blocks.push('-');
+ blocks.push(block('reportDate'));
// for debugging: ///////////////
@@ -2254,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;
@@ -2284,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) {
@@ -2309,6 +2355,10 @@ SpriteMorph.prototype.playSound = function (name) {
}
};
+SpriteMorph.prototype.reportSounds = function () {
+ return this.sounds;
+};
+
// SpriteMorph user menu
SpriteMorph.prototype.userMenu = function () {
@@ -2717,8 +2767,13 @@ SpriteMorph.prototype.drawLine = function (start, dest) {
if (this.isDown) {
context.lineWidth = this.size;
context.strokeStyle = this.color.toString();
- context.lineCap = 'round';
- context.lineJoin = 'round';
+ if (this.useFlatLineEnds) {
+ context.lineCap = 'butt';
+ context.lineJoin = 'miter';
+ } else {
+ context.lineCap = 'round';
+ context.lineJoin = 'round';
+ }
context.beginPath();
context.moveTo(from.x, from.y);
context.lineTo(to.x, to.y);
@@ -4340,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'));
}
@@ -4361,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'));
@@ -4442,6 +4513,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportIsFastTracking'));
blocks.push(block('doSetFastTracking'));
+ blocks.push('-');
+ blocks.push(block('reportDate'));
// for debugging: ///////////////
@@ -4817,6 +4890,9 @@ StageMorph.prototype.doWearPreviousCostume
StageMorph.prototype.doSwitchToCostume
= SpriteMorph.prototype.doSwitchToCostume;
+StageMorph.prototype.reportCostumes
+ = SpriteMorph.prototype.reportCostumes;
+
// StageMorph graphic effects
StageMorph.prototype.setEffect
@@ -4858,6 +4934,9 @@ StageMorph.prototype.resumeAllActiveSounds = function () {
});
};
+StageMorph.prototype.reportSounds
+ = SpriteMorph.prototype.reportSounds;
+
// StageMorph non-variable watchers
StageMorph.prototype.toggleWatcher
@@ -4984,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);
@@ -5191,7 +5276,7 @@ Costume.prototype.shrinkWrap = function () {
};
Costume.prototype.boundingBox = function () {
- // answer the rectangle surrounding my contents' non-transparent pixels
+ // answer the rectangle surrounding my contents' non-transparent pixels
var row,
col,
pic = this.contents,
@@ -5299,7 +5384,7 @@ Costume.prototype.edit = function (aWorld, anIDE, isnew, oncancel, onsubmit) {
editor.openIn(
aWorld,
isnew ?
- newCanvas(new Point(480, 360)) :
+ newCanvas(StageMorph.prototype.dimensions) :
this.contents,
isnew ?
new Point(240, 180) :
@@ -5647,17 +5732,21 @@ Note.prototype.setupContext = function () {
if (this.audioContext) { return; }
var AudioContext = (function () {
// cross browser some day?
- return window.AudioContext ||
+ var ctx = window.AudioContext ||
window.mozAudioContext ||
window.msAudioContext ||
window.oAudioContext ||
window.webkitAudioContext;
+ if (!ctx.prototype.hasOwnProperty('createGain')) {
+ ctx.prototype.createGain = ctx.prototype.createGainNode;
+ }
+ return ctx;
}());
if (!AudioContext) {
throw new Error('Web Audio API is not supported\nin this browser');
}
Note.prototype.audioContext = new AudioContext();
- Note.prototype.gainNode = Note.prototype.audioContext.createGainNode();
+ Note.prototype.gainNode = Note.prototype.audioContext.createGain();
Note.prototype.gainNode.gain.value = 0.25; // reduce volume by 1/4
};
@@ -5665,17 +5754,23 @@ Note.prototype.setupContext = function () {
Note.prototype.play = function () {
this.oscillator = this.audioContext.createOscillator();
+ if (!this.oscillator.start) {
+ this.oscillator.start = this.oscillator.noteOn;
+ }
+ if (!this.oscillator.stop) {
+ this.oscillator.stop = this.oscillator.noteOff;
+ }
this.oscillator.type = 0;
this.oscillator.frequency.value =
Math.pow(2, (this.pitch - 69) / 12) * 440;
this.oscillator.connect(this.gainNode);
this.gainNode.connect(this.audioContext.destination);
- this.oscillator.noteOn(0); // deprecated, renamed to start()
+ this.oscillator.start(0);
};
Note.prototype.stop = function () {
if (this.oscillator) {
- this.oscillator.noteOff(0); // deprecated, renamed to stop()
+ this.oscillator.stop(0);
this.oscillator = null;
}
};
@@ -5816,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(
@@ -6386,7 +6487,7 @@ WatcherMorph.prototype.userMenu = function () {
'export...',
function () {
window.open(
- 'data:text/plain,' +
+ 'data:text/plain;charset=utf-8,' +
encodeURIComponent(this.currentValue.toString())
);
}
@@ -6541,7 +6642,7 @@ StagePrompterMorph.prototype.init = function (question) {
if (this.label) {this.add(this.label); }
this.add(this.inputField);
this.add(this.button);
- this.setWidth(480 - 20);
+ this.setWidth(StageMorph.prototype.dimensions.x - 20);
this.fixLayout();
};