Skip to content
This repository has been archived by the owner on Oct 2, 2021. It is now read-only.

Commit

Permalink
Create custom redraw() for foodglow
Browse files Browse the repository at this point in the history
Remove the foodglow as suggested by @pllsner in #236
Since this modifies the redraw()-function, the zoom is altered as well
instead of calling an extra function on each redraw.
  • Loading branch information
tjorim committed Jun 20, 2016
1 parent a89550f commit 420e562
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions bot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,12 @@ var canvasUtil = window.canvasUtil = (function() {
// Scaling ratio
if (window.gsc) {
window.gsc *= Math.pow(0.9, e.wheelDelta / -120 || e.detail / 2 || 0);
window.desired_gsc = window.gsc;
}
},

// Restores zoom to the default value.
resetZoom: function() {
window.gsc = 0.9;
window.desired_gsc = 0.9;
},

// Maintains Zoom
maintainZoom: function() {
if (window.desired_gsc !== undefined) {
window.gsc = window.desired_gsc;
}
},

// Sets background to the given image URL.
Expand Down Expand Up @@ -919,6 +910,16 @@ var userInterface = window.userInterface = (function() {
window.oef = function() {};
window.redraw = function() {};

// Modify the redraw()-function to remove the zoom altering code
// and replace b.globalCompositeOperation = "lighter"; to "hard-light".
var original_redraw_string = window.redraw.toString();
var new_redraw_string = original_redraw_string.replace(
'gsc!=f&&(gsc<f?(gsc+=2E-4,gsc>=f&&(gsc=f)):(gsc-=2E-4,gsc<=f&&(gsc=f)))', '');
new_redraw_string = new_redraw_string.replace(/b.globalCompositeOperation="lighter"/gi,
'b.globalCompositeOperation="lighter"');
var new_redraw = new Function(new_redraw_string.substring(
new_redraw_string.indexOf('{') + 1, new_redraw_string.lastIndexOf('}')));

return {
overlays: {},

Expand Down Expand Up @@ -1314,9 +1315,10 @@ var userInterface = window.userInterface = (function() {

oefTimer: function() {
var start = Date.now();
canvasUtil.maintainZoom();
// Original slither.io oef function + whatever is under it
original_oef();
original_redraw();
// Modified slither.io redraw function
new_redraw();

if (window.playing && bot.isBotEnabled && window.snake !== null) {
window.onmousemove = function() {};
Expand Down

0 comments on commit 420e562

Please sign in to comment.