Removed evil evals
Filters now reset when the stop button is clicked.
This commit is contained in:
parent
64535641fc
commit
c40c1b4027
3 changed files with 18 additions and 23 deletions
js
|
@ -89,6 +89,11 @@ Runtime.prototype.stopAll = function() {
|
|||
if (typeof runtime.sprites[s].hideBubble == 'function')
|
||||
runtime.sprites[s].hideBubble();
|
||||
}
|
||||
// Reset graphic effects
|
||||
for (var s = 0; s < runtime.sprites.length; s++) {
|
||||
if (typeof runtime.sprites[s].hideBubble == 'function')
|
||||
runtime.sprites[s].resetFilters();
|
||||
}
|
||||
}
|
||||
|
||||
// Step method for execution - called every 33 milliseconds
|
||||
|
|
30
js/Sprite.js
30
js/Sprite.js
|
@ -89,14 +89,8 @@ var Sprite = function(data) {
|
|||
this.soundsLoaded = 0;
|
||||
this.instrument = 1;
|
||||
|
||||
// Filter effects
|
||||
this.colorFilterEffect = 0;
|
||||
this.fisheyeFilterEffect = 0;
|
||||
this.whirlFilterEffect = 0;
|
||||
this.pixelateFilterEffect = 0;
|
||||
this.mosaicFilterEffect = 0;
|
||||
this.brightnessFilterEffect = 0;
|
||||
this.ghostFilterEffect = 0;
|
||||
// Image effects
|
||||
this.filters = { color: 0, fisheye: 0, whirl: 0, pixelate: 0, mosaic: 0, brightness: 0, ghost: 0 };
|
||||
|
||||
// Incremented when images are loaded by the browser.
|
||||
this.costumesLoaded = 0;
|
||||
|
@ -306,16 +300,18 @@ Sprite.prototype.updateTransform = function() {
|
|||
$(this.mesh).css('-o-transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
|
||||
$(this.mesh).css('transform-origin', rotationCenterX + 'px ' + rotationCenterY + 'px');
|
||||
|
||||
$(this.mesh).css('opacity', (1 - (this.ghostFilterEffect) / 100));
|
||||
$(this.mesh).css('opacity', (1 - (this.filters['ghost']) / 100));
|
||||
//Chrome
|
||||
if (!!window.chrome) {
|
||||
$(this.mesh).css('-webkit-filter',
|
||||
'hue-rotate(' + ((this.colorFilterEffect % 200) * 1.8) + 'deg) \
|
||||
brightness(' + ((this.brightnessFilterEffect / 100) + 1) + ')');
|
||||
'hue-rotate(' + ((this.filters['color'] % 200) * 1.8) + 'deg) \
|
||||
brightness(' + ((this.filters['brightness'] / 100) + 1) + ')');
|
||||
}
|
||||
//Safari
|
||||
if (/Constructor/.test(window.HTMLElement)) {
|
||||
$(this.mesh).css('-webkit-filter',
|
||||
'hue-rotate(' + ((this.colorFilterEffect % 200) * 1.8) + 'deg) \
|
||||
brightness(' + (this.brightnessFilterEffect / 100) + ')');
|
||||
'hue-rotate(' + ((this.filters['color'] % 200) * 1.8) + 'deg) \
|
||||
brightness(' + (this.filters['brightness'] / 100) + ')');
|
||||
}
|
||||
|
||||
// Don't forget to update the talk bubble.
|
||||
|
@ -479,12 +475,6 @@ Sprite.prototype.soundNamed = function(name) {
|
|||
}
|
||||
|
||||
Sprite.prototype.resetFilters = function() {
|
||||
this.colorFilterEffect = 0;
|
||||
this.fisheyeFilterEffect = 0;
|
||||
this.whirlFilterEffect = 0;
|
||||
this.pixelateFilterEffect = 0;
|
||||
this.mosaicFilterEffect = 0;
|
||||
this.brightnessFilterEffect = 0;
|
||||
this.ghostFilterEffect = 0;
|
||||
this.filters = { color: 0, fisheye: 0, whirl: 0, pixelate: 0, mosaic: 0, brightness: 0, ghost: 0 };
|
||||
this.updateTransform();
|
||||
}
|
|
@ -155,15 +155,15 @@ LooksPrims.prototype.primGoBack = function(b) {
|
|||
LooksPrims.prototype.primChangeEffect = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var filter = interp.arg(b, 0);
|
||||
var currentValue = eval("s." + filter + "FilterEffect");
|
||||
eval("s." + filter + "FilterEffect = (currentValue + (interp.arg(b, 1)));");
|
||||
var currentValue = s.filters[filter];
|
||||
s.filters[filter] = currentValue + interp.arg(b, 1);
|
||||
s.updateTransform();
|
||||
}
|
||||
|
||||
LooksPrims.prototype.primSetEffect = function(b) {
|
||||
var s = interp.targetSprite();
|
||||
var filter = interp.arg(b, 0);
|
||||
eval("s." + filter + "FilterEffect = (interp.arg(b, 1));");
|
||||
s.filters[filter] = interp.arg(b, 1);
|
||||
s.updateTransform();
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue