rearranged some code

to fit inside lines of 80 characters max, to satisfy static code
analysis
pull/29/head
jmoenig 2017-01-04 16:52:59 +01:00
rodzic cae286d346
commit 5f43d7af76
2 zmienionych plików z 105 dodań i 30 usunięć

Wyświetl plik

@ -3137,14 +3137,24 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
receiver.variables.setVar(newName, oldValue);
if (oldWatcher && oldWatcher.isVisible) {
newWatcher = receiver.toggleVariableWatcher(newName, false);
newWatcher = receiver.toggleVariableWatcher(
newName,
false
);
newWatcher.setPosition(oldWatcher.position());
}
if (!justTheTemplate) {
receiver.refactorVariableInstances(oldName, newName, false);
receiver.refactorVariableInstances(
oldName,
newName,
false
);
receiver.customBlocks.forEach(function (eachBlock) {
eachBlock.body.expression.refactorVarInStack(oldName, newName);
eachBlock.body.expression.refactorVarInStack(
oldName,
newName
);
});
}
}
@ -3170,21 +3180,40 @@ BlockMorph.prototype.refactorThisVar = function (justTheTemplate) {
ide.globalVariables.setVar(newName, oldValue);
if (oldWatcher && oldWatcher.isVisible) {
newWatcher = receiver.toggleVariableWatcher(newName, true);
newWatcher = receiver.toggleVariableWatcher(
newName,
true
);
newWatcher.setPosition(oldWatcher.position());
}
if (!justTheTemplate) {
stage.refactorVariableInstances(oldName, newName, true);
stage.refactorVariableInstances(
oldName,
newName,
true
);
stage.globalBlocks.forEach(function (eachBlock) {
eachBlock.body.expression.refactorVarInStack(oldName, newName);
eachBlock.body.expression.refactorVarInStack(
oldName,
newName
);
});
stage.forAllChildren(function (child) {
if (child instanceof SpriteMorph) {
child.refactorVariableInstances(oldName, newName, true);
child.customBlocks.forEach(function (eachBlock) {
eachBlock.body.expression.refactorVarInStack(oldName, newName);
child.refactorVariableInstances(
oldName,
newName,
true
);
child.customBlocks.forEach(
function (eachBlock) {
eachBlock.body.expression
.refactorVarInStack(
oldName,
newName
);
});
}
});

Wyświetl plik

@ -3346,7 +3346,7 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
var ctx, imagedata;
function transform_fisheye (imagedata, value) {
function transform_fisheye(imagedata, value) {
var pixels, newImageData, newPixels, centerX, centerY,
w, h, x, y, dx, dy, r, angle, srcX, srcY, i, srcI;
@ -3366,8 +3366,12 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
r = Math.pow(Math.sqrt(dx * dx + dy * dy), value);
if (r <= 1) {
angle = Math.atan2(dy, dx);
srcX = Math.floor(centerX + (r * Math.cos(angle) * centerX));
srcY = Math.floor(centerY + (r * Math.sin(angle) * centerY));
srcX = Math.floor(
centerX + (r * Math.cos(angle) * centerX)
);
srcY = Math.floor(
centerY + (r * Math.sin(angle) * centerY)
);
} else {
srcX = x;
srcY = y;
@ -3383,7 +3387,7 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
return newImageData;
}
function transform_whirl (imagedata, value) {
function transform_whirl(imagedata, value) {
var pixels, newImageData, newPixels, w, h, centerX, centerY,
x, y, radius, scaleX, scaleY, whirlRadians, radiusSquared,
dx, dy, d, factor, angle, srcX, srcY, i, srcI, sina, cosa;
@ -3416,8 +3420,12 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
angle = whirlRadians * (factor * factor);
sina = Math.sin(angle);
cosa = Math.cos(angle);
srcX = Math.floor((cosa * dx - sina * dy) / scaleX + centerX);
srcY = Math.floor((sina * dx + cosa * dy) / scaleY + centerY);
srcX = Math.floor(
(cosa * dx - sina * dy) / scaleX + centerX
);
srcY = Math.floor(
(sina * dx + cosa * dy) / scaleY + centerY
);
} else {
srcX = x;
srcY = y;
@ -3433,7 +3441,7 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
return newImageData;
}
function transform_pixelate (imagedata, value) {
function transform_pixelate(imagedata, value) {
var pixels, newImageData, newPixels, w, h,
x, y, srcX, srcY, i, srcI;
@ -3459,14 +3467,17 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
return newImageData;
}
function transform_mosaic (imagedata, value) {
function transform_mosaic(imagedata, value) {
var pixels, i, l, newImageData, newPixels, srcI;
pixels = imagedata.data;
newImageData = ctx.createImageData(imagedata.width, imagedata.height);
newPixels = newImageData.data;
value = Math.round((Math.abs(value) + 10) / 10);
value = Math.max(0, Math.min(value, Math.min(imagedata.width, imagedata.height)));
value = Math.max(
0,
Math.min(value, Math.min(imagedata.width, imagedata.height))
);
for (i = 0, l = pixels.length; i < l; i += 4) {
srcI = i * value % l;
newPixels[i] = pixels[srcI];
@ -3477,7 +3488,7 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
return newImageData;
}
function transform_duplicate (imagedata, value) {
function transform_duplicate(imagedata, value) {
var pixels, i;
pixels = imagedata.data;
for (i = 0; i < pixels.length; i += 4) {
@ -3489,7 +3500,12 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
return imagedata;
}
function transform_HSV (imagedata, hueShift, saturationShift, brightnessShift) {
function transform_HSV(
imagedata,
hueShift,
saturationShift,
brightnessShift
) {
var pixels, index, l, r, g, b, max, min, span,
h, s, v, i, f, p, q, t, newR, newG, newB;
pixels = imagedata.data;
@ -3613,21 +3629,38 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
imagedata = ctx.getImageData(0, 0, canvas.width, canvas.height);
if (this.graphicsValues.fisheye) {
imagedata = transform_fisheye(imagedata, this.graphicsValues.fisheye);
imagedata = transform_fisheye(
imagedata,
this.graphicsValues.fisheye
);
}
if (this.graphicsValues.whirl) {
imagedata = transform_whirl(imagedata, this.graphicsValues.whirl);
imagedata = transform_whirl(
imagedata,
this.graphicsValues.whirl
);
}
if (this.graphicsValues.pixelate) {
imagedata = transform_pixelate(imagedata, this.graphicsValues.pixelate);
imagedata = transform_pixelate(
imagedata,
this.graphicsValues.pixelate
);
}
if (this.graphicsValues.mosaic) {
imagedata = transform_mosaic(imagedata, this.graphicsValues.mosaic);
imagedata = transform_mosaic(
imagedata,
this.graphicsValues.mosaic
);
}
if (this.graphicsValues.duplicate) {
imagedata = transform_duplicate(imagedata, this.graphicsValues.duplicate);
imagedata = transform_duplicate(
imagedata,
this.graphicsValues.duplicate
);
}
if (this.graphicsValues.color || this.graphicsValues.saturation || this.graphicsValues.brightness) {
if (this.graphicsValues.color ||
this.graphicsValues.saturation ||
this.graphicsValues.brightness) {
imagedata = transform_HSV(
imagedata,
this.graphicsValues.color,
@ -3636,13 +3669,22 @@ SpriteMorph.prototype.applyGraphicsEffects = function (canvas) {
);
}
if (this.graphicsValues.negative) {
imagedata = transform_negative(imagedata, this.graphicsValues.negative);
imagedata = transform_negative(
imagedata,
this.graphicsValues.negative
);
}
if (this.graphicsValues.comic) {
imagedata = transform_comic(imagedata, this.graphicsValues.comic);
imagedata = transform_comic(
imagedata,
this.graphicsValues.comic
);
}
if (this.graphicsValues.confetti) {
imagedata = transform_confetti(imagedata, this.graphicsValues.confetti);
imagedata = transform_confetti(
imagedata,
this.graphicsValues.confetti
);
}
ctx.putImageData(imagedata, 0, 0);
@ -4824,7 +4866,11 @@ SpriteMorph.prototype.hasSpriteVariable = function (varName) {
// Variable refactoring
SpriteMorph.prototype.refactorVariableInstances = function (oldName, newName, isGlobal) {
SpriteMorph.prototype.refactorVariableInstances = function (
oldName,
newName,
isGlobal
) {
if (isGlobal && this.hasSpriteVariable(oldName)) {
return;
}