Complete overhaul of code structure and relevant files (#639)
This commit is contained in:
17
src/Main/CheckStates/Garden.js
Normal file
17
src/Main/CheckStates/Garden.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { LastGardenNextStep } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function checks if a garden tick has happened
|
||||
*/
|
||||
export default function CheckGardenTick() {
|
||||
if (Game.Objects.Farm.minigameLoaded && LastGardenNextStep !== Game.Objects.Farm.minigame.nextStep) {
|
||||
if (LastGardenNextStep !== 0 && LastGardenNextStep < Date.now()) {
|
||||
Flash(3, 'GardFlash');
|
||||
PlaySound(CMOptions.GardSoundURL, 'GardSound', 'GardVolume');
|
||||
}
|
||||
LastGardenNextStep = Game.Objects.Farm.minigame.nextStep;
|
||||
}
|
||||
}
|
||||
66
src/Main/CheckStates/GoldenCookie.js
Normal file
66
src/Main/CheckStates/GoldenCookie.js
Normal file
@@ -0,0 +1,66 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { CacheSpawnedGoldenShimmer, CacheGoldenShimmersByID } from '../../Cache/VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import CreateGCTimer from '../../Disp/GoldenCookieTimers/GoldenCookieTimers';
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import Notification from '../../Disp/Notifications/Notification';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { UpdateFavicon } from '../../Disp/TabTitle/FavIcon';
|
||||
import { GCTimers } from '../../Disp/VariablesAndData';
|
||||
import { CurrSpawnedGoldenCookieState, LastGoldenCookieState, LastSpawnedGoldenCookieState } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* Auxilirary function that finds all currently spawned shimmers.
|
||||
* CM.Cache.spawnedGoldenShimmer stores the non-user spawned cookie to later determine data for the favicon and tab-title
|
||||
* It is called by CM.CM.Main.CheckGoldenCookie
|
||||
*/
|
||||
function FindShimmer() {
|
||||
CurrSpawnedGoldenCookieState = 0;
|
||||
CacheGoldenShimmersByID = {};
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
CacheGoldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i];
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type === 'golden') {
|
||||
CacheSpawnedGoldenShimmer = Game.shimmers[i];
|
||||
CurrSpawnedGoldenCookieState += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function checks for changes in the amount of Golden Cookies
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
export default function CheckGoldenCookie() {
|
||||
FindShimmer();
|
||||
for (const i of Object.keys(GCTimers)) {
|
||||
if (typeof CacheGoldenShimmersByID[i] === 'undefined') {
|
||||
GCTimers[i].parentNode.removeChild(GCTimers[i]);
|
||||
delete GCTimers[i];
|
||||
}
|
||||
}
|
||||
if (LastGoldenCookieState !== Game.shimmerTypes.golden.n) {
|
||||
LastGoldenCookieState = Game.shimmerTypes.golden.n;
|
||||
if (LastGoldenCookieState) {
|
||||
if (LastSpawnedGoldenCookieState < CurrSpawnedGoldenCookieState) {
|
||||
Flash(3, 'GCFlash');
|
||||
PlaySound(CMOptions.GCSoundURL, 'GCSound', 'GCVolume');
|
||||
Notification('GCNotification', 'Golden Cookie Spawned', 'A Golden Cookie has spawned. Click it now!');
|
||||
}
|
||||
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
if (typeof GCTimers[Game.shimmers[i].id] === 'undefined') {
|
||||
CreateGCTimer(Game.shimmers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateFavicon();
|
||||
LastSpawnedGoldenCookieState = CurrSpawnedGoldenCookieState;
|
||||
if (CurrSpawnedGoldenCookieState === 0) CacheSpawnedGoldenShimmer = 0;
|
||||
} else if (CMOptions.GCTimer === 1 && LastGoldenCookieState) {
|
||||
for (const i of Object.keys(GCTimers)) {
|
||||
GCTimers[i].style.opacity = CacheGoldenShimmersByID[i].l.style.opacity;
|
||||
GCTimers[i].style.transform = CacheGoldenShimmersByID[i].l.style.transform;
|
||||
GCTimers[i].textContent = Math.ceil(CacheGoldenShimmersByID[i].life / Game.fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
src/Main/CheckStates/Grimoire.js
Normal file
22
src/Main/CheckStates/Grimoire.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import Notification from '../../Disp/Notifications/Notification';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { LastMagicBarFull } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function checks if the magic meter is full
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
export default function CheckMagicMeter() {
|
||||
if (Game.Objects['Wizard tower'].minigameLoaded && CMOptions.GrimoireBar === 1) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
if (minigame.magic < minigame.magicM) LastMagicBarFull = false;
|
||||
else if (!LastMagicBarFull) {
|
||||
LastMagicBarFull = true;
|
||||
Flash(3, 'MagicFlash');
|
||||
PlaySound(CMOptions.MagicSoundURL, 'MagicSound', 'MagicVolume');
|
||||
Notification('MagicNotification', 'Magic Meter full', 'Your Magic Meter is full. Cast a spell!');
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/Main/CheckStates/Season.js
Normal file
26
src/Main/CheckStates/Season.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { CacheSeasonPopShimmer } from '../../Cache/VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import Notification from '../../Disp/Notifications/Notification';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { LastSeasonPopupState } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function checks if there is reindeer that has spawned
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
export default function CheckSeasonPopup() {
|
||||
if (LastSeasonPopupState !== Game.shimmerTypes.reindeer.spawned) {
|
||||
LastSeasonPopupState = Game.shimmerTypes.reindeer.spawned;
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type === 'reindeer') {
|
||||
CacheSeasonPopShimmer = Game.shimmers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
Flash(3, 'SeaFlash');
|
||||
PlaySound(CMOptions.SeaSoundURL, 'SeaSound', 'SeaVolume');
|
||||
Notification('SeaNotification', 'Reindeer sighted!', 'A Reindeer has spawned. Click it now!');
|
||||
}
|
||||
}
|
||||
19
src/Main/CheckStates/Ticker.js
Normal file
19
src/Main/CheckStates/Ticker.js
Normal file
@@ -0,0 +1,19 @@
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import Notification from '../../Disp/Notifications/Notification';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { LastTickerFortuneState } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function checks if there is a fortune cookie on the ticker
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
export default function CheckTickerFortune() {
|
||||
if (LastTickerFortuneState !== (Game.TickerEffect && Game.TickerEffect.type === 'fortune')) {
|
||||
LastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type === 'fortune');
|
||||
if (LastTickerFortuneState) {
|
||||
Flash(3, 'FortuneFlash');
|
||||
PlaySound(CM.Options.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
|
||||
Notification('FortuneNotification', 'Fortune Cookie found', 'A Fortune Cookie has appeared on the Ticker.');
|
||||
}
|
||||
}
|
||||
}
|
||||
38
src/Main/CheckStates/Wrinkler.js
Normal file
38
src/Main/CheckStates/Wrinkler.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import Flash from '../../Disp/Notifications/Flash';
|
||||
import Notification from '../../Disp/Notifications/Notification';
|
||||
import PlaySound from '../../Disp/Notifications/Sound';
|
||||
import { LastWrinklerCount } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function checks if any new Wrinklers have popped up
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
export default function CheckWrinklerCount() {
|
||||
if (Game.elderWrath > 0) {
|
||||
let CurrentWrinklers = 0;
|
||||
for (const i in Game.wrinklers) {
|
||||
if (Game.wrinklers[i].phase === 2) CurrentWrinklers++;
|
||||
}
|
||||
if (CurrentWrinklers > LastWrinklerCount) {
|
||||
LastWrinklerCount = CurrentWrinklers;
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CMOptions.WrinklerMaxFlash) {
|
||||
Flash(3, 'WrinklerMaxFlash');
|
||||
} else {
|
||||
Flash(3, 'WrinklerFlash');
|
||||
}
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CMOptions.WrinklerMaxSound) {
|
||||
PlaySound(CMOptions.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
|
||||
} else {
|
||||
PlaySound(CMOptions.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
|
||||
}
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CMOptions.WrinklerMaxNotification) {
|
||||
Notification('WrinklerMaxNotification', 'Maximum Wrinklers Reached', 'You have reached your maximum ammount of wrinklers');
|
||||
} else {
|
||||
Notification('WrinklerNotification', 'A Wrinkler appeared', 'A new wrinkler has appeared');
|
||||
}
|
||||
} else {
|
||||
LastWrinklerCount = CurrentWrinklers;
|
||||
}
|
||||
}
|
||||
}
|
||||
62
src/Main/Initialization.js
Normal file
62
src/Main/Initialization.js
Normal file
@@ -0,0 +1,62 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import InitCache from '../Cache/CacheInit';
|
||||
import { CacheStatsCookies } from '../Cache/Stats/Stats';
|
||||
import { LoadConfig } from '../Config/SaveLoadReload/SaveLoadReloadSettings';
|
||||
import { VersionMajor, VersionMinor } from '../Data/Moddata';
|
||||
import CreateUpgradeBar from '../Disp/BuildingsUpgrades/UpgradeBar';
|
||||
import { CreateBotBar } from '../Disp/InfoBars/BottomBar';
|
||||
import { CreateTimerBar } from '../Disp/InfoBars/TimerBar';
|
||||
import CreateWrinklerButtons from '../Disp/Initialization/CreateWrinklerButton';
|
||||
import CreateCssArea from '../Disp/Initialization/CssArea';
|
||||
import UpdateBuildingUpgradeStyle from '../Disp/Initialization/UpdateBuildingUpgradeStyle';
|
||||
import CreateWhiteScreen from '../Disp/Initialization/WhiteScreen';
|
||||
import { CreateFavicon } from '../Disp/TabTitle/FavIcon';
|
||||
import { CreateSimpleTooltip } from '../Disp/Tooltips/Tooltip';
|
||||
import { CMLastAscendState, TooltipText } from '../Disp/VariablesAndData';
|
||||
import InitData from '../Sim/InitializeData/InitData';
|
||||
import ReplaceNativeGrimoire from './ReplaceGameElements/NativeGrimoire';
|
||||
import ReplaceTooltips from './ReplaceGameElements/Tooltips';
|
||||
import ReplaceNative from './ReplaceGameFunctions/ReplaceNative';
|
||||
import { LastModCount } from './VariablesAndData';
|
||||
import AddWrinklerAreaDetect from './WrinklerArea/AddDetectArea';
|
||||
|
||||
/**
|
||||
* Initialization loop of Cookie Monster
|
||||
*/
|
||||
export default function InitializeCookieMonster() {
|
||||
InitData();
|
||||
CacheStatsCookies();
|
||||
InitCache();
|
||||
|
||||
// Stored to check if we need to re-initiliaze data
|
||||
LastModCount = Object.keys(Game.mods).length;
|
||||
|
||||
// Creating visual elements
|
||||
CreateCssArea();
|
||||
CreateBotBar();
|
||||
CreateTimerBar();
|
||||
CreateUpgradeBar();
|
||||
CreateWhiteScreen();
|
||||
CreateFavicon();
|
||||
for (const i of Object.keys(TooltipText)) {
|
||||
CreateSimpleTooltip(TooltipText[i][0], TooltipText[i][1], TooltipText[i][2]);
|
||||
}
|
||||
CreateWrinklerButtons();
|
||||
UpdateBuildingUpgradeStyle();
|
||||
|
||||
ReplaceTooltips();
|
||||
AddWrinklerAreaDetect();
|
||||
|
||||
// Replace native functions
|
||||
ReplaceNative();
|
||||
ReplaceNativeGrimoire();
|
||||
Game.CalculateGains();
|
||||
|
||||
LoadConfig(); // Must be after all things are created!
|
||||
CMLastAscendState = Game.OnAscend;
|
||||
|
||||
if (Game.prefs.popups) Game.Popup(`Cookie Monster version ${VersionMajor}.${VersionMinor} loaded!`);
|
||||
else Game.Notify(`Cookie Monster version ${VersionMajor}.${VersionMinor} loaded!`, '', '', 1, 1);
|
||||
|
||||
Game.Win('Third-party');
|
||||
}
|
||||
85
src/Main/Loop.js
Normal file
85
src/Main/Loop.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import InitCache from '../Cache/CacheInit';
|
||||
import LoopCache from '../Cache/CacheLoop';
|
||||
import CacheNoGoldSwitchCPS from '../Cache/CPS/NoGoldSwitchCPS';
|
||||
import CacheSellAllForChoEgg from '../Cache/CPS/SellChoEgg';
|
||||
import CacheDragonCost from '../Cache/Dragon/Dragon';
|
||||
import { CacheBuildingsPrices, CacheIncome } from '../Cache/PriceAndIncome/PriceAndIncome';
|
||||
import { CacheChain } from '../Cache/Stats/ChainCookies';
|
||||
import CacheAllMissingUpgrades from '../Cache/Stats/MissingUpgrades';
|
||||
import CacheSeasonSpec from '../Cache/Stats/Reindeer';
|
||||
import { CacheGoldenAndWrathCookiesMults, CacheStatsCookies } from '../Cache/Stats/Stats';
|
||||
import {
|
||||
CacheDoRemakeBuildPrices, CacheHadBuildAura,
|
||||
} from '../Cache/VariablesAndData';
|
||||
import UpdateAscendState from '../Disp/HelperFunctions/UpdateAscendState';
|
||||
import { LastAscendState } from '../Disp/VariablesAndData';
|
||||
import InitData from '../Sim/InitializeData/InitData';
|
||||
import { SimDoSims } from '../Sim/VariablesAndData';
|
||||
import CheckGardenTick from './CheckStates/Garden';
|
||||
import CheckGoldenCookie from './CheckStates/GoldenCookie';
|
||||
import CheckMagicMeter from './CheckStates/Grimoire';
|
||||
import CheckSeasonPopup from './CheckStates/Season';
|
||||
import CheckTickerFortune from './CheckStates/Ticker';
|
||||
import CheckWrinklerCount from './CheckStates/Wrinkler';
|
||||
import { LastModCount } from './VariablesAndData';
|
||||
|
||||
/**
|
||||
* Main loop of Cookie Monster
|
||||
* CM.init registers it to the "logic" hook provided by the modding api
|
||||
*/
|
||||
export default function CMLoop() {
|
||||
if (LastAscendState !== Game.OnAscend) {
|
||||
LastAscendState = Game.OnAscend;
|
||||
UpdateAscendState();
|
||||
}
|
||||
if (!Game.OnAscend && Game.AscendTimer === 0) {
|
||||
// Check if any other mods have been loaded
|
||||
if (LastModCount !== Object.keys(Game.mods).length) {
|
||||
InitData();
|
||||
InitCache();
|
||||
LastModCount = Object.keys(Game.mods).length;
|
||||
}
|
||||
|
||||
// CM.Sim.DoSims is set whenever CPS has changed
|
||||
if (SimDoSims) {
|
||||
CacheIncome();
|
||||
|
||||
CacheNoGoldSwitchCPS(); // Needed first
|
||||
CacheGoldenAndWrathCookiesMults();
|
||||
CacheStatsCookies();
|
||||
CacheAllMissingUpgrades();
|
||||
CacheChain();
|
||||
CacheDragonCost();
|
||||
|
||||
CacheSeasonSpec();
|
||||
CacheSellAllForChoEgg();
|
||||
|
||||
SimDoSims = 0;
|
||||
}
|
||||
|
||||
// Check for aura change to recalculate buildings prices
|
||||
const hasBuildAura = Game.auraMult('Fierce Hoarder') > 0;
|
||||
if (!CacheHadBuildAura && hasBuildAura) {
|
||||
CacheHadBuildAura = true;
|
||||
CacheDoRemakeBuildPrices = 1;
|
||||
} else if (CacheHadBuildAura && !hasBuildAura) {
|
||||
CacheHadBuildAura = false;
|
||||
CacheDoRemakeBuildPrices = 1;
|
||||
}
|
||||
|
||||
if (CacheDoRemakeBuildPrices) {
|
||||
CacheBuildingsPrices();
|
||||
CacheDoRemakeBuildPrices = 0;
|
||||
}
|
||||
|
||||
LoopCache();
|
||||
|
||||
// Check all changing minigames and game-states
|
||||
CheckGoldenCookie();
|
||||
CheckTickerFortune();
|
||||
CheckSeasonPopup();
|
||||
CheckGardenTick();
|
||||
CheckMagicMeter();
|
||||
CheckWrinklerCount();
|
||||
}
|
||||
}
|
||||
550
src/Main/Main.js
550
src/Main/Main.js
@@ -1,550 +0,0 @@
|
||||
/**
|
||||
* Main *
|
||||
*/
|
||||
|
||||
/**
|
||||
* Section: Functions related to the main and initialization loop */
|
||||
|
||||
/**
|
||||
* Main loop of Cookie Monster
|
||||
* CM.init registers it to the "logic" hook provided by the modding api
|
||||
*/
|
||||
CM.Main.Loop = function () {
|
||||
if (CM.Disp.lastAscendState !== Game.OnAscend) {
|
||||
CM.Disp.lastAscendState = Game.OnAscend;
|
||||
CM.Disp.UpdateAscendState();
|
||||
}
|
||||
if (!Game.OnAscend && Game.AscendTimer === 0) {
|
||||
// Check if any other mods have been loaded
|
||||
if (CM.Main.LastModCount !== Object.keys(Game.mods).length) {
|
||||
CM.Sim.CreateSimFunctions();
|
||||
CM.Sim.InitData();
|
||||
CM.Cache.InitCache();
|
||||
CM.Main.LastModCount = Object.keys(Game.mods).length;
|
||||
}
|
||||
|
||||
// CM.Sim.DoSims is set whenever CPS has changed
|
||||
if (CM.Sim.DoSims) {
|
||||
CM.Cache.CacheIncome();
|
||||
|
||||
CM.Cache.NoGoldSwitchCPS(); // Needed first
|
||||
CM.Cache.CacheGoldenAndWrathCookiesMults();
|
||||
CM.Cache.CacheStats();
|
||||
CM.Cache.CacheMissingUpgrades();
|
||||
CM.Cache.CacheChain();
|
||||
CM.Cache.CacheDragonCost();
|
||||
|
||||
CM.Cache.CacheSeaSpec();
|
||||
CM.Cache.CacheSellForChoEgg();
|
||||
|
||||
CM.Sim.DoSims = 0;
|
||||
}
|
||||
|
||||
// Check for aura change to recalculate buildings prices
|
||||
const hasBuildAura = Game.auraMult('Fierce Hoarder') > 0;
|
||||
if (!CM.Cache.HadBuildAura && hasBuildAura) {
|
||||
CM.Cache.HadBuildAura = true;
|
||||
CM.Cache.DoRemakeBuildPrices = 1;
|
||||
} else if (CM.Cache.HadBuildAura && !hasBuildAura) {
|
||||
CM.Cache.HadBuildAura = false;
|
||||
CM.Cache.DoRemakeBuildPrices = 1;
|
||||
}
|
||||
|
||||
if (CM.Cache.DoRemakeBuildPrices) {
|
||||
CM.Cache.CacheBuildingsPrices();
|
||||
CM.Cache.DoRemakeBuildPrices = 0;
|
||||
}
|
||||
|
||||
CM.Cache.LoopCache();
|
||||
|
||||
// Check all changing minigames and game-states
|
||||
CM.Main.CheckGoldenCookie();
|
||||
CM.Main.CheckTickerFortune();
|
||||
CM.Main.CheckSeasonPopup();
|
||||
CM.Main.CheckGardenTick();
|
||||
CM.Main.CheckMagicMeter();
|
||||
CM.Main.CheckWrinklerCount();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialization loop of Cookie Monster
|
||||
* Called by CM.init()
|
||||
*/
|
||||
CM.Main.DelayInit = function () {
|
||||
// Create CM.Sim functions
|
||||
CM.Sim.CreateSimFunctions();
|
||||
|
||||
CM.Sim.InitData();
|
||||
CM.Cache.InitCache();
|
||||
|
||||
// Stored to check if we need to re-initiliaze data
|
||||
CM.Main.LastModCount = Object.keys(Game.mods).length;
|
||||
|
||||
// Creating visual elements
|
||||
CM.Disp.CreateCssArea();
|
||||
CM.Disp.CreateBotBar();
|
||||
CM.Disp.CreateTimerBar();
|
||||
CM.Disp.CreateUpgradeBar();
|
||||
CM.Disp.CreateWhiteScreen();
|
||||
CM.Disp.CreateFavicon();
|
||||
for (const i of Object.keys(CM.Disp.TooltipText)) {
|
||||
CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]);
|
||||
}
|
||||
CM.Disp.CreateWrinklerButtons();
|
||||
CM.Disp.UpdateBuildingUpgradeStyle();
|
||||
CM.Main.ReplaceTooltips();
|
||||
CM.Main.AddWrinklerAreaDetect();
|
||||
|
||||
// Replace native functions
|
||||
CM.Main.ReplaceNative();
|
||||
CM.Main.ReplaceNativeGrimoire();
|
||||
Game.CalculateGains();
|
||||
|
||||
CM.Config.LoadConfig(); // Must be after all things are created!
|
||||
CM.Disp.lastAscendState = Game.OnAscend;
|
||||
|
||||
if (Game.prefs.popups) Game.Popup(`Cookie Monster version ${CM.VersionMajor}.${CM.VersionMinor} loaded!`);
|
||||
else Game.Notify(`Cookie Monster version ${CM.VersionMajor}.${CM.VersionMinor} loaded!`, '', '', 1, 1);
|
||||
|
||||
Game.Win('Third-party');
|
||||
};
|
||||
|
||||
/**
|
||||
* Section: Functions related to replacing stuff */
|
||||
|
||||
/**
|
||||
* This function replaces certain native (from the base-game) functions
|
||||
* It is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Main.ReplaceNative = function () {
|
||||
CM.Backup.Beautify = Beautify;
|
||||
Beautify = CM.Disp.Beautify;
|
||||
|
||||
CM.Backup.CalculateGains = Game.CalculateGains;
|
||||
eval(`CM.Backup.CalculateGainsMod = ${Game.CalculateGains.toString().split('ages\');').join('ages\');CM.Sim.DateAges = Date.now();').split('if (Game.Has(\'Century')
|
||||
.join('CM.Sim.DateCentury = Date.now();if (Game.Has(\'Century')}`);
|
||||
Game.CalculateGains = function () {
|
||||
CM.Backup.CalculateGainsMod();
|
||||
CM.Sim.DoSims = 1;
|
||||
};
|
||||
|
||||
CM.Backup.tooltip = {};
|
||||
CM.Backup.tooltip.draw = Game.tooltip.draw;
|
||||
eval(`CM.Backup.tooltip.drawMod = ${Game.tooltip.draw.toString().split('this').join('Game.tooltip')}`);
|
||||
Game.tooltip.draw = function (from, text, origin) {
|
||||
CM.Backup.tooltip.drawMod(from, text, origin);
|
||||
};
|
||||
|
||||
CM.Backup.tooltip.update = Game.tooltip.update;
|
||||
eval(`CM.Backup.tooltip.updateMod = ${Game.tooltip.update.toString().split('this.').join('Game.tooltip.')}`);
|
||||
Game.tooltip.update = function () {
|
||||
CM.Backup.tooltip.updateMod();
|
||||
CM.Disp.UpdateTooltipLocation();
|
||||
};
|
||||
|
||||
CM.Backup.UpdateWrinklers = Game.UpdateWrinklers;
|
||||
Game.UpdateWrinklers = function () {
|
||||
CM.Main.FixMouseY(CM.Backup.UpdateWrinklers);
|
||||
};
|
||||
|
||||
CM.Backup.UpdateSpecial = Game.UpdateSpecial;
|
||||
Game.UpdateSpecial = function () {
|
||||
CM.Main.FixMouseY(CM.Backup.UpdateSpecial);
|
||||
};
|
||||
|
||||
// Assumes newer browsers
|
||||
l('bigCookie').removeEventListener('click', Game.ClickCookie, false);
|
||||
l('bigCookie').addEventListener('click', function () { CM.Main.FixMouseY(Game.ClickCookie); }, false);
|
||||
|
||||
CM.Backup.RebuildUpgrades = Game.RebuildUpgrades;
|
||||
Game.RebuildUpgrades = function () {
|
||||
CM.Backup.RebuildUpgrades();
|
||||
CM.Disp.ReplaceTooltipUpgrade();
|
||||
Game.CalculateGains();
|
||||
};
|
||||
|
||||
CM.Backup.ClickProduct = Game.ClickProduct;
|
||||
/**
|
||||
* This function adds a check to the purchase of a building to allow BulkBuyBlock to work.
|
||||
* If the options is 1 (on) bulkPrice is under cookies you can't buy the building.
|
||||
*/
|
||||
Game.ClickProduct = function (what) {
|
||||
if (!CM.Options.BulkBuyBlock || (Game.ObjectsById[what].bulkPrice < Game.cookies || Game.buyMode === -1)) {
|
||||
CM.Backup.ClickProduct(what);
|
||||
}
|
||||
};
|
||||
|
||||
CM.Backup.DescribeDragonAura = Game.DescribeDragonAura;
|
||||
/**
|
||||
* This function adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura()
|
||||
* This adds information about CPS differences and costs to the aura choosing interface
|
||||
* @param {number} aura The number of the aura currently selected by the mouse/user
|
||||
*/
|
||||
Game.DescribeDragonAura = function (aura) {
|
||||
CM.Backup.DescribeDragonAura(aura);
|
||||
CM.Disp.AddAuraInfo(aura);
|
||||
};
|
||||
|
||||
CM.Backup.ToggleSpecialMenu = Game.ToggleSpecialMenu;
|
||||
/**
|
||||
* This function adds the code to display the tooltips for the levelUp button of the dragon
|
||||
*/
|
||||
Game.ToggleSpecialMenu = function (on) {
|
||||
CM.Backup.ToggleSpecialMenu(on);
|
||||
CM.Disp.AddDragonLevelUpTooltip();
|
||||
};
|
||||
|
||||
CM.Backup.UpdateMenu = Game.UpdateMenu;
|
||||
Game.UpdateMenu = function () {
|
||||
if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') {
|
||||
CM.Backup.UpdateMenu();
|
||||
CM.Disp.AddMenu();
|
||||
}
|
||||
};
|
||||
|
||||
CM.Backup.sayTime = Game.sayTime;
|
||||
CM.Disp.sayTime = function (time, detail) {
|
||||
if (Number.isNaN(time) || time <= 0) return CM.Backup.sayTime(time, detail);
|
||||
else return CM.Disp.FormatTime(time / Game.fps, 1);
|
||||
};
|
||||
|
||||
// Since the Ascend Tooltip is not actually a tooltip we need to add our additional info here...
|
||||
CM.Backup.Logic = Game.Logic;
|
||||
CM.Backup.LogicMod = new Function(
|
||||
`return ${Game.Logic.toString()
|
||||
.split('document.title')
|
||||
.join('CM.Disp.Title')
|
||||
.split("' more cookies</b> for the next level.<br>';")
|
||||
.join("` more cookies</b> for the next level.<br>${CM.Options.TooltipAscendButton ? `<div class='line'></div>It takes ${CM.Cache.TimeTillNextPrestige} to reach the next level and you are making ${Beautify(CM.Cache.HCPerSecond, 2)} chips on average in the last 5 seconds.<br>` : ``}`;")}`,
|
||||
)();
|
||||
Game.Logic = function () {
|
||||
CM.Backup.LogicMod();
|
||||
// Update Title
|
||||
CM.Disp.UpdateTitle();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* This function fixes replaces the Launch and Draw functions of the Grimoire
|
||||
* It is called by CM.Main.DelayInit() and Game.LoadMinigames()
|
||||
*/
|
||||
CM.Main.ReplaceNativeGrimoire = function () {
|
||||
CM.Main.ReplaceNativeGrimoireLaunch();
|
||||
CM.Main.ReplaceNativeGrimoireDraw();
|
||||
};
|
||||
|
||||
/**
|
||||
* This function fixes replaces the .launch function of the Grimoire
|
||||
* It is called by CM.Main.ReplaceNativeGrimoire()
|
||||
*/
|
||||
CM.Main.ReplaceNativeGrimoireLaunch = function () {
|
||||
if (!CM.Main.HasReplaceNativeGrimoireLaunch && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
CM.Backup.GrimoireLaunch = minigame.launch;
|
||||
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.Main.ReplaceTooltipGrimoire();
|
||||
CM.HasReplaceNativeGrimoireDraw = false;
|
||||
CM.Main.ReplaceNativeGrimoireDraw();
|
||||
};
|
||||
CM.Main.HasReplaceNativeGrimoireLaunch = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function fixes replaces the .draw function of the Grimoire
|
||||
* It is called by CM.Main.ReplaceNativeGrimoire()
|
||||
*/
|
||||
CM.Main.ReplaceNativeGrimoireDraw = function () {
|
||||
if (!CM.Main.HasReplaceNativeGrimoireDraw && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
CM.Backup.GrimoireDraw = minigame.draw;
|
||||
Game.Objects['Wizard tower'].minigame.draw = function () {
|
||||
CM.Backup.GrimoireDraw();
|
||||
if (CM.Options.GrimoireBar === 1 && minigame.magic < minigame.magicM) {
|
||||
minigame.magicBarTextL.innerHTML += ` (${CM.Disp.FormatTime(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, minigame.magicM))})`;
|
||||
}
|
||||
};
|
||||
CM.Main.HasReplaceNativeGrimoireDraw = true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.Main.DelayInit()
|
||||
*/
|
||||
CM.Main.ReplaceTooltips = function () {
|
||||
CM.Main.ReplaceTooltipBuild();
|
||||
CM.Main.ReplaceTooltipLump();
|
||||
|
||||
// Replace Tooltips of Minigames. Nesting it in LoadMinigames makes sure to replace them even if
|
||||
// they were not loaded initially
|
||||
CM.Backup.LoadMinigames = Game.LoadMinigames;
|
||||
Game.LoadMinigames = function () {
|
||||
CM.Backup.LoadMinigames();
|
||||
CM.Main.ReplaceTooltipGarden();
|
||||
CM.Main.ReplaceTooltipGrimoire();
|
||||
CM.Main.ReplaceNativeGrimoire();
|
||||
};
|
||||
Game.LoadMinigames();
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 (const i of Object.keys(Game.Objects)) {
|
||||
const 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 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();}');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 (const 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 all garden plants so that it calls CM.Disp.Tooltip()
|
||||
* CM.Disp.Tooltip() sets the tooltip type to 'p'
|
||||
* It is called by CM.Main.ReplaceTooltips()
|
||||
*/
|
||||
CM.Main.ReplaceTooltipGarden = function () {
|
||||
if (Game.Objects.Farm.minigameLoaded) {
|
||||
l('gardenTool-1').onmouseover = function () { Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function () { return CM.Disp.Tooltip('ha', 'HarvestAllButton'); }, 'this'); Game.tooltip.wobble(); };
|
||||
Array.from(l('gardenPlot').children).forEach((child) => {
|
||||
const coords = child.id.slice(-3);
|
||||
child.onmouseover = function () { Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function () { return CM.Disp.Tooltip('p', [`${coords[0]}`, `${coords[2]}`]); }, 'this'); Game.tooltip.wobble(); };
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Section: Functions related to checking for changes in Minigames/GC's/Ticker */
|
||||
|
||||
/**
|
||||
* Auxilirary function that finds all currently spawned shimmers.
|
||||
* CM.Cache.spawnedGoldenShimmer stores the non-user spawned cookie to later determine data for the favicon and tab-title
|
||||
* It is called by CM.CM.Main.CheckGoldenCookie
|
||||
*/
|
||||
CM.Main.FindShimmer = function () {
|
||||
CM.Main.currSpawnedGoldenCookieState = 0;
|
||||
CM.Cache.goldenShimmersByID = {};
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
CM.Cache.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i];
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type === 'golden') {
|
||||
CM.Cache.spawnedGoldenShimmer = Game.shimmers[i];
|
||||
CM.Main.currSpawnedGoldenCookieState += 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks for changes in the amount of Golden Cookies
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckGoldenCookie = function () {
|
||||
CM.Main.FindShimmer();
|
||||
for (const i of Object.keys(CM.Disp.GCTimers)) {
|
||||
if (typeof CM.Cache.goldenShimmersByID[i] === 'undefined') {
|
||||
CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
|
||||
delete CM.Disp.GCTimers[i];
|
||||
}
|
||||
}
|
||||
if (CM.Main.lastGoldenCookieState !== Game.shimmerTypes.golden.n) {
|
||||
CM.Main.lastGoldenCookieState = Game.shimmerTypes.golden.n;
|
||||
if (CM.Main.lastGoldenCookieState) {
|
||||
if (CM.Main.lastSpawnedGoldenCookieState < CM.Main.currSpawnedGoldenCookieState) {
|
||||
CM.Disp.Flash(3, 'GCFlash');
|
||||
CM.Disp.PlaySound(CM.Options.GCSoundURL, 'GCSound', 'GCVolume');
|
||||
CM.Disp.Notification('GCNotification', 'Golden Cookie Spawned', 'A Golden Cookie has spawned. Click it now!');
|
||||
}
|
||||
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] === 'undefined') {
|
||||
CM.Disp.CreateGCTimer(Game.shimmers[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
CM.Disp.UpdateFavicon();
|
||||
CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState;
|
||||
if (CM.Main.currSpawnedGoldenCookieState === 0) CM.Cache.spawnedGoldenShimmer = 0;
|
||||
} else if (CM.Options.GCTimer === 1 && CM.Main.lastGoldenCookieState) {
|
||||
for (const i of Object.keys(CM.Disp.GCTimers)) {
|
||||
CM.Disp.GCTimers[i].style.opacity = CM.Cache.goldenShimmersByID[i].l.style.opacity;
|
||||
CM.Disp.GCTimers[i].style.transform = CM.Cache.goldenShimmersByID[i].l.style.transform;
|
||||
CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Cache.goldenShimmersByID[i].life / Game.fps);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks if there is reindeer that has spawned
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckSeasonPopup = function () {
|
||||
if (CM.Main.lastSeasonPopupState !== Game.shimmerTypes.reindeer.spawned) {
|
||||
CM.Main.lastSeasonPopupState = Game.shimmerTypes.reindeer.spawned;
|
||||
for (const i of Object.keys(Game.shimmers)) {
|
||||
if (Game.shimmers[i].spawnLead && Game.shimmers[i].type === 'reindeer') {
|
||||
CM.Cache.seasonPopShimmer = Game.shimmers[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
CM.Disp.Flash(3, 'SeaFlash');
|
||||
CM.Disp.PlaySound(CM.Options.SeaSoundURL, 'SeaSound', 'SeaVolume');
|
||||
CM.Disp.Notification('SeaNotification', 'Reindeer sighted!', 'A Reindeer has spawned. Click it now!');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks if there is a fortune cookie on the ticker
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckTickerFortune = function () {
|
||||
if (CM.Main.lastTickerFortuneState !== (Game.TickerEffect && Game.TickerEffect.type === 'fortune')) {
|
||||
CM.Main.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type === 'fortune');
|
||||
if (CM.Main.lastTickerFortuneState) {
|
||||
CM.Disp.Flash(3, 'FortuneFlash');
|
||||
CM.Disp.PlaySound(CM.Options.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
|
||||
CM.Disp.Notification('FortuneNotification', 'Fortune Cookie found', 'A Fortune Cookie has appeared on the Ticker.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks if a garden tick has happened
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckGardenTick = function () {
|
||||
if (Game.Objects.Farm.minigameLoaded && CM.Main.lastGardenNextStep !== Game.Objects.Farm.minigame.nextStep) {
|
||||
if (CM.Main.lastGardenNextStep !== 0 && CM.Main.lastGardenNextStep < Date.now()) {
|
||||
CM.Disp.Flash(3, 'GardFlash');
|
||||
CM.Disp.PlaySound(CM.Options.GardSoundURL, 'GardSound', 'GardVolume');
|
||||
}
|
||||
CM.Main.lastGardenNextStep = Game.Objects.Farm.minigame.nextStep;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks if the magic meter is full
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckMagicMeter = function () {
|
||||
if (Game.Objects['Wizard tower'].minigameLoaded && CM.Options.GrimoireBar === 1) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
if (minigame.magic < minigame.magicM) CM.Main.lastMagicBarFull = false;
|
||||
else if (!CM.Main.lastMagicBarFull) {
|
||||
CM.Main.lastMagicBarFull = true;
|
||||
CM.Disp.Flash(3, 'MagicFlash');
|
||||
CM.Disp.PlaySound(CM.Options.MagicSoundURL, 'MagicSound', 'MagicVolume');
|
||||
CM.Disp.Notification('MagicNotification', 'Magic Meter full', 'Your Magic Meter is full. Cast a spell!');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function checks if any new Wrinklers have popped up
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckWrinklerCount = function () {
|
||||
if (Game.elderWrath > 0) {
|
||||
let CurrentWrinklers = 0;
|
||||
for (const i in Game.wrinklers) {
|
||||
if (Game.wrinklers[i].phase === 2) CurrentWrinklers++;
|
||||
}
|
||||
if (CurrentWrinklers > CM.Main.lastWrinklerCount) {
|
||||
CM.Main.lastWrinklerCount = CurrentWrinklers;
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CM.Options.WrinklerMaxFlash) {
|
||||
CM.Disp.Flash(3, 'WrinklerMaxFlash');
|
||||
} else {
|
||||
CM.Disp.Flash(3, 'WrinklerFlash');
|
||||
}
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CM.Options.WrinklerMaxSound) {
|
||||
CM.Disp.PlaySound(CM.Options.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
|
||||
} else {
|
||||
CM.Disp.PlaySound(CM.Options.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
|
||||
}
|
||||
if (CurrentWrinklers === Game.getWrinklersMax() && CM.Options.WrinklerMaxNotification) {
|
||||
CM.Disp.Notification('WrinklerMaxNotification', 'Maximum Wrinklers Reached', 'You have reached your maximum ammount of wrinklers');
|
||||
} else {
|
||||
CM.Disp.Notification('WrinklerNotification', 'A Wrinkler appeared', 'A new wrinkler has appeared');
|
||||
}
|
||||
} else {
|
||||
CM.Main.lastWrinklerCount = CurrentWrinklers;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler
|
||||
* It is called by CM.Main.DelayInit
|
||||
* As wrinklers are not appended to the DOM we us a different system than for other tooltips
|
||||
*/
|
||||
CM.Main.AddWrinklerAreaDetect = function () {
|
||||
l('backgroundLeftCanvas').onmouseover = function () { CM.Disp.TooltipWrinklerArea = 1; };
|
||||
l('backgroundLeftCanvas').onmouseout = function () {
|
||||
CM.Disp.TooltipWrinklerArea = 0;
|
||||
Game.tooltip.hide();
|
||||
for (const i of Object.keys(Game.wrinklers)) {
|
||||
CM.Disp.TooltipWrinklerBeingShown[i] = 0;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Section: Functions related to the mouse */
|
||||
|
||||
/**
|
||||
* This function fixes Game.mouseY as a result of bars that are added by CookieMonster
|
||||
* It is called by Game.UpdateWrinklers(), Game.UpdateSpecial() and the .onmousover of the BigCookie
|
||||
* before execution of their actual function
|
||||
*/
|
||||
CM.Main.FixMouseY = function (target) {
|
||||
if (CM.Options.TimerBar === 1 && CM.Options.TimerBarPos === 0) {
|
||||
const timerBarHeight = parseInt(CM.Disp.TimerBar.style.height);
|
||||
Game.mouseY -= timerBarHeight;
|
||||
target();
|
||||
Game.mouseY += timerBarHeight;
|
||||
} else {
|
||||
target();
|
||||
}
|
||||
};
|
||||
53
src/Main/ReplaceGameElements/NativeGrimoire.js
Normal file
53
src/Main/ReplaceGameElements/NativeGrimoire.js
Normal file
@@ -0,0 +1,53 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import { FormatTime } from '../../Disp/BeautifyAndFormatting/BeautifyFormatting';
|
||||
|
||||
import CalculateGrimoireRefillTime from '../../Disp/HelperFunctions/CalculateGrimoireRefillTime';
|
||||
import {
|
||||
BackupGrimoireDraw, BackupGrimoireLaunch, BackupGrimoireLaunchMod, HasReplaceNativeGrimoireDraw, HasReplaceNativeGrimoireLaunch,
|
||||
} from '../VariablesAndData';
|
||||
import ReplaceTooltipGrimoire from './TooltipGrimoire';
|
||||
|
||||
/**
|
||||
* This function fixes replaces the .draw function of the Grimoire
|
||||
*/
|
||||
function ReplaceNativeGrimoireDraw() {
|
||||
if (!HasReplaceNativeGrimoireDraw && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
BackupGrimoireDraw = minigame.draw;
|
||||
Game.Objects['Wizard tower'].minigame.draw = function () {
|
||||
BackupGrimoireDraw();
|
||||
if (CMOptions.GrimoireBar === 1 && minigame.magic < minigame.magicM) {
|
||||
minigame.magicBarTextL.innerHTML += ` (${FormatTime(CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, minigame.magicM))})`;
|
||||
}
|
||||
};
|
||||
HasReplaceNativeGrimoireDraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function fixes replaces the .launch function of the Grimoire
|
||||
*/
|
||||
function ReplaceNativeGrimoireLaunch() {
|
||||
if (!HasReplaceNativeGrimoireLaunch && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
const minigame = Game.Objects['Wizard tower'].minigame;
|
||||
BackupGrimoireLaunch = minigame.launch;
|
||||
BackupGrimoireLaunchMod = new Function(`return ${minigame.launch.toString().split('=this').join('= Game.Objects[\'Wizard tower\'].minigame')}`);
|
||||
Game.Objects['Wizard tower'].minigame.launch = function () {
|
||||
BackupGrimoireLaunchMod();
|
||||
ReplaceTooltipGrimoire();
|
||||
HasReplaceNativeGrimoireDraw = false;
|
||||
ReplaceNativeGrimoireDraw();
|
||||
|
||||
HasReplaceNativeGrimoireLaunch = true;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function fixes replaces the Launch and Draw functions of the Grimoire
|
||||
*/
|
||||
export default function ReplaceNativeGrimoire() {
|
||||
ReplaceNativeGrimoireLaunch();
|
||||
ReplaceNativeGrimoireDraw();
|
||||
}
|
||||
20
src/Main/ReplaceGameElements/TooltipGrimoire.js
Normal file
20
src/Main/ReplaceGameElements/TooltipGrimoire.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { CreateTooltip } from '../../Disp/Tooltips/Tooltip';
|
||||
import { TooltipGrimoireBackup } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function replaces the original .onmouseover functions of the Grimoire minigame
|
||||
*/
|
||||
export default function ReplaceTooltipGrimoire() {
|
||||
if (Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
for (const i in Game.Objects['Wizard tower'].minigame.spellsById) {
|
||||
if (l(`grimoireSpell${i}`).onmouseover !== null) {
|
||||
TooltipGrimoireBackup[i] = l(`grimoireSpell${i}`).onmouseover;
|
||||
l(`grimoireSpell${i}`).onmouseover = function () {
|
||||
Game.tooltip.dynamic = 1;
|
||||
Game.tooltip.draw(this, function () { return CreateTooltip('g', `${i}`); }, 'this');
|
||||
Game.tooltip.wobble();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
26
src/Main/ReplaceGameElements/TooltipUpgrades.js
Normal file
26
src/Main/ReplaceGameElements/TooltipUpgrades.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { CreateTooltip } from '../../Disp/Tooltips/Tooltip';
|
||||
import { TooltipUpgradeBackup } from '../VariablesAndData';
|
||||
|
||||
/**
|
||||
* 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 Game.RebuildUpgrades() through CM.Main.ReplaceNative() and is therefore not permanent like the other ReplaceTooltip functions
|
||||
*/
|
||||
export default function ReplaceTooltipUpgrade() {
|
||||
TooltipUpgradeBackup = [];
|
||||
for (const i of Object.keys(Game.UpgradesInStore)) {
|
||||
if (l(`upgrade${i}`).onmouseover !== null) {
|
||||
TooltipUpgradeBackup[i] = l(`upgrade${i}`).onmouseover;
|
||||
l(`upgrade${i}`).onmouseover = function () {
|
||||
if (!Game.mouseDown) {
|
||||
Game.setOnCrate(this);
|
||||
Game.tooltip.dynamic = 1;
|
||||
Game.tooltip.draw(this, function () {
|
||||
return CreateTooltip('u', `${i}`);
|
||||
}, 'store');
|
||||
Game.tooltip.wobble();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
76
src/Main/ReplaceGameElements/Tooltips.js
Normal file
76
src/Main/ReplaceGameElements/Tooltips.js
Normal file
@@ -0,0 +1,76 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
/** Functions related to replacing tooltips */
|
||||
|
||||
import { CreateTooltip } from '../../Disp/Tooltips/Tooltip';
|
||||
import {
|
||||
LoadMinigames, TooltipBuildBackup, TooltipLumpBackup,
|
||||
} from '../VariablesAndData';
|
||||
import ReplaceNativeGrimoire from './NativeGrimoire';
|
||||
import ReplaceTooltipGrimoire from './TooltipGrimoire';
|
||||
|
||||
/**
|
||||
* This function replaces the original .onmouseover functions of buildings
|
||||
*/
|
||||
function ReplaceTooltipBuild() {
|
||||
for (const i of Object.keys(Game.Objects)) {
|
||||
const me = Game.Objects[i];
|
||||
if (l(`product${me.id}`).onmouseover !== null) {
|
||||
TooltipBuildBackup[i] = l(`product${me.id}`).onmouseover;
|
||||
l(`product${me.id}`).onmouseover = function () {
|
||||
Game.tooltip.dynamic = 1;
|
||||
Game.tooltip.draw(this, function () { return CreateTooltip('b', `${i}`); }, 'store');
|
||||
Game.tooltip.wobble();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function replaces the original .onmouseover functions of sugar lumps
|
||||
*/
|
||||
function ReplaceTooltipLump() {
|
||||
if (Game.canLumps()) {
|
||||
TooltipLumpBackup = l('lumps').onmouseover;
|
||||
l('lumps').onmouseover = function () {
|
||||
Game.tooltip.dynamic = 1;
|
||||
Game.tooltip.draw(this, function () { return CreateTooltip('s', 'Lump'); }, 'this');
|
||||
Game.tooltip.wobble();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function replaces the original .onmouseover functions of all garden plants
|
||||
*/
|
||||
function ReplaceTooltipGarden() {
|
||||
if (Game.Objects.Farm.minigameLoaded) {
|
||||
l('gardenTool-1').onmouseover = function () { Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function () { return CreateTooltip('ha', 'HarvestAllButton'); }, 'this'); Game.tooltip.wobble(); };
|
||||
Array.from(l('gardenPlot').children).forEach((child) => {
|
||||
const coords = child.id.slice(-3);
|
||||
child.onmouseover = function () {
|
||||
Game.tooltip.dynamic = 1;
|
||||
Game.tooltip.draw(this, function () { return CreateTooltip('p', [`${coords[0]}`, `${coords[2]}`]); }, 'this');
|
||||
Game.tooltip.wobble();
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function call all functions that replace Game-tooltips with Cookie Monster enhanced tooltips
|
||||
*/
|
||||
export default function ReplaceTooltips() {
|
||||
ReplaceTooltipBuild();
|
||||
ReplaceTooltipLump();
|
||||
|
||||
// Replace Tooltips of Minigames. Nesting it in LoadMinigames makes sure to replace them even if
|
||||
// they were not loaded initially
|
||||
LoadMinigames = Game.LoadMinigames;
|
||||
Game.LoadMinigames = function () {
|
||||
LoadMinigames();
|
||||
ReplaceTooltipGarden();
|
||||
ReplaceTooltipGrimoire();
|
||||
ReplaceNativeGrimoire();
|
||||
};
|
||||
Game.LoadMinigames();
|
||||
}
|
||||
17
src/Main/ReplaceGameFunctions/FixMouse.js
Normal file
17
src/Main/ReplaceGameFunctions/FixMouse.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function fixes Game.mouseY as a result of bars that are added by CookieMonster
|
||||
* It is called by Game.UpdateWrinklers(), Game.UpdateSpecial() and the .onmousover of the BigCookie
|
||||
* before execution of their actual function
|
||||
*/
|
||||
export default function FixMouseY(target) {
|
||||
if (CMOptions.TimerBar === 1 && CMOptions.TimerBarPos === 0) {
|
||||
const timerBarHeight = parseInt(l('CMTimerBar').style.height, 10);
|
||||
Game.mouseY -= timerBarHeight;
|
||||
target();
|
||||
Game.mouseY += timerBarHeight;
|
||||
} else {
|
||||
target();
|
||||
}
|
||||
}
|
||||
126
src/Main/ReplaceGameFunctions/ReplaceNative.js
Normal file
126
src/Main/ReplaceGameFunctions/ReplaceNative.js
Normal file
@@ -0,0 +1,126 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import jscolor from '@eastdesire/jscolor';
|
||||
import { CacheHCPerSecond, CacheTimeTillNextPrestige } from '../../Cache/VariablesAndData';
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
import { Beautify as CMBeautify, FormatTime } from '../../Disp/BeautifyAndFormatting/BeautifyFormatting';
|
||||
import { AddAuraInfo, AddDragonLevelUpTooltip } from '../../Disp/Dragon/Dragon';
|
||||
import AddMenu from '../../Disp/MenuSections/AddMenus';
|
||||
import UpdateTitle from '../../Disp/TabTitle/TabTitle';
|
||||
import UpdateTooltipLocation from '../../Disp/Tooltips/PositionLocation';
|
||||
import { CMSayTime, Title } from '../../Disp/VariablesAndData';
|
||||
import { SimDateAges, SimDateCentury, SimDoSims } from '../../Sim/VariablesAndData';
|
||||
import ReplaceTooltipUpgrade from '../ReplaceGameElements/TooltipUpgrades';
|
||||
import { BackupFunctions } from '../VariablesAndData';
|
||||
import FixMouseY from './FixMouse';
|
||||
|
||||
/**
|
||||
* This function replaces certain native (from the base-game) functions
|
||||
*/
|
||||
export default function ReplaceNative() {
|
||||
// eslint-disable-next-line no-undef
|
||||
BackupFunctions.Beautify = Beautify;
|
||||
// eslint-disable-next-line no-undef
|
||||
Beautify = CMBeautify;
|
||||
|
||||
BackupFunctions.CalculateGains = Game.CalculateGains;
|
||||
Game.CalculateGains = function () {
|
||||
BackupFunctions.CalculateGains();
|
||||
SimDoSims = 1;
|
||||
SimDateAges = Date.now();
|
||||
SimDateCentury = Date.now();
|
||||
};
|
||||
|
||||
BackupFunctions.tooltip = {};
|
||||
BackupFunctions.tooltip.draw = Game.tooltip.draw;
|
||||
BackupFunctions.tooltip.drawMod = new Function(`return ${Game.tooltip.draw.toString().split('this').join('Game.tooltip')}`)();
|
||||
Game.tooltip.draw = function (from, text, origin) {
|
||||
BackupFunctions.tooltip.drawMod(from, text, origin);
|
||||
};
|
||||
|
||||
BackupFunctions.tooltip.update = Game.tooltip.update;
|
||||
BackupFunctions.tooltip.updateMod = new Function(`return ${Game.tooltip.update.toString().split('this.').join('Game.tooltip.')}`)();
|
||||
Game.tooltip.update = function () {
|
||||
BackupFunctions.tooltip.updateMod();
|
||||
UpdateTooltipLocation();
|
||||
};
|
||||
|
||||
BackupFunctions.UpdateWrinklers = Game.UpdateWrinklers;
|
||||
Game.UpdateWrinklers = function () {
|
||||
FixMouseY(BackupFunctions.UpdateWrinklers);
|
||||
};
|
||||
|
||||
BackupFunctions.UpdateSpecial = Game.UpdateSpecial;
|
||||
Game.UpdateSpecial = function () {
|
||||
FixMouseY(BackupFunctions.UpdateSpecial);
|
||||
};
|
||||
|
||||
// Assumes newer browsers
|
||||
l('bigCookie').removeEventListener('click', Game.ClickCookie, false);
|
||||
l('bigCookie').addEventListener('click', function () { FixMouseY(Game.ClickCookie); }, false);
|
||||
|
||||
BackupFunctions.RebuildUpgrades = Game.RebuildUpgrades;
|
||||
Game.RebuildUpgrades = function () {
|
||||
BackupFunctions.RebuildUpgrades();
|
||||
ReplaceTooltipUpgrade();
|
||||
Game.CalculateGains();
|
||||
};
|
||||
|
||||
BackupFunctions.ClickProduct = Game.ClickProduct;
|
||||
/**
|
||||
* This function adds a check to the purchase of a building to allow BulkBuyBlock to work.
|
||||
* If the options is 1 (on) bulkPrice is under cookies you can't buy the building.
|
||||
*/
|
||||
Game.ClickProduct = function (what) {
|
||||
if (!CMOptions.BulkBuyBlock || (Game.ObjectsById[what].bulkPrice < Game.cookies || Game.buyMode === -1)) {
|
||||
BackupFunctions.ClickProduct(what);
|
||||
}
|
||||
};
|
||||
|
||||
BackupFunctions.DescribeDragonAura = Game.DescribeDragonAura;
|
||||
/**
|
||||
* This function adds the function CM.Disp.AddAuraInfo() to Game.DescribeDragonAura()
|
||||
* This adds information about CPS differences and costs to the aura choosing interface
|
||||
* @param {number} aura The number of the aura currently selected by the mouse/user
|
||||
*/
|
||||
Game.DescribeDragonAura = function (aura) {
|
||||
BackupFunctions.DescribeDragonAura(aura);
|
||||
AddAuraInfo(aura);
|
||||
};
|
||||
|
||||
BackupFunctions.ToggleSpecialMenu = Game.ToggleSpecialMenu;
|
||||
/**
|
||||
* This function adds the code to display the tooltips for the levelUp button of the dragon
|
||||
*/
|
||||
Game.ToggleSpecialMenu = function (on) {
|
||||
BackupFunctions.ToggleSpecialMenu(on);
|
||||
AddDragonLevelUpTooltip();
|
||||
};
|
||||
|
||||
BackupFunctions.UpdateMenu = Game.UpdateMenu;
|
||||
Game.UpdateMenu = function () {
|
||||
if (typeof jscolor.picker === 'undefined' || typeof jscolor.picker.owner === 'undefined') {
|
||||
BackupFunctions.UpdateMenu();
|
||||
AddMenu();
|
||||
}
|
||||
};
|
||||
|
||||
BackupFunctions.sayTime = Game.sayTime;
|
||||
CMSayTime = function (time, detail) {
|
||||
if (Number.isNaN(time) || time <= 0) return BackupFunctions.sayTime(time, detail);
|
||||
return FormatTime(time / Game.fps, 1);
|
||||
};
|
||||
|
||||
BackupFunctions.Logic = Game.Logic;
|
||||
Game.Logic = function () {
|
||||
BackupFunctions.Logic();
|
||||
|
||||
// Update tab title
|
||||
let title = 'Cookie Clicker';
|
||||
if (Game.season === 'fools') title = 'Cookie Baker';
|
||||
Title = `${(Game.OnAscend ? 'Ascending! ' : '')}${CMBeautify(Game.cookies)} ${(Game.cookies === 1 ? 'cookie' : 'cookies')} - ${title}`;
|
||||
UpdateTitle();
|
||||
|
||||
// Since the Ascend Tooltip is not actually a tooltip we need to add our additional info here...
|
||||
l('ascendTooltip').innerHTML += `${CMOptions.TooltipAscendButton ? `<div class='line'></div>It takes ${CacheTimeTillNextPrestige} to reach the next level and you are making ${CMBeautify(CacheHCPerSecond, 2)} chips on average in the last 5 seconds.<br>` : ''}`;
|
||||
};
|
||||
}
|
||||
23
src/Main/VariablesAndData.js
Normal file
23
src/Main/VariablesAndData.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/* eslint-disable prefer-const */
|
||||
|
||||
export let LastModCount;
|
||||
export let TooltipBuildBackup = [];
|
||||
export let TooltipLumpBackup;
|
||||
export let TooltipGrimoireBackup = [];
|
||||
export let TooltipUpgradeBackup = [];
|
||||
export let BackupGrimoireLaunch;
|
||||
export let BackupGrimoireLaunchMod;
|
||||
export let BackupGrimoireDraw;
|
||||
export let HasReplaceNativeGrimoireLaunch;
|
||||
export let HasReplaceNativeGrimoireDraw;
|
||||
export let LoadMinigames;
|
||||
export let BackupFunctions = {};
|
||||
|
||||
export let LastSeasonPopupState;
|
||||
export let LastTickerFortuneState;
|
||||
export let LastGardenNextStep;
|
||||
export let LastGoldenCookieState;
|
||||
export let LastSpawnedGoldenCookieState;
|
||||
export let LastMagicBarFull;
|
||||
export let CurrSpawnedGoldenCookieState;
|
||||
export let LastWrinklerCount;
|
||||
17
src/Main/WrinklerArea/AddDetectArea.js
Normal file
17
src/Main/WrinklerArea/AddDetectArea.js
Normal file
@@ -0,0 +1,17 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
import { TooltipWrinklerArea, TooltipWrinklerBeingShown } from '../../Disp/VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function creates .onmouseover/out events that determine if the mouse is hovering-over a Wrinkler
|
||||
* As wrinklers are not appended to the DOM we us a different system than for other tooltips
|
||||
*/
|
||||
export default function AddWrinklerAreaDetect() {
|
||||
l('backgroundLeftCanvas').onmouseover = function () { TooltipWrinklerArea = 1; };
|
||||
l('backgroundLeftCanvas').onmouseout = function () {
|
||||
TooltipWrinklerArea = 0;
|
||||
Game.tooltip.hide();
|
||||
for (const i of Object.keys(Game.wrinklers)) {
|
||||
TooltipWrinklerBeingShown[i] = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user