From 29ba1c66cf1105ce577659e3abae27ea0c5bb3a9 Mon Sep 17 00:00:00 2001 From: Daniel van Noord Date: Sat, 23 Jan 2021 22:36:26 +0100 Subject: [PATCH] Moved most replace tooltip funcs to Main.js --- CookieMonster.js | 132 ++++++++++++++++++++++++----------------------- src/Disp.js | 56 +------------------- src/Main.js | 76 +++++++++++++++++++++++---- 3 files changed, 136 insertions(+), 128 deletions(-) diff --git a/CookieMonster.js b/CookieMonster.js index e07907d..dde6bfb 100644 --- a/CookieMonster.js +++ b/CookieMonster.js @@ -2352,31 +2352,10 @@ CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } -/** - * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'b' - * It is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipBuild = function() { - CM.Disp.TooltipBuildBackup = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - /** * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() * CM.Disp.Tooltip() sets the tooltip type to 'u' - * It is called by CM.ReplaceNative() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - * + * It is called by Game.RebuildUpgrades() through CM.ReplaceNative() and is therefore not permanent like the other ReplaceTooltip functions */ CM.Disp.ReplaceTooltipUpgrade = function() { CM.Disp.TooltipUpgradeBackup = []; @@ -2389,39 +2368,6 @@ CM.Disp.ReplaceTooltipUpgrade = function() { } } -/** - * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'g' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBackup = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 's' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - /** * This function enhance the standard tooltips by creating and changing l('tooltip') * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip() @@ -4094,12 +4040,10 @@ CM.ReplaceNative = function() { CM.Backup.scriptLoaded = Game.scriptLoaded; Game.scriptLoaded = function(who, script) { CM.Backup.scriptLoaded(who, script); - CM.Disp.ReplaceTooltipGrimoire() + CM.Main.ReplaceTooltipGrimoire() CM.ReplaceNativeGrimoire(); } - // TODO: Move this ReplaceTooltip function too other ReplaceTooltip functions - // OR: Move all other into this function CM.Backup.RebuildUpgrades = Game.RebuildUpgrades; Game.RebuildUpgrades = function() { CM.Backup.RebuildUpgrades(); @@ -4107,7 +4051,6 @@ CM.ReplaceNative = function() { Game.CalculateGains(); } - CM.Backup.DescribeDragonAura = Game.DescribeDragonAura; /** * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() @@ -4171,7 +4114,7 @@ CM.ReplaceNativeGrimoireLaunch = function() { eval('CM.Backup.GrimoireLaunchMod = ' + minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame')); Game.Objects['Wizard tower'].minigame.launch = function() { CM.Backup.GrimoireLaunchMod(); - CM.Disp.ReplaceTooltipGrimoire(); + CM.Main.ReplaceTooltipGrimoire(); CM.HasReplaceNativeGrimoireDraw = false; CM.ReplaceNativeGrimoireDraw(); } @@ -4286,9 +4229,7 @@ CM.DelayInit = function() { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } CM.Disp.CreateWrinklerButtons(); - CM.Disp.ReplaceTooltipBuild(); - CM.Disp.ReplaceTooltipGrimoire(); - CM.Disp.ReplaceTooltipLump(); + CM.Main.ReplaceTooltips(); CM.Main.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); @@ -4313,6 +4254,69 @@ CM.DelayInit = function() { Game.Win('Third-party'); } +/******** + * Section: Functions related to first initizalition of CM */ + +/** + * This function call all functions that replace Game-tooltips with CM-enhanced tooltips + * It is called by CM.DelayInit() + */ +CM.Main.ReplaceTooltips = function() { + CM.Main.ReplaceTooltipBuild(); + CM.Main.ReplaceTooltipGrimoire(); + CM.Main.ReplaceTooltipLump(); +} + +/******** + * Section: Functions related to replacing tooltips */ + + +/** + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipBuild = function() { + CM.Main.TooltipBuildBackup = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Main.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Main.TooltipGrimoireBackup = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Main.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipLump = function() { + if (Game.canLumps()) { + CM.Main.TooltipLumpBackup = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + + /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ @@ -4478,7 +4482,7 @@ CM.Main.CheckWrinklerCount = function() { * This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler * It is called by CM.DelayInit * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips - * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc. + * Thus, writing a CM.Main.ReplaceTooltipWrinkler function etc. */ CM.Main.AddWrinklerAreaDetect = function() { l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;}; diff --git a/src/Disp.js b/src/Disp.js index 102f600..b900572 100644 --- a/src/Disp.js +++ b/src/Disp.js @@ -1171,31 +1171,10 @@ CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) { CM.Disp[placeholder].appendChild(desc); } -/** - * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'b' - * It is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipBuild = function() { - CM.Disp.TooltipBuildBackup = []; - for (var i in Game.Objects) { - var me = Game.Objects[i]; - if (l('product' + me.id).onmouseover != null) { - CM.Disp.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; - eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); - } - } -} - /** * This function replaces the original .onmouseover functions of upgrades so that it calls CM.Disp.Tooltip() * CM.Disp.Tooltip() sets the tooltip type to 'u' - * It is called by CM.ReplaceNative() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - * + * It is called by Game.RebuildUpgrades() through CM.ReplaceNative() and is therefore not permanent like the other ReplaceTooltip functions */ CM.Disp.ReplaceTooltipUpgrade = function() { CM.Disp.TooltipUpgradeBackup = []; @@ -1208,39 +1187,6 @@ CM.Disp.ReplaceTooltipUpgrade = function() { } } -/** - * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 'g' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipGrimoire = function() { - if (Game.Objects['Wizard tower'].minigameLoaded) { - CM.Disp.TooltipGrimoireBackup = []; - for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { - if (l('grimoireSpell' + i).onmouseover != null) { - CM.Disp.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; - eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); - } - } - } -} - -/** - * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() - * CM.Disp.Tooltip() sets the tooltip type to 's' - * The function is called by CM.DelayInit() - * TODO: Place all ReplaceTooltip functions either under CM.DelayInit() or CM.ReplaceNative() - * TODO: Move this code to Main.js file - */ -CM.Disp.ReplaceTooltipLump = function() { - if (Game.canLumps()) { - CM.Disp.TooltipLumpBackup = l('lumps').onmouseover; - eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); - } -}; - /** * This function enhance the standard tooltips by creating and changing l('tooltip') * The function is called by .onmouseover events that have replaced original code to use CM.Disp.Tooltip() diff --git a/src/Main.js b/src/Main.js index caa11b2..17ac29e 100644 --- a/src/Main.js +++ b/src/Main.js @@ -45,12 +45,10 @@ CM.ReplaceNative = function() { CM.Backup.scriptLoaded = Game.scriptLoaded; Game.scriptLoaded = function(who, script) { CM.Backup.scriptLoaded(who, script); - CM.Disp.ReplaceTooltipGrimoire() + CM.Main.ReplaceTooltipGrimoire() CM.ReplaceNativeGrimoire(); } - // TODO: Move this ReplaceTooltip function too other ReplaceTooltip functions - // OR: Move all other into this function CM.Backup.RebuildUpgrades = Game.RebuildUpgrades; Game.RebuildUpgrades = function() { CM.Backup.RebuildUpgrades(); @@ -58,7 +56,6 @@ CM.ReplaceNative = function() { Game.CalculateGains(); } - CM.Backup.DescribeDragonAura = Game.DescribeDragonAura; /** * This functions adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura() @@ -122,7 +119,7 @@ CM.ReplaceNativeGrimoireLaunch = function() { eval('CM.Backup.GrimoireLaunchMod = ' + minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame')); Game.Objects['Wizard tower'].minigame.launch = function() { CM.Backup.GrimoireLaunchMod(); - CM.Disp.ReplaceTooltipGrimoire(); + CM.Main.ReplaceTooltipGrimoire(); CM.HasReplaceNativeGrimoireDraw = false; CM.ReplaceNativeGrimoireDraw(); } @@ -237,9 +234,7 @@ CM.DelayInit = function() { CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]); } CM.Disp.CreateWrinklerButtons(); - CM.Disp.ReplaceTooltipBuild(); - CM.Disp.ReplaceTooltipGrimoire(); - CM.Disp.ReplaceTooltipLump(); + CM.Main.ReplaceTooltips(); CM.Main.AddWrinklerAreaDetect(); CM.Cache.InitCookiesDiff(); CM.ReplaceNative(); @@ -264,6 +259,69 @@ CM.DelayInit = function() { Game.Win('Third-party'); } +/******** + * Section: Functions related to first initizalition of CM */ + +/** + * This function call all functions that replace Game-tooltips with CM-enhanced tooltips + * It is called by CM.DelayInit() + */ +CM.Main.ReplaceTooltips = function() { + CM.Main.ReplaceTooltipBuild(); + CM.Main.ReplaceTooltipGrimoire(); + CM.Main.ReplaceTooltipLump(); +} + +/******** + * Section: Functions related to replacing tooltips */ + + +/** + * This function replaces the original .onmouseover functions of buildings so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'b' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipBuild = function() { + CM.Main.TooltipBuildBackup = []; + for (var i in Game.Objects) { + var me = Game.Objects[i]; + if (l('product' + me.id).onmouseover != null) { + CM.Main.TooltipBuildBackup[i] = l('product' + me.id).onmouseover; + eval('l(\'product\' + me.id).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'b\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}'); + } + } +} + +/** + * This function replaces the original .onmouseover functions of the Grimoire minigame so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 'g' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipGrimoire = function() { + if (Game.Objects['Wizard tower'].minigameLoaded) { + CM.Main.TooltipGrimoireBackup = []; + for (var i in Game.Objects['Wizard tower'].minigame.spellsById) { + if (l('grimoireSpell' + i).onmouseover != null) { + CM.Main.TooltipGrimoireBackup[i] = l('grimoireSpell' + i).onmouseover; + eval('l(\'grimoireSpell\' + i).onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'g\', \'' + i + '\');}, \'this\'); Game.tooltip.wobble();}'); + } + } + } +} + +/** + * This function replaces the original .onmouseover functions of sugar lumps so that it calls CM.Disp.Tooltip() + * CM.Disp.Tooltip() sets the tooltip type to 's' + * It is called by CM.Main.ReplaceTooltips() + */ +CM.Main.ReplaceTooltipLump = function() { + if (Game.canLumps()) { + CM.Main.TooltipLumpBackup = l('lumps').onmouseover; + eval('l(\'lumps\').onmouseover = function() {Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'s\', \'Lump\');}, \'this\'); Game.tooltip.wobble();}'); + } +}; + + /******** * Section: Functions related to checking for changes in Minigames/GC's/Ticker * TODO: Possibly move this section */ @@ -429,7 +487,7 @@ CM.Main.CheckWrinklerCount = function() { * This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler * It is called by CM.DelayInit * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips - * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc. + * Thus, writing a CM.Main.ReplaceTooltipWrinkler function etc. */ CM.Main.AddWrinklerAreaDetect = function() { l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;};