Skip to content

Commit

Permalink
Fix bug with timer bar displacing wrinkler detection area (Issue #213)…
Browse files Browse the repository at this point in the history
… and use game detection instead of copying code plus a minor code formatting change
  • Loading branch information
Aktanusa committed Aug 17, 2018
1 parent 6895719 commit 2f862ac
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 44 deletions.
42 changes: 20 additions & 22 deletions CookieMonster.js
Expand Up @@ -2046,6 +2046,18 @@ CM.Disp.RefreshMenu = function() {
if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu();
}

CM.Disp.FixMouseY = function(target) {
if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height);
Game.mouseY -= timerBarHeight;
target();
Game.mouseY += timerBarHeight;
}
else {
target();
}
}

CM.Disp.UpdateTooltipLocation = function() {
if (Game.tooltip.origin == 'store') {
var warnCautOffset = 0;
Expand Down Expand Up @@ -2435,20 +2447,9 @@ CM.Disp.AddWrinklerAreaDetect = function() {
CM.Disp.CheckWrinklerTooltip = function() {
if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) {
var showingTooltip = false;
var mouseInWrinkler = function (x, y, rect) {
var dx = x + Math.sin(-rect.r) * (-(rect.h / 2 - rect.o)), dy = y + Math.cos(-rect.r) * (-(rect.h / 2 - rect.o));
var h1 = Math.sqrt(dx * dx + dy * dy);
var currA = Math.atan2(dy, dx);
var newA = currA - rect.r;
var x2 = Math.cos(newA) * h1;
var y2 = Math.sin(newA) * h1;
if (x2 > -0.5 * rect.w && x2 < 0.5 * rect.w && y2 > -0.5 * rect.h && y2 < 0.5 * rect.h) return true;
return false;
}
for (var i in Game.wrinklers) {
var me = Game.wrinklers[i];
var rect = {w: 100, h: 200, r: (-me.r) * Math.PI / 180, o: 10};
if (me.phase > 0 && Game.LeftBackground && Game.mouseX < Game.LeftBackground.canvas.width && mouseInWrinkler(Game.mouseX - me.x, Game.mouseY - me.y, rect)) {
if (me.phase > 0 && me.selected) {
showingTooltip = true;
if (CM.Disp.TooltipWrinklerCache[i] == 0) {
var placeholder = document.createElement('div');
Expand Down Expand Up @@ -2591,17 +2592,14 @@ CM.ReplaceNative = function() {
CM.Disp.UpdateTooltipLocation();
}

CM.Backup.UpdateWrinklers = Game.UpdateWrinklers;
Game.UpdateWrinklers = function() {
CM.Disp.FixMouseY(CM.Backup.UpdateWrinklers);
}

CM.Backup.UpdateSpecial = Game.UpdateSpecial;
Game.UpdateSpecial = function() {
if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height);
Game.mouseY -= timerBarHeight;
CM.Backup.UpdateSpecial();
Game.mouseY += timerBarHeight;
}
else {
CM.Backup.UpdateSpecial();
}
CM.Disp.FixMouseY(CM.Backup.UpdateSpecial);
}

// Probably better to load per minigame
Expand Down Expand Up @@ -2866,7 +2864,7 @@ CM.Sim.BuildingSell = function(basePrice, start, free, amount, emuAura) {
price = Game.modifyBuildingPrice(null, price);
price = Math.ceil(price);
var giveBack = 0.25;
if (Game.hasAura('Earth Shatterer') || emuAura) giveBack=0.5;
if (Game.hasAura('Earth Shatterer') || emuAura) giveBack = 0.5;
price = Math.floor(price * giveBack);
if (start > 0) {
moni += price;
Expand Down
25 changes: 13 additions & 12 deletions src/Disp.js
Expand Up @@ -1492,6 +1492,18 @@ CM.Disp.RefreshMenu = function() {
if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu();
}

CM.Disp.FixMouseY = function(target) {
if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height);
Game.mouseY -= timerBarHeight;
target();
Game.mouseY += timerBarHeight;
}
else {
target();
}
}

CM.Disp.UpdateTooltipLocation = function() {
if (Game.tooltip.origin == 'store') {
var warnCautOffset = 0;
Expand Down Expand Up @@ -1881,20 +1893,9 @@ CM.Disp.AddWrinklerAreaDetect = function() {
CM.Disp.CheckWrinklerTooltip = function() {
if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) {
var showingTooltip = false;
var mouseInWrinkler = function (x, y, rect) {
var dx = x + Math.sin(-rect.r) * (-(rect.h / 2 - rect.o)), dy = y + Math.cos(-rect.r) * (-(rect.h / 2 - rect.o));
var h1 = Math.sqrt(dx * dx + dy * dy);
var currA = Math.atan2(dy, dx);
var newA = currA - rect.r;
var x2 = Math.cos(newA) * h1;
var y2 = Math.sin(newA) * h1;
if (x2 > -0.5 * rect.w && x2 < 0.5 * rect.w && y2 > -0.5 * rect.h && y2 < 0.5 * rect.h) return true;
return false;
}
for (var i in Game.wrinklers) {
var me = Game.wrinklers[i];
var rect = {w: 100, h: 200, r: (-me.r) * Math.PI / 180, o: 10};
if (me.phase > 0 && Game.LeftBackground && Game.mouseX < Game.LeftBackground.canvas.width && mouseInWrinkler(Game.mouseX - me.x, Game.mouseY - me.y, rect)) {
if (me.phase > 0 && me.selected) {
showingTooltip = true;
if (CM.Disp.TooltipWrinklerCache[i] == 0) {
var placeholder = document.createElement('div');
Expand Down
15 changes: 6 additions & 9 deletions src/Main.js
Expand Up @@ -29,17 +29,14 @@ CM.ReplaceNative = function() {
CM.Disp.UpdateTooltipLocation();
}

CM.Backup.UpdateWrinklers = Game.UpdateWrinklers;
Game.UpdateWrinklers = function() {
CM.Disp.FixMouseY(CM.Backup.UpdateWrinklers);
}

CM.Backup.UpdateSpecial = Game.UpdateSpecial;
Game.UpdateSpecial = function() {
if (CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
var timerBarHeight = parseInt(CM.Disp.TimerBar.style.height);
Game.mouseY -= timerBarHeight;
CM.Backup.UpdateSpecial();
Game.mouseY += timerBarHeight;
}
else {
CM.Backup.UpdateSpecial();
}
CM.Disp.FixMouseY(CM.Backup.UpdateSpecial);
}

// Probably better to load per minigame
Expand Down
2 changes: 1 addition & 1 deletion src/Sim.js
Expand Up @@ -49,7 +49,7 @@ CM.Sim.BuildingSell = function(basePrice, start, free, amount, emuAura) {
price = Game.modifyBuildingPrice(null, price);
price = Math.ceil(price);
var giveBack = 0.25;
if (Game.hasAura('Earth Shatterer') || emuAura) giveBack=0.5;
if (Game.hasAura('Earth Shatterer') || emuAura) giveBack = 0.5;
price = Math.floor(price * giveBack);
if (start > 0) {
moni += price;
Expand Down

0 comments on commit 2f862ac

Please sign in to comment.