Finished annotation of Main.js #556
This commit is contained in:
File diff suppressed because one or more lines are too long
31
src/Cache.js
31
src/Cache.js
@@ -8,8 +8,8 @@
|
||||
/**
|
||||
* This functions runs all cache-functions to generate all "full" cache
|
||||
* The declaration follows the structure of the CM.Cache.js file
|
||||
* It is called by CM.DelayInit
|
||||
* TODO: Add all functions that should be here and remove them from CM.Loop()
|
||||
* It is called by CM.Main.DelayInit
|
||||
* TODO: Add all functions that should be here and remove them from CM.Main.Loop()
|
||||
*/
|
||||
CM.Cache.InitCache = function() {
|
||||
CM.Cache.CacheDragonAuras();
|
||||
@@ -19,6 +19,7 @@ CM.Cache.InitCache = function() {
|
||||
CM.Cache.CacheChain();
|
||||
CM.Cache.CacheMissingUpgrades();
|
||||
CM.Cache.CacheSeaSpec();
|
||||
CM.Cache.InitCookiesDiff();
|
||||
CM.Cache.CacheAvgCPS();
|
||||
CM.Cache.CacheIncome();
|
||||
CM.Cache.CacheBuildingsPrices();
|
||||
@@ -45,7 +46,7 @@ CM.Cache.CacheDragonAuras = function() {
|
||||
|
||||
/**
|
||||
* This functions caches data related to Wrinklers
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
* @global {number} CM.Cache.WrinklersTotal The cookies of all wrinklers
|
||||
* @global {number} CM.Cache.WrinklersNormal The cookies of all normal wrinklers
|
||||
* @global {[{number}, {number}]} CM.Cache.WrinklersFattest A list containing the cookies and the id of the fattest non-shiny wrinkler
|
||||
@@ -80,7 +81,7 @@ CM.Cache.CacheWrinklers = function() {
|
||||
|
||||
/**
|
||||
* This functions caches variables related to the stats apge
|
||||
* It is called by CM.Loop() upon changes to cps and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() upon changes to cps and CM.Cache.InitCache()
|
||||
* @global {number} CM.Cache.Lucky Cookies required for max Lucky
|
||||
* @global {number} CM.Cache.LuckyReward Reward for max normal Lucky
|
||||
* @global {number} CM.Cache.LuckyWrathReward Reward for max normal Lucky from Wrath cookie
|
||||
@@ -190,7 +191,7 @@ CM.Cache.MaxChainMoni = function(digit, maxPayout, mult) {
|
||||
|
||||
/**
|
||||
* This functions caches data related to Chain Cookies reward from Golden Cookioes
|
||||
* It is called by CM.Loop() upon changes to cps and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() upon changes to cps and CM.Cache.InitCache()
|
||||
* @global [{number, number}] CM.Cache.ChainReward Total cookies earned, and cookies needed for next level for normal chain
|
||||
* @global {number} CM.Cache.ChainRequired Cookies needed for maximum reward for normal chain
|
||||
* @global {number} CM.Cache.ChainRequiredNext Total cookies needed for next level for normal chain
|
||||
@@ -231,7 +232,7 @@ CM.Cache.CacheChain = function() {
|
||||
|
||||
/**
|
||||
* This functions caches variables related to missing upgrades
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
* @global {string} CM.Cache.MissingUpgrades String containig the HTML to create the "crates" for missing normal upgrades
|
||||
* @global {string} CM.Cache.MissingUpgradesCookies String containig the HTML to create the "crates" for missing cookie upgrades
|
||||
* @global {string} CM.Cache.MissingUpgradesPrestige String containig the HTML to create the "crates" for missing prestige upgrades
|
||||
@@ -268,7 +269,7 @@ CM.Cache.CacheMissingUpgrades = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the reward of popping a reindeer
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
* @global {number} CM.Cache.SeaSpec The reward for popping a reindeer
|
||||
*/
|
||||
CM.Cache.CacheSeaSpec = function() {
|
||||
@@ -318,7 +319,7 @@ class CMAvgQueue {
|
||||
|
||||
/**
|
||||
* This functions caches creates the CMAvgQueue used by CM.Cache.CacheAvgCPS() to calculate CPS
|
||||
* Called by CM.DelayInit()
|
||||
* Called by CM.Cache.InitCache()
|
||||
*/
|
||||
CM.Cache.InitCookiesDiff = function() {
|
||||
CM.Cache.CookiesDiff = new CMAvgQueue(CM.Disp.cookieTimes[CM.Disp.cookieTimes.length - 1]);
|
||||
@@ -330,7 +331,7 @@ CM.Cache.InitCookiesDiff = function() {
|
||||
|
||||
/**
|
||||
* This functions caches two variables related average CPS and Clicks
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
* TODO: Check if this can be made more concise
|
||||
* @global {number} CM.Cache.RealCookiesEarned Cookies earned including the Chocolate Egg
|
||||
* @global {number} CM.Cache.AvgCPS Average cookies over time-period as defined by AvgCPSHist
|
||||
@@ -394,7 +395,7 @@ CM.Cache.CacheAvgCPS = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the reward for selling the Chocolate egg
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
* @global {number} CM.Cache.SellForChoEgg Total cookies to be gained from selling Chocolate egg
|
||||
*/
|
||||
CM.Cache.CacheSellForChoEgg = function() {
|
||||
@@ -416,7 +417,7 @@ CM.Cache.CacheSellForChoEgg = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the current Wrinkler CPS multiplier
|
||||
* It is called by CM.Loop(). Variables are mostly used by CM.Disp.GetCPS().
|
||||
* It is called by CM.Main.Loop(). Variables are mostly used by CM.Disp.GetCPS().
|
||||
* @global {number} CM.Cache.CurrWrinklerCount Current number of wrinklers
|
||||
* @global {number} CM.Cache.CurrWrinklerCPSMult Current multiplier of CPS because of wrinklers (excluding their negative sucking effect)
|
||||
*/
|
||||
@@ -442,7 +443,7 @@ CM.Cache.CacheCurrWrinklerCPS = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the current cost of upgrading the dragon level so it can be displayed in the tooltip
|
||||
* It is called by the relevan tooltip-code as a result of CM.Disp.AddDragonLevelUpTooltip() and by CM.Loop()
|
||||
* It is called by the relevan tooltip-code as a result of CM.Disp.AddDragonLevelUpTooltip() and by CM.Main.Loop()
|
||||
* @global {number} CM.Cache.lastDragonLevel The last cached dragon level
|
||||
* @global {string} CM.Cache.CostDragonUpgrade The Beautified cost of the next upgrade
|
||||
*/
|
||||
@@ -500,7 +501,7 @@ CM.Cache.CacheDragonCost = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the income gain of each building and upgrade and stores it in the cache
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
*/
|
||||
CM.Cache.CacheIncome = function() {
|
||||
// Simulate Building Buys for 1, 10 and 100 amount
|
||||
@@ -517,7 +518,7 @@ CM.Cache.CacheIncome = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the price of each building and stores it in the cache
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
*/
|
||||
CM.Cache.CacheBuildingsPrices = function() {
|
||||
for (let i of Object.keys(Game.Objects)) {
|
||||
@@ -532,7 +533,7 @@ CM.Cache.CacheBuildingsPrices = function() {
|
||||
|
||||
/**
|
||||
* This functions caches the PP of each building and upgrade and stores it in the cache
|
||||
* It is called by CM.Loop() and CM.Cache.InitCache()
|
||||
* It is called by CM.Main.Loop() and CM.Cache.InitCache()
|
||||
*/
|
||||
CM.Cache.CachePP = function() {
|
||||
CM.Cache.CacheBuildingsPP();
|
||||
|
||||
@@ -22,7 +22,7 @@ CM.Config.SaveConfig = function() {
|
||||
|
||||
/**
|
||||
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
||||
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
||||
* It is called by CM.Main.DelayInit() and CM.Config.RestoreDefault()
|
||||
*/
|
||||
CM.Config.LoadConfig = function(settings) {
|
||||
// This removes cookies left from earlier versions of CookieMonster
|
||||
@@ -71,7 +71,7 @@ CM.Config.LoadConfig = function(settings) {
|
||||
}
|
||||
}
|
||||
if (mod) CM.Config.SaveConfig();
|
||||
CM.Loop(); // Do loop once
|
||||
CM.Main.Loop(); // Do loop once
|
||||
for (let i in CM.Data.ConfigDefault) {
|
||||
if (i != 'Header' && typeof CM.ConfigData[i].func !== 'undefined') {
|
||||
CM.ConfigData[i].func();
|
||||
|
||||
49
src/Disp.js
49
src/Disp.js
@@ -257,7 +257,7 @@ CM.Disp.Beautify = function(num, floats, forced) {
|
||||
|
||||
/**
|
||||
* This function disables and shows the bars created by CookieMonster when the game is "ascending"
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
*/
|
||||
CM.Disp.UpdateAscendState = function() {
|
||||
if (Game.OnAscend) {
|
||||
@@ -274,7 +274,7 @@ CM.Disp.UpdateAscendState = function() {
|
||||
|
||||
/**
|
||||
* This function creates a CSS style that stores certain standard CSS classes used by CookieMonster
|
||||
* It is called by CM.DelayInit()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Disp.CreateCssArea = function() {
|
||||
CM.Disp.Css = document.createElement('style');
|
||||
@@ -353,7 +353,7 @@ CM.Disp.ToggleBotBar = function() {
|
||||
|
||||
/**
|
||||
* This function creates the bottom bar and appends it to l('wrapper')
|
||||
* It is called by CM.DelayInit and a change in CM.Options.BotBar
|
||||
* It is called by CM.Main.DelayInit and a change in CM.Options.BotBar
|
||||
*/
|
||||
CM.Disp.CreateBotBar = function() {
|
||||
CM.Disp.BotBar = document.createElement('div');
|
||||
@@ -404,7 +404,7 @@ CM.Disp.CreateBotBar = function() {
|
||||
|
||||
/**
|
||||
* This function updates the bonus-, pp-, and time-rows in the the bottom bar
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
*/
|
||||
CM.Disp.UpdateBotBar = function() {
|
||||
if (CM.Options.BotBar === 1 && CM.Cache.Objects1) {
|
||||
@@ -461,7 +461,7 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
|
||||
|
||||
/**
|
||||
* This function creates the TimerBar and appends it to l('wrapper')
|
||||
* It is called by CM.DelayInit()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Disp.CreateTimerBar = function() {
|
||||
CM.Disp.TimerBar = document.createElement('div');
|
||||
@@ -495,7 +495,7 @@ CM.Disp.CreateTimerBar = function() {
|
||||
|
||||
/**
|
||||
* This function creates an indivudual timer for the timer bar
|
||||
* It is called by CM.DelayInit()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
* @param {string} id An id to identify the timer
|
||||
* @param {string} name The title of the timer
|
||||
* @param [{{string}, {string}}, ...] bars ([id, color]) The id and colours of individual parts of the timer
|
||||
@@ -557,7 +557,7 @@ CM.Disp.TimerBarCreateBar = function(id, name, bars) {
|
||||
|
||||
/**
|
||||
* This function updates indivudual timers in the timer bar
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
*/
|
||||
CM.Disp.UpdateTimerBar = function() {
|
||||
if (CM.Options.TimerBar === 1) {
|
||||
@@ -711,7 +711,7 @@ CM.Disp.UpdateBotTimerBarPosition = function() {
|
||||
/**
|
||||
* This function adjusts some things in the column of buildings.
|
||||
* It colours them, helps display the correct sell-price and shuffles the order when CM.Options.SortBuildings is set
|
||||
* The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale()
|
||||
* The function is called by CM.Main.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale()
|
||||
* And by changes in CM.Options.BuildColor, CM.Options.SortBuild & CM.ConfigData.BulkBuildColor
|
||||
*/
|
||||
CM.Disp.UpdateBuildings = function() {
|
||||
@@ -778,7 +778,7 @@ CM.Disp.UpdateBuildings = function() {
|
||||
/**
|
||||
* This function adjusts some things in the upgrades section
|
||||
* It colours them and shuffles the order when CM.Options.SortBuildings is set
|
||||
* The function is called by CM.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale()
|
||||
* The function is called by CM.Main.Loop(), CM.Disp.ToggleUpgradeBarAndColor & CM.Disp.RefreshScale()
|
||||
* And by changes in CM.Options.SortUpgrades
|
||||
*/
|
||||
CM.Disp.UpdateUpgrades = function() {
|
||||
@@ -971,7 +971,7 @@ CM.Disp.CreateUpgradeBarLegend = function() {
|
||||
|
||||
/**
|
||||
* This function creates a white square over the full screen and appends it to l('wrapper')
|
||||
* It is used by CM.Disp.Flash() to create the effect of a flash and called by CM.DelayInit()
|
||||
* It is used by CM.Disp.Flash() to create the effect of a flash and called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Disp.CreateWhiteScreen = function() {
|
||||
CM.Disp.WhiteScreen = document.createElement('div');
|
||||
@@ -1047,7 +1047,7 @@ CM.Disp.Notification = function(notifyConfig, title, message) {
|
||||
* Section: Functions related to updating the tab in the browser's tab-bar
|
||||
|
||||
/**
|
||||
* This function creates the Favicon, it is called by CM.DelayInit()
|
||||
* This function creates the Favicon, it is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Disp.CreateFavicon = function() {
|
||||
CM.Disp.Favicon = document.createElement('link');
|
||||
@@ -1193,7 +1193,7 @@ CM.Disp.ToggleGCTimer = function() {
|
||||
/**
|
||||
* This function creates some very basic tooltips, (e.g., the tooltips in the stats page)
|
||||
* The tooltips are created with CM.Disp[placeholder].appendChild(desc)
|
||||
* It is called by CM.DelayInit()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
* @param {string} placeholder The name used to later refer and spawn the tooltip
|
||||
* @param {string} text The text of the tooltip
|
||||
* @param {string} minWidth The minimum width of the tooltip
|
||||
@@ -1213,7 +1213,7 @@ CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) {
|
||||
/**
|
||||
* 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.ReplaceNative() and is therefore not permanent like the other ReplaceTooltip functions
|
||||
* It is called by Game.RebuildUpgrades() through CM.Main.ReplaceNative() and is therefore not permanent like the other ReplaceTooltip functions
|
||||
*/
|
||||
CM.Disp.ReplaceTooltipUpgrade = function() {
|
||||
CM.Disp.TooltipUpgradeBackup = [];
|
||||
@@ -1409,7 +1409,7 @@ CM.Disp.TooltipCreateWarningSection = function() {
|
||||
|
||||
/**
|
||||
* This function updates the sections of the tooltips created by CookieMonster
|
||||
* It is called when tooltips are created by and CM.Disp.Tooltip() on every loop by CM.Loop()
|
||||
* It is called when tooltips are created by and CM.Disp.Tooltip() on every loop by CM.Main.Loop()
|
||||
*/
|
||||
CM.Disp.UpdateTooltip = function() {
|
||||
CM.Sim.CopyData();
|
||||
@@ -1778,7 +1778,7 @@ CM.Disp.UpdateTooltipWarnings = function() {
|
||||
|
||||
/**
|
||||
* This function updates the location of the tooltip
|
||||
* It is called by Game.tooltip.update() because of CM.ReplaceNative()
|
||||
* It is called by Game.tooltip.update() because of CM.Main.ReplaceNative()
|
||||
*/
|
||||
CM.Disp.UpdateTooltipLocation = function() {
|
||||
if (Game.tooltip.origin === 'store') {
|
||||
@@ -1816,7 +1816,7 @@ CM.Disp.ToggleToolWarnPos = function() {
|
||||
|
||||
/**
|
||||
* This function checks and create a tooltip for the wrinklers
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
* TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w")
|
||||
*/
|
||||
CM.Disp.CheckWrinklerTooltip = function() {
|
||||
@@ -1854,7 +1854,7 @@ CM.Disp.CheckWrinklerTooltip = function() {
|
||||
|
||||
/**
|
||||
* This function updates the amount to be displayed by the wrinkler tooltip created by CM.Disp.CheckWrinklerTooltip()
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
* TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip()
|
||||
*/
|
||||
CM.Disp.UpdateWrinklerTooltip = function() {
|
||||
@@ -1880,7 +1880,7 @@ CM.Disp.UpdateWrinklerTooltip = function() {
|
||||
|
||||
/**
|
||||
* This functions adds the two extra lines about CPS and time to recover to the aura picker infoscreen
|
||||
* It is called by Game.DescribeDragonAura() after CM.ReplaceNative()
|
||||
* It is called by Game.DescribeDragonAura() after CM.Main.ReplaceNative()
|
||||
* @param {number} aura The number of the aura currently selected by the mouse/user
|
||||
*/
|
||||
CM.Disp.AddAuraInfo = function(aura) {
|
||||
@@ -1908,7 +1908,7 @@ CM.Disp.AddAuraInfo = function(aura) {
|
||||
|
||||
/**
|
||||
* This functions adds a tooltip to the level up button displaying the cost of rebuying all
|
||||
* It is called by Game.ToggleSpecialMenu() after CM.ReplaceNative()
|
||||
* It is called by Game.ToggleSpecialMenu() after CM.Main.ReplaceNative()
|
||||
*/
|
||||
CM.Disp.AddDragonLevelUpTooltip = function() {
|
||||
// Check if it is the dragon popup that is on screen
|
||||
@@ -1949,7 +1949,7 @@ CM.Disp.AddMenu = function() {
|
||||
|
||||
/**
|
||||
* This function refreshes the stats page, CM.Options.UpStats determines the rate at which that happens
|
||||
* It is called by CM.Loop()
|
||||
* It is called by CM.Main.Loop()
|
||||
*/
|
||||
CM.Disp.RefreshMenu = function() {
|
||||
if (CM.Options.UpStats && Game.onMenu === 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps === 0) Game.UpdateMenu();
|
||||
@@ -2831,7 +2831,7 @@ CM.Disp.crateMissing = function(me) {
|
||||
|
||||
/**
|
||||
* This function creates two objects at the bottom of the left column that allowing popping of wrinklers
|
||||
* It is called by CM.DelayInit()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Disp.CreateWrinklerButtons = function() {
|
||||
var popAllA = document.createElement('a');
|
||||
@@ -2868,7 +2868,7 @@ CM.Disp.UpdateWrinklerButtons = function() {
|
||||
|
||||
/**
|
||||
* This list is used to make some very basic tooltips.
|
||||
* It is used by CM.DelayInit() in the call of CM.Disp.CreateSimpleTooltip()
|
||||
* It is used by CM.Main.DelayInit() in the call of CM.Disp.CreateSimpleTooltip()
|
||||
* @item {string} placeholder
|
||||
* @item {string} text
|
||||
* @item {string} minWidth
|
||||
@@ -2909,8 +2909,11 @@ CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM
|
||||
* This array is used to give certain timers specific colours
|
||||
*/
|
||||
CM.Disp.buffColors = {'Frenzy': CM.Disp.colorYellow, 'Dragon Harvest': CM.Disp.colorBrown, 'Elder frenzy': CM.Disp.colorGreen, 'Clot': CM.Disp.colorRed, 'Click frenzy': CM.Disp.colorBlue, 'Dragonflight': CM.Disp.colorPink};
|
||||
|
||||
/**
|
||||
* This array is used to track GC timers
|
||||
*/
|
||||
CM.Disp.GCTimers = {};
|
||||
CM.Disp.lastAscendState = -1;
|
||||
|
||||
/**
|
||||
* These lists are used in the stats page to show
|
||||
|
||||
@@ -18,9 +18,9 @@ CM.init = function() {
|
||||
proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?');
|
||||
}
|
||||
if (proceed) {
|
||||
CM.DelayInit();
|
||||
CM.Main.DelayInit();
|
||||
Game.registerHook('draw', CM.Disp.Draw);
|
||||
Game.registerHook('logic', CM.Loop);
|
||||
Game.registerHook('logic', CM.Main.Loop);
|
||||
CM.Footer.isInitzializing = false
|
||||
}
|
||||
};
|
||||
|
||||
268
src/Main.js
268
src/Main.js
@@ -2,7 +2,124 @@
|
||||
* Main *
|
||||
********/
|
||||
|
||||
CM.ReplaceNative = function() {
|
||||
/********
|
||||
* 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) {
|
||||
// CM.Sim.DoSims is set whenever CPS has changed
|
||||
if (CM.Sim.DoSims) {
|
||||
CM.Cache.CacheIncome();
|
||||
|
||||
CM.Sim.NoGoldSwitchCookiesPS(); // 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
|
||||
var 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;
|
||||
}
|
||||
|
||||
// Update Wrinkler Bank
|
||||
CM.Cache.CacheWrinklers();
|
||||
|
||||
// Calculate PP
|
||||
CM.Cache.CachePP();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// Cache average CPS
|
||||
CM.Cache.CacheCurrWrinklerCPS();
|
||||
CM.Cache.CacheAvgCPS();
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialization loop of Cookie Monster
|
||||
* Called by CM.init()
|
||||
*/
|
||||
CM.Main.DelayInit = function() {
|
||||
CM.Sim.InitData();
|
||||
CM.Cache.InitCache();
|
||||
|
||||
// Creating visual elements
|
||||
CM.Disp.CreateCssArea();
|
||||
CM.Disp.CreateBotBar();
|
||||
CM.Disp.CreateTimerBar();
|
||||
CM.Disp.CreateUpgradeBar();
|
||||
CM.Disp.CreateWhiteScreen();
|
||||
CM.Disp.CreateFavicon();
|
||||
for (let 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.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);
|
||||
|
||||
// TODO: given the architecture of your code, you probably want these lines somewhere else,
|
||||
// but I stuck them here for convenience
|
||||
l("products").style.display = "grid";
|
||||
l("storeBulk").style.gridRow = "1/1";
|
||||
|
||||
l("upgrades").style.display = "flex";
|
||||
l("upgrades").style["flex-wrap"] = "wrap";
|
||||
|
||||
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;
|
||||
|
||||
@@ -48,11 +165,11 @@ CM.ReplaceNative = function() {
|
||||
Game.CalculateGains();
|
||||
};
|
||||
|
||||
CM.Backup.ClickProduct = Game.ClickProduct;
|
||||
/**
|
||||
* This optiond adds a check to the purchase of a building to allow BulkBuyBlock to work.
|
||||
* 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.
|
||||
*/
|
||||
CM.Backup.ClickProduct = Game.ClickProduct;
|
||||
Game.ClickProduct = function(what) {
|
||||
if (!CM.Options.BulkBuyBlock || Game.ObjectsById[what].bulkPrice < Game.cookies) {
|
||||
CM.Backup.ClickProduct(what);
|
||||
@@ -61,7 +178,7 @@ CM.ReplaceNative = function() {
|
||||
|
||||
CM.Backup.DescribeDragonAura = Game.DescribeDragonAura;
|
||||
/**
|
||||
* This functions adds the function CM.Disp.AddAuraInfo() to 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
|
||||
*/
|
||||
@@ -72,7 +189,7 @@ CM.ReplaceNative = function() {
|
||||
|
||||
CM.Backup.ToggleSpecialMenu = Game.ToggleSpecialMenu;
|
||||
/**
|
||||
* This functions adds the code to display the tooltips for the levelUp button of the dragon
|
||||
* This function adds the code to display the tooltips for the levelUp button of the dragon
|
||||
*/
|
||||
Game.ToggleSpecialMenu = function(on) {
|
||||
CM.Backup.ToggleSpecialMenu(on);
|
||||
@@ -97,18 +214,25 @@ CM.ReplaceNative = function() {
|
||||
eval('CM.Backup.LogicMod = ' + Game.Logic.toString().split('document.title').join('CM.Disp.Title'));
|
||||
Game.Logic = function() {
|
||||
CM.Backup.LogicMod();
|
||||
|
||||
// Update Title
|
||||
CM.Disp.UpdateTitle();
|
||||
};
|
||||
};
|
||||
|
||||
CM.ReplaceNativeGrimoire = function() {
|
||||
CM.ReplaceNativeGrimoireLaunch();
|
||||
CM.ReplaceNativeGrimoireDraw();
|
||||
/**
|
||||
* 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();
|
||||
};
|
||||
|
||||
CM.ReplaceNativeGrimoireLaunch = function() {
|
||||
/**
|
||||
* This function fixes replaces the .launch function of the Grimoire
|
||||
* It is called by CM.Main.ReplaceNativeGrimoire()
|
||||
*/
|
||||
CM.Main.ReplaceNativeGrimoireLaunch = function() {
|
||||
if (!CM.HasReplaceNativeGrimoireLaunch && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
var minigame = Game.Objects['Wizard tower'].minigame;
|
||||
CM.Backup.GrimoireLaunch = minigame.launch;
|
||||
@@ -117,13 +241,17 @@ CM.ReplaceNativeGrimoireLaunch = function() {
|
||||
CM.Backup.GrimoireLaunchMod();
|
||||
CM.Main.ReplaceTooltipGrimoire();
|
||||
CM.HasReplaceNativeGrimoireDraw = false;
|
||||
CM.ReplaceNativeGrimoireDraw();
|
||||
CM.Main.ReplaceNativeGrimoireDraw();
|
||||
};
|
||||
CM.HasReplaceNativeGrimoireLaunch = true;
|
||||
}
|
||||
};
|
||||
|
||||
CM.ReplaceNativeGrimoireDraw = function() {
|
||||
/**
|
||||
* This function fixes replaces the .draw function of the Grimoire
|
||||
* It is called by CM.Main.ReplaceNativeGrimoire()
|
||||
*/
|
||||
CM.Main.ReplaceNativeGrimoireDraw = function() {
|
||||
if (!CM.HasReplaceNativeGrimoireDraw && Game.Objects['Wizard tower'].minigameLoaded) {
|
||||
var minigame = Game.Objects['Wizard tower'].minigame;
|
||||
CM.Backup.GrimoireDraw = minigame.draw;
|
||||
@@ -137,110 +265,12 @@ CM.ReplaceNativeGrimoireDraw = function() {
|
||||
}
|
||||
};
|
||||
|
||||
CM.Loop = function() {
|
||||
if (CM.Disp.lastAscendState != Game.OnAscend) {
|
||||
CM.Disp.lastAscendState = Game.OnAscend;
|
||||
CM.Disp.UpdateAscendState();
|
||||
}
|
||||
if (!Game.OnAscend && Game.AscendTimer === 0) {
|
||||
// CM.Sim.DoSims is set whenever CPS has changed
|
||||
if (CM.Sim.DoSims) {
|
||||
CM.Cache.CacheIncome();
|
||||
|
||||
CM.Sim.NoGoldSwitchCookiesPS(); // 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
|
||||
var 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;
|
||||
}
|
||||
|
||||
// Update Wrinkler Bank
|
||||
CM.Cache.CacheWrinklers();
|
||||
|
||||
// Calculate PP
|
||||
CM.Cache.CachePP();
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
||||
// Update Average CPS (might need to move)
|
||||
CM.Cache.CacheCurrWrinklerCPS();
|
||||
CM.Cache.CacheAvgCPS();
|
||||
};
|
||||
|
||||
CM.DelayInit = function() {
|
||||
CM.Sim.InitData();
|
||||
CM.Cache.InitCache();
|
||||
CM.Disp.CreateCssArea();
|
||||
CM.Disp.CreateBotBar();
|
||||
CM.Disp.CreateTimerBar();
|
||||
CM.Disp.CreateUpgradeBar();
|
||||
CM.Disp.CreateWhiteScreen();
|
||||
CM.Disp.CreateFavicon();
|
||||
for (let 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.Main.ReplaceTooltips();
|
||||
CM.Main.AddWrinklerAreaDetect();
|
||||
CM.Cache.InitCookiesDiff();
|
||||
CM.ReplaceNative();
|
||||
CM.ReplaceNativeGrimoire();
|
||||
Game.CalculateGains();
|
||||
CM.Config.LoadConfig(); // Must be after all things are created!
|
||||
CM.Disp.lastAscendState = Game.OnAscend;
|
||||
CM.Disp.lastBuyMode = Game.buyMode;
|
||||
CM.Disp.lastBuyBulk = Game.buyBulk;
|
||||
|
||||
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);
|
||||
|
||||
// given the architecture of your code, you probably want these lines somewhere else,
|
||||
// but I stuck them here for convenience
|
||||
l("products").style.display = "grid";
|
||||
l("storeBulk").style.gridRow = "1/1";
|
||||
|
||||
l("upgrades").style.display = "flex";
|
||||
l("upgrades").style["flex-wrap"] = "wrap";
|
||||
|
||||
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()
|
||||
* It is called by CM.Main.DelayInit()
|
||||
*/
|
||||
CM.Main.ReplaceTooltips = function() {
|
||||
CM.Main.ReplaceTooltipBuild();
|
||||
@@ -253,7 +283,7 @@ CM.Main.ReplaceTooltips = function() {
|
||||
CM.Backup.LoadMinigames();
|
||||
CM.Main.ReplaceTooltipGarden();
|
||||
CM.Main.ReplaceTooltipGrimoire();
|
||||
CM.ReplaceNativeGrimoire();
|
||||
CM.Main.ReplaceNativeGrimoire();
|
||||
};
|
||||
Game.LoadMinigames();
|
||||
};
|
||||
@@ -343,7 +373,7 @@ CM.Main.FindShimmer = function() {
|
||||
|
||||
/**
|
||||
* This function checks for changes in the amount of Golden Cookies
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckGoldenCookie = function() {
|
||||
CM.Main.FindShimmer();
|
||||
@@ -383,7 +413,7 @@ CM.Main.CheckGoldenCookie = function() {
|
||||
|
||||
/**
|
||||
* This function checks if there is reindeer that has spawned
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckSeasonPopup = function() {
|
||||
if (CM.Main.lastSeasonPopupState != Game.shimmerTypes.reindeer.spawned) {
|
||||
@@ -402,7 +432,7 @@ CM.Main.CheckSeasonPopup = function() {
|
||||
|
||||
/**
|
||||
* This function checks if there is a fortune cookie on the ticker
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckTickerFortune = function() {
|
||||
if (CM.Main.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type === 'fortune')) {
|
||||
@@ -417,7 +447,7 @@ CM.Main.CheckTickerFortune = function() {
|
||||
|
||||
/**
|
||||
* This function checks if a garden tick has happened
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckGardenTick = function() {
|
||||
if (Game.Objects.Farm.minigameLoaded && CM.Main.lastGardenNextStep != Game.Objects.Farm.minigame.nextStep) {
|
||||
@@ -431,7 +461,7 @@ CM.Main.CheckGardenTick = function() {
|
||||
|
||||
/**
|
||||
* This function checks if the magic meter is full
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckMagicMeter = function() {
|
||||
if (Game.Objects['Wizard tower'].minigameLoaded && CM.Options.GrimoireBar === 1) {
|
||||
@@ -448,7 +478,7 @@ CM.Main.CheckMagicMeter = function() {
|
||||
|
||||
/**
|
||||
* This function checks if any new Wrinklers have popped up
|
||||
* It is called by CM.Loop
|
||||
* It is called by CM.Main.Loop
|
||||
*/
|
||||
CM.Main.CheckWrinklerCount = function() {
|
||||
if (Game.elderWrath > 0) {
|
||||
@@ -481,7 +511,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
|
||||
* It is called by CM.Main.DelayInit
|
||||
* TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips
|
||||
* Thus, writing a CM.Main.ReplaceTooltipWrinkler function etc.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user