kopia lustrzana https://github.com/backface/turtlestitch
Merge pull request #340 from cs10/extensions
Save stage/pentrails as costume (for animations)pull/3/merge
commit
c11e4c7c6d
12
blocks.js
12
blocks.js
|
@ -665,6 +665,18 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
|
|||
|
||||
// single-arg and specialized multi-arg slots:
|
||||
switch (spec) {
|
||||
case '%imgsource':
|
||||
part = new InputSlotMorph(
|
||||
null, // text
|
||||
false, // non-numeric
|
||||
{
|
||||
'pen trails': ['pen trails'],
|
||||
'stage image': ['stage image']
|
||||
},
|
||||
true
|
||||
);
|
||||
part.setContents(['pen trails']);
|
||||
break;
|
||||
case '%inputs':
|
||||
part = new MultiArgMorph('%s', 'with inputs');
|
||||
part.isStatic = false;
|
||||
|
|
70
objects.js
70
objects.js
|
@ -415,6 +415,12 @@ SpriteMorph.prototype.initBlocks = function () {
|
|||
spec: 'go back %n layers',
|
||||
defaults: [1]
|
||||
},
|
||||
doScreenshot: {
|
||||
type: 'command',
|
||||
category: 'looks',
|
||||
spec: 'save %imgsource as costume named %s',
|
||||
defaults: [['pen trails'], localize('screenshot')]
|
||||
},
|
||||
|
||||
// Looks - Debugging primitives for development mode
|
||||
reportCostumes: {
|
||||
|
@ -1319,6 +1325,8 @@ SpriteMorph.prototype.init = function (globals) {
|
|||
this.changed();
|
||||
this.drawNew();
|
||||
this.changed();
|
||||
|
||||
this.screenshotNames = {}; // Keeps track of stage image names
|
||||
};
|
||||
|
||||
// SpriteMorph duplicating (fullCopy)
|
||||
|
@ -1695,6 +1703,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push('-');
|
||||
blocks.push(block('comeToFront'));
|
||||
blocks.push(block('goBack'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doScreenshot'));
|
||||
|
||||
// for debugging: ///////////////
|
||||
|
||||
|
@ -4076,6 +4086,58 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) {
|
|||
morph.slideBackTo(hand.grabOrigin);
|
||||
};
|
||||
|
||||
var re = /\((\d+)\)$/; // RegExp to match costume names
|
||||
SpriteMorph.prototype.newCostumeName = function (name) {
|
||||
var foundSameName = false,
|
||||
foundIndex = false,
|
||||
lastIndex = 0,
|
||||
i = 1,
|
||||
p = null,
|
||||
costume = null;
|
||||
|
||||
for (i = 1; i <= this.costumes.length(); i++) {
|
||||
costume = this.costumes.at(i);
|
||||
if (costume !== null) {
|
||||
if (costume.name === name) {
|
||||
foundSameName = true;
|
||||
}
|
||||
if (foundSameName) {
|
||||
p = re.exec(costume.name);
|
||||
if (p) {
|
||||
lastIndex = Number(p[1]);
|
||||
foundIndex = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (foundSameName) {
|
||||
if (foundIndex) {
|
||||
lastIndex += 1;
|
||||
return name + '(' + lastIndex + ')'; // New index with a +1
|
||||
}
|
||||
return name + '(2)'; // No indexing has started so start it off with a (1)
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
SpriteMorph.prototype.doScreenshot = function (imgSource, data) {
|
||||
var canvas,
|
||||
stage = this.parentThatIsA(StageMorph),
|
||||
costume;
|
||||
data = this.newCostumeName(data);
|
||||
if (imgSource[0] === undefined) {
|
||||
return;
|
||||
}
|
||||
if (imgSource[0] === "pen trails") {
|
||||
canvas = stage.trailsCanvas;
|
||||
costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation
|
||||
} else if (imgSource[0] === "stage image") {
|
||||
canvas = stage.fullImageClassic();
|
||||
costume = new Costume(canvas, data);
|
||||
}
|
||||
this.addCostume(costume);
|
||||
};
|
||||
|
||||
// SpriteHighlightMorph /////////////////////////////////////////////////
|
||||
|
||||
// SpriteHighlightMorph inherits from Morph:
|
||||
|
@ -4753,6 +4815,8 @@ StageMorph.prototype.blockTemplates = function (category) {
|
|||
blocks.push(block('setEffect'));
|
||||
blocks.push(block('clearEffects'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('doScreenshot'));
|
||||
blocks.push('-');
|
||||
blocks.push(block('show'));
|
||||
blocks.push(block('hide'));
|
||||
|
||||
|
@ -5244,6 +5308,12 @@ StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable;
|
|||
|
||||
// StageMorph block rendering
|
||||
|
||||
StageMorph.prototype.doScreenshot
|
||||
= SpriteMorph.prototype.doScreenshot;
|
||||
|
||||
StageMorph.prototype.newCostumeName
|
||||
= SpriteMorph.prototype.newCostumeName;
|
||||
|
||||
StageMorph.prototype.blockForSelector
|
||||
= SpriteMorph.prototype.blockForSelector;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue