tweaked and optimized reportNewCostume() primitive

pull/89/head
jmoenig 2019-10-18 13:26:44 +02:00
rodzic 14822fb957
commit 2aab0294ba
1 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -4951,15 +4951,17 @@ Process.prototype.costumeNamed = function (name) {
};
Process.prototype.reportNewCostume = function (pixels, width, height, name) {
var rcvr = this.blockReceiver(),
stage = rcvr.parentThatIsA(StageMorph),
canvas, ctx, src, dta, i, k, px;
var rcvr, stage, canvas, ctx, src, dta, i, k, px;
this.assertType(pixels, 'list');
if (this.inputOption(width) === 'current') {
rcvr = this.blockReceiver();
stage = rcvr.parentThatIsA(StageMorph);
width = rcvr.costume ? rcvr.costume.width() : stage.dimensions.x;
}
if (this.inputOption(height) === 'current') {
rcvr = rcvr || this.blockReceiver();
stage = stage || rcvr.parentThatIsA(StageMorph);
height = rcvr.costume ? rcvr.costume.height() : stage.dimensions.y;
}
width = Math.abs(Math.floor(+width));
@ -4983,7 +4985,7 @@ Process.prototype.reportNewCostume = function (pixels, width, height, name) {
ctx.putImageData(dta, 0, 0);
return new Costume(
canvas,
name || rcvr.newCostumeName(localize('snap'))
name || (rcvr || this.blockReceiver()).newCostumeName(localize('snap'))
);
};