diff --git a/CookieMonster.js b/CookieMonster.js
index 3a3b3e9..66c9b12 100644
--- a/CookieMonster.js
+++ b/CookieMonster.js
@@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() {
CM.Disp = {};
+ CM.Main = {};
+
CM.Sim = {};
}
@@ -27,6 +29,9 @@ if (typeof CM == "undefined") {
* Cache *
*********/
+/********
+ * Section: UNSORTED */
+
CM.Cache.AddQueue = function() {
CM.Cache.Queue = document.createElement('script');
CM.Cache.Queue.type = 'text/javascript';
@@ -549,7 +554,9 @@ CM.Cache.MissingCookies = Game.Upgrades;
CM.Cache.UpgradesOwned = -1;
CM.Cache.MissingUpgradesString = null;
CM.Cache.MissingCookiesString = null;
-
+CM.Cache.seasonPopShimmer;
+CM.Cache.goldenShimmersByID = {};
+CM.Cache.spawnedGoldenShimmer = 0;
/**********
* Config *
**********/
@@ -603,7 +610,7 @@ CM.LoadConfig = function() {
if (mod) CM.SaveConfig(CM.Config);
CM.Loop(); // Do loop once
for (var i in CM.ConfigDefault) {
- if (i != 'StatsPref' && i != 'MenuPref' && typeof CM.ConfigData[i].func !== 'undefined') {
+ if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') {
CM.ConfigData[i].func();
}
}
@@ -666,12 +673,12 @@ CM.ToggleStatsConfig = function(config) {
CM.SaveConfig(CM.Config);
}
-CM.ToggleMenuConfig = function(config) {
- if (CM.Config.MenuPref[config] == 0) {
- CM.Config.MenuPref[config]++;
+CM.ToggleOptionsConfig = function(config) {
+ if (CM.Config.OptionsPref[config] == 0) {
+ CM.Config.OptionsPref[config]++;
}
else {
- CM.Config.MenuPref[config]--;
+ CM.Config.OptionsPref[config]--;
}
CM.SaveConfig(CM.Config);
}
@@ -703,111 +710,7 @@ CM.CheckNotificationPermissions = function(ToggleOnOff) {
}
}
}
-}
-
-CM.ConfigData.BotBar = {label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}};
-CM.ConfigData.TimerBar = {label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}};
-CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}};
-CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}};
-CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
-CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
-CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpBarColor();}};
-CM.ConfigData.Colors = {
- desc: {
- Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels',
- Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
- Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels',
- Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels',
- Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels',
- Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels',
- Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
- Pink: 'Color Pink. Used for Dragonflight bar',
- Brown: 'Color Brown. Used for Dragon Harvest bar'
- },
- func: function() {CM.Disp.UpdateColors();}
-};
-CM.ConfigData.UpgradeBarFixedPos = {label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}};
-CM.ConfigData.CalcWrink = {label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true};
-CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false};
-CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
-CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
-CM.ConfigData.ToolWarnBon = {label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
-CM.ConfigData.GCNotification = {label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}};
-CM.ConfigData.GCFlash = {label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true};
-CM.ConfigData.GCSound = {label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true};
-CM.ConfigData.GCVolume = {label: [], desc: 'Volume of the Golden Cookie sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.GCVolume.label[i] = i + '%';
-}
-CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
-CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}};
-CM.ConfigData.Favicon = {label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}};
-CM.ConfigData.FortuneNotification = {label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}};
-CM.ConfigData.FortuneFlash = {label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true};
-CM.ConfigData.FortuneSound = {label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true};
-CM.ConfigData.FortuneVolume = {label: [], desc: 'Volume of the Fortune Cookie sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.FortuneVolume.label[i] = i + '%';
-}
-CM.ConfigData.FortuneSoundURL = {label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'};
-CM.ConfigData.SeaNotification = {label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}};
-CM.ConfigData.SeaFlash = {label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true};
-CM.ConfigData.SeaSound = {label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true};
-CM.ConfigData.SeaVolume = {label: [], desc: 'Volume of the Season Special sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.SeaVolume.label[i] = i + '%';
-}
-CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'};
-CM.ConfigData.GardFlash = {label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true};
-CM.ConfigData.GardSound = {label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true};
-CM.ConfigData.GardVolume = {label: [], desc: 'Volume of the Garden Tick sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.GardVolume.label[i] = i + '%';
-}
-CM.ConfigData.GardSoundURL = {label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'};
-CM.ConfigData.MagicNotification = {label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}};
-CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true};
-CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true};
-CM.ConfigData.MagicVolume = {label: [], desc: 'Volume of the Max Magic sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.MagicVolume.label[i] = i + '%';
-}
-CM.ConfigData.MagicSoundURL = {label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'};
-CM.ConfigData.WrinklerNotification = {label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}};
-CM.ConfigData.WrinklerFlash = {label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true};
-CM.ConfigData.WrinklerSound = {label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true};
-CM.ConfigData.WrinklerVolume = {label: [], desc: 'Volume of the Wrinkler sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.WrinklerVolume.label[i] = i + '%';
-}
-CM.ConfigData.WrinklerSoundURL = {label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'};
-CM.ConfigData.WrinklerMaxNotification = {label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}};
-CM.ConfigData.WrinklerMaxFlash = {label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true};
-CM.ConfigData.WrinklerMaxSound = {label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true};
-CM.ConfigData.WrinklerMaxVolume = {label: [], desc: 'Volume of the Wrinkler Max sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%';
-}
-CM.ConfigData.WrinklerMaxSoundURL = {label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'};
-CM.ConfigData.Title = {label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true};
-CM.ConfigData.TooltipBuildUp = {label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true};
-CM.ConfigData.TooltipAmor = {label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true};
-CM.ConfigData.ToolWarnLucky = {label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true};
-CM.ConfigData.ToolWarnConjure = {label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true};
-CM.ConfigData.ToolWarnPos = {label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}};
-CM.ConfigData.TooltipGrim = {label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true};
-CM.ConfigData.ToolWrink = {label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true};
-CM.ConfigData.TooltipLump = {label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true};
-CM.ConfigData.Stats = {label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
-CM.ConfigData.MissingUpgrades = {label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true};
-CM.ConfigData.UpStats = {label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false};
-CM.ConfigData.TimeFormat = {label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false};
-CM.ConfigData.SayTime = {label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}};
-CM.ConfigData.GrimoireBar = {label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true};
-CM.ConfigData.Scale = {label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};
-CM.ConfigData.SortBuildings = {label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}};
-CM.ConfigData.SortUpgrades = {label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
-/********
+}/********
* Data *
********/
@@ -840,53 +743,170 @@ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime
CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits'];
CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits'];
+
/********
+ * Section: Data for the various scales used by CookieMonster */
+CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
+CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
+
+/********
+ * Section: An array containing all Config groups and their to-be displayed title */
+
+CM.ConfigGroups = {
+ BarsColors: "Bars/Colors",
+ Calculation: "Calculation",
+ Notification: "Notification",
+ Tooltip: "Tooltips",
+ Statistics: "Statitics",
+ Other: "Other"},
+
+/********
+ * Section: An array (CM.ConfigData) containing all Config options
+ *
+ * Each array has the following items
+ * @item {string} type The type of option (bool(ean), vol(ume), url or color)
+ * @item {string} group The options-group the option belongs to
+ * @item {[string, ...]} label A list of the various configurations of the option
+ * @item {string} desc Description to be used in options menu
+ * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu
+ * @item {function} func A function to be called when the option is toggled
+ */
+
+// Barscolors
+CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}};
+CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}};
+CM.ConfigData.TimerBarPos = {type: 'bool', group: 'BarsColors', label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}};
+CM.ConfigData.SortBuildings = {type: 'bool', group: 'BarsColors', label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}};
+CM.ConfigData.SortUpgrades = {type: 'bool', group: 'BarsColors', label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
+CM.ConfigData.BuildColor = {type: 'bool', group: 'BarsColors', label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}};
+CM.ConfigData.BulkBuildColor = {type: 'bool', group: 'BarsColors', label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
+CM.ConfigData.ColorPPBulkMode = {type: 'bool', group: 'BarsColors', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
+CM.ConfigData.UpBarColor = {type: 'bool', group: 'BarsColors', label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}};
+CM.ConfigData.Colors = { type: 'color', group: 'BarsColors',
+ desc: {
+ Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels',
+ Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
+ Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels',
+ Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels',
+ Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels',
+ Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels',
+ Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
+ Pink: 'Color Pink. Used for Dragonflight bar',
+ Brown: 'Color Brown. Used for Dragon Harvest bar'
+ },
+ func: function() {CM.Disp.UpdateColors();}
+};
+CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}};
+
+// Calculation
+CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true};
+CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false};
+CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
+CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
+CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
+
+// Notification
+CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}};
+CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true};
+CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true};
+CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.GCVolume.label[i] = i + '%';
+}
+CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
+CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}};
+CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}};
+CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}};
+CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true};
+CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true};
+CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.FortuneVolume.label[i] = i + '%';
+}
+CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'};
+CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}};
+CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true};
+CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true};
+CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.SeaVolume.label[i] = i + '%';
+}
+CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'};
+CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true};
+CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true};
+CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.GardVolume.label[i] = i + '%';
+}
+CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'};
+CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}};
+CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true};
+CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true};
+CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.MagicVolume.label[i] = i + '%';
+}
+CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'};
+CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}};
+CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true};
+CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true};
+CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.WrinklerVolume.label[i] = i + '%';
+}
+CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'};
+CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}};
+CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true};
+CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true};
+CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%';
+}
+CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'};
+CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true};
+
+// Tooltip
+CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true};
+CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true};
+CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true};
+CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true};
+CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}};
+CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true};
+CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true};
+CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true};
+
+// Statistics
+CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
+CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true};
+CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false};
+CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false};
+CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}};
+CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true};
+
+// Statistics
+CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};/********
* Disp *
********/
+/********
+ * Please make sure to annotate your code correctly. See the options page section for some examples.
+ * Only put functions related to graphics and displays in this file.
+ * All calculations and data should be put in others. */
+
/********
* Section: Unsorted functions
* TODO: Annotate most functions
* TODO: Sort functionsn in relevant (new) sections or files */
-CM.Disp.GetTimeColor = function(price, bank, cps, time) {
- var color;
- var text;
- if (bank >= price) {
- color = CM.Disp.colorGreen;
- if (CM.Config.TimeFormat) {
- text = '00:00:00:00:00';
- }
- else {
- text = 'Done!';
- }
- }
- else {
- if (typeof time !== 'undefined') {
- var time = time;
- }
- else {
- var time = (price - bank) / cps;
- }
- text = CM.Disp.FormatTime(time);
- if (time > 300) {
- color = CM.Disp.colorRed;
- }
- else if (time > 60) {
- color = CM.Disp.colorOrange;
- }
- else {
- color = CM.Disp.colorYellow;
- }
- }
- return {text: text, color: color};
+CM.Disp.TooltipWrinklerCache = [];
+for (var i in Game.wrinklers) {
+ CM.Disp.TooltipWrinklerCache[i] = 0;
}
/**
* This function returns Name and Color as object for sugar lump type that is given as input param.
* @param type Sugar Lump Type.
* @returns {{text: string, color: string}}
- * @constructor
*/
CM.Disp.GetLumpColor = function(type) {
var name = "";
@@ -954,20 +974,7 @@ CM.Disp.AddJscolor = function() {
document.head.appendChild(CM.Disp.Jscolor);
}
-CM.Disp.CreateCssArea = function() {
- CM.Disp.Css = document.createElement('style');
- CM.Disp.Css.type = 'text/css';
- document.head.appendChild(CM.Disp.Css);
-
- // 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";
-}
CM.Disp.UpdateUpgrades = function() {
if (CM.Config.UpBarColor > 0) {
@@ -1049,31 +1056,6 @@ CM.Disp.UpdateColors = function() {
CM.Disp.UpdateBuildings(); // Class has been already set
}
-CM.Disp.CreateWhiteScreen = function() {
- CM.Disp.WhiteScreen = document.createElement('div');
- CM.Disp.WhiteScreen.id = 'CMWhiteScreen';
- CM.Disp.WhiteScreen.style.width = '100%';
- CM.Disp.WhiteScreen.style.height = '100%';
- CM.Disp.WhiteScreen.style.backgroundColor = 'white';
- CM.Disp.WhiteScreen.style.display = 'none';
- CM.Disp.WhiteScreen.style.zIndex = '9999999999';
- CM.Disp.WhiteScreen.style.position = 'absolute';
-
- l('wrapper').appendChild(CM.Disp.WhiteScreen);
-}
-
-CM.Disp.FindShimmer = function() {
- CM.Disp.currSpawnedGoldenCookieState = 0
- CM.Disp.goldenShimmersByID = {}
- for (var i in Game.shimmers) {
- CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i]
- if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') {
- CM.Disp.spawnedGoldenShimmer = Game.shimmers[i];
- CM.Disp.currSpawnedGoldenCookieState += 1;
- }
- }
-}
-
CM.Disp.CollectWrinklers = function() {
for (var i in Game.wrinklers) {
if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) {
@@ -1103,16 +1085,7 @@ CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMag
return count / Game.fps;
}
-CM.Disp.AddWrinklerAreaDetect = function() {
- l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;};
- l('backgroundLeftCanvas').onmouseout = function() {
- CM.Disp.TooltipWrinklerArea = 0;
- Game.tooltip.hide();
- for (var i in Game.wrinklers) {
- CM.Disp.TooltipWrinklerCache[i] = 0;
- }
- };
-}
+
CM.Disp.UpdateAscendState = function() {
if (Game.OnAscend) {
@@ -1155,19 +1128,34 @@ CM.Disp.RefreshScale = function() {
Game.RefreshStore();
Game.RebuildUpgrades();
- CM.Disp.UpdateBotBarOther();
+ CM.Disp.UpdateBotBar();
CM.Disp.UpdateBuildings();
CM.Disp.UpdateUpgrades();
}
+
+CM.Disp.CreateCssArea = function() {
+ CM.Disp.Css = document.createElement('style');
+ CM.Disp.Css.type = 'text/css';
+
+ document.head.appendChild(CM.Disp.Css);
+
+ // 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";
+}
+
/********
- * Section: General functions to format or beautify strings
- * TODO: Annotate most functions */
+ * Section: General functions to format or beautify strings */
/**
* This function returns time as a string depending on TimeFormat setting
- * @param {number} time Time as number
- * @param {number} longFormat 1 or 0
- * @return {string}
+ * @param {number} time Time to be formatted
+ * @param {number} longFormat 1 or 0
+ * @returns {string} Formatted time
*/
CM.Disp.FormatTime = function(time, longFormat) {
if (time == Infinity) return time;
@@ -1195,118 +1183,209 @@ CM.Disp.FormatTime = function(time, longFormat) {
return str;
}
-CM.Disp.Beautify = function(num, frac) {
- if (CM.Config.Scale != 0 && isFinite(num)) {
+/**
+ * This function returns the color to be used for time-strings
+ * @param {number} time Time to be coloured
+ * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array
+ */
+CM.Disp.GetTimeColor = function(time) {
+ var color;
+ var text;
+ if (time < 0) {
+ if (CM.Config.TimeFormat) text = '00:00:00:00:00';
+ else text = 'Done!';
+ color = CM.Disp.colorGreen;
+ }
+ else {
+ text = CM.Disp.FormatTime(time);
+ if (time > 300) color = CM.Disp.colorRed;
+ else if (time > 60) color = CM.Disp.colorOrange;
+ else color = CM.Disp.colorYellow;
+ }
+ return {text: text, color: color};
+}
+
+/**
+ * This function returns formats number based on the Scale setting
+ * @param {number} num Number to be beautified
+ * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function)
+ * @param {number} forced Used to force (type 3) in certains cases
+ * @returns {string} Formatted number
+ * TODO: Add functionality to choose amount of decimals and separators
+ */
+CM.Disp.Beautify = function(num, frac, forced) {
+ var decimals = 3; // This can be used to implement function to let user choose amount of decimals
+ if (CM.Config.Scale == 0) {
+ return CM.Backup.Beautify(num, frac);
+ }
+ else if (isFinite(num)) {
var answer = '';
- var negative = false;
if (num < 0) {
num = Math.abs(num);
- negative = true;
+ var negative = true;
}
-
- if (CM.Config.Scale == 3) {
- if (num >= 999999) {
- var count = 0;
- while (num >= 10) {
- count++;
- num /= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
- }
+ num = num.toString();
+ var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3)
+ if (num == "0") {
+ return num
}
- else if (CM.Config.Scale == 4) {
- if (um >= 999999) {
- var count = 0;
- while (num >= 1000) {
- count++;
- num /= 1000;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3);
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 1000;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3);
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
+ else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) {
+ answer = Math.round(num * 100) / 100;
+ }
+ else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8
+ answer = num[0] + '.'
+ i = 0;
+ while (i < decimals - 1) {
+ answer += num[i + 2]; // num has a 0-based index and [1] is a '.'
+ i++;
}
+ answer += Math.round(num[i + 2] + '.' + num[i + 3]);
+ answer += 'E+' + Math.trunc(Math.log10(num));
}
else {
- for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) {
- if (i < CM.Disp.metric.length && CM.Config.Scale == 1) {
- // Revert to Scientific Notation from e27
- if (Math.log10(num) > 27) {
- if (num >= 999999) {
- var count = 0;
- while (num >= 10) {
- count++;
- num /= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
- }
- }
- else if (num >= Math.pow(1000, i + 2)) {
- answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
- break;
- }
+ var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString();
+ numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length))
+ i = 0
+ while (i < numbersToAdd - 1) {
+ answer += restOfNumber[i];
+ i++
+ }
+ answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]);
+
+ // answer is now "xxx.xx" (e.g., 123456789 would be 123.46)
+ if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M
+ if (timesTenToPowerThree - 1 < CM.Data.metric.length) {
+ answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1]
}
- else if (CM.Config.Scale == 2) {
- if (num >= Math.pow(1000, i + 2)) {
- answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + ' ' + CM.Disp.shortScale[i];
- break;
- }
+ else { // If number is too large, revert to scientific notation
+ return CM.Disp.Beautify(num, 0, 3);
}
}
+ else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M
+ if (timesTenToPowerThree < CM.Data.shortScale.length + 1) {
+ answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1];
+ }
+ else { // If number is too large, revert to scientific notation
+ return CM.Disp.Beautify(num, 0, 3);
+ }
+ }
+ else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6
+ answer += 'E+' + (timesTenToPowerThree * 3);
+ }
}
if (answer == '') {
- answer = CM.Backup.Beautify(num, frac);
+ console.log("Could not beautify number with CM.Disp.Beautify");
+ answer = CM.Backup.Beautify(num, frac);
}
-
- if (negative) {
- answer = '-' + answer;
- }
- return answer;
+ if (negative) answer = '-' + answer;
+ return answer.toString();
+ }
+ else if (num == Infinity) {
+ return "Infinity";
}
else {
+ console.log("Could not beautify number with CM.Disp.Beautify");
return CM.Backup.Beautify(num, frac);
}
}
/********
- * Section: Functions related to the Bottom Bar
- * TODO: Annotate functions */
+ * Section: Functions related to the Bottom Bar */
/**
- * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building.
- *
+ * This function toggle the bottom bar
+ * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar
+ */
+CM.Disp.ToggleBotBar = function() {
+ if (CM.Config.BotBar == 1) {
+ CM.Disp.BotBar.style.display = '';
+ CM.Disp.UpdateBotBar();
+ }
+ else {
+ CM.Disp.BotBar.style.display = 'none';
+ }
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/**
+ * This function creates the bottom bar and appends it to l('wrapper')
+ * It is called by CM.DelayInit and a change in CM.Config.BotBar
+ */
+CM.Disp.CreateBotBar = function() {
+ CM.Disp.BotBar = document.createElement('div');
+ CM.Disp.BotBar.id = 'CMBotBar';
+ CM.Disp.BotBar.style.height = '69px';
+ CM.Disp.BotBar.style.width = '100%';
+ CM.Disp.BotBar.style.position = 'absolute';
+ CM.Disp.BotBar.style.display = 'none';
+ CM.Disp.BotBar.style.backgroundColor = '#262224';
+ // This is old code for very old browsersand should not be needed anymore
+ //CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)';
+ //CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)';
+ //CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)';
+ CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)';
+ CM.Disp.BotBar.style.borderTop = '1px solid black';
+ CM.Disp.BotBar.style.overflow = 'auto';
+ CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
+
+ var table = CM.Disp.BotBar.appendChild(document.createElement('table'));
+ table.style.width = '100%';
+ table.style.textAlign = 'center';
+ table.style.whiteSpace = 'nowrap';
+ var tbody = table.appendChild(document.createElement('tbody'));
+
+ var firstCol = function(text, color) {
+ var td = document.createElement('td');
+ td.style.textAlign = 'right';
+ td.className = CM.Disp.colorTextPre + color;
+ td.textContent = text;
+ return td;
+ }
+ var type = tbody.appendChild(document.createElement('tr'));
+ type.style.fontWeight = 'bold';
+ type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow));
+ var bonus = tbody.appendChild(document.createElement('tr'));
+ bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue));
+ var pp = tbody.appendChild(document.createElement('tr'));
+ pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue));
+ var time = tbody.appendChild(document.createElement('tr'));
+ time.appendChild(firstCol('Time Left', CM.Disp.colorBlue));
+
+ for (var i in Game.Objects) {
+ CM.Disp.CreateBotBarBuildingColumn(i);
+ }
+
+ l('wrapper').appendChild(CM.Disp.BotBar);
+}
+
+/**
+ * This function updates the bonus-, pp-, and time-rows in the the bottom bar
+ * It is called by CM.Loop()
+ */
+CM.Disp.UpdateBotBar = function() {
+ if (CM.Config.BotBar == 1) {
+ var count = 0;
+ for (var i in CM.Cache.Objects) {
+ var target = 'Objects';
+ if (Game.buyBulk == 10) {target = 'Objects10';}
+ if (Game.buyBulk == 100) {target = 'Objects100';}
+ count++;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2);
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2);
+ var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text;
+ }
+ }
+}
+
+/**
+ * This function extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building.
* This function is called by CM.Disp.CreateBotBar on initialization of Cookie Monster,
* and also in CM.Sim.CopyData if a new building (added by another mod) is discovered.
+ * @param {string} buildingName Objectname to be added (e.g., "Cursor")
*/
CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
if(!CM.Disp.BotBar) {
@@ -1332,101 +1411,13 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
time.appendChild(document.createElement('td'));
}
-CM.Disp.CreateBotBar = function() {
- CM.Disp.BotBar = document.createElement('div');
- CM.Disp.BotBar.id = 'CMBotBar';
- CM.Disp.BotBar.style.height = '69px';
- CM.Disp.BotBar.style.width = '100%';
- CM.Disp.BotBar.style.position = 'absolute';
- CM.Disp.BotBar.style.display = 'none';
- CM.Disp.BotBar.style.backgroundColor = '#262224';
- CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)';
- CM.Disp.BotBar.style.borderTop = '1px solid black';
- CM.Disp.BotBar.style.overflow = 'auto';
- CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
-
- var table = CM.Disp.BotBar.appendChild(document.createElement('table'));
- table.style.width = '100%';
- table.style.textAlign = 'center';
- table.style.whiteSpace = 'nowrap';
- // TODO figure a better way
- //table.style.tableLayout = 'fixed';
- //table.style.overflow = 'hidden';
- var tbody = table.appendChild(document.createElement('tbody'));
-
- var firstCol = function(text, color) {
- var td = document.createElement('td');
- td.style.textAlign = 'right';
- td.className = CM.Disp.colorTextPre + color;
- td.textContent = text;
- return td;
- }
-
- var type = tbody.appendChild(document.createElement('tr'));
- type.style.fontWeight = 'bold';
- type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow));
- var bonus = tbody.appendChild(document.createElement('tr'));
- bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue));
- var pp = tbody.appendChild(document.createElement('tr'));
- pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue));
- var time = tbody.appendChild(document.createElement('tr'));
- time.appendChild(firstCol('Time Left', CM.Disp.colorBlue));
-
- for (var i in Game.Objects) {
- CM.Disp.CreateBotBarBuildingColumn(i);
- }
-
- l('wrapper').appendChild(CM.Disp.BotBar);
-}
-
-CM.Disp.ToggleBotBar = function() {
- if (CM.Config.BotBar == 1) {
- CM.Disp.BotBar.style.display = '';
- CM.Disp.UpdateBotBarOther();
- }
- else {
- CM.Disp.BotBar.style.display = 'none';
- }
- CM.Disp.UpdateBotTimerBarDisplay();
-}
-
-CM.Disp.UpdateBotBarOther = function() {
- if (CM.Config.BotBar == 1) {
- var count = 0;
-
- for (var i in CM.Cache.Objects) {
- var target = 'Objects';
- if (Game.buyBulk == 10) {target = 'Objects10';}
- if (Game.buyBulk == 100) {target = 'Objects100';}
- count++;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2);
- CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2);
- }
- }
-}
-
-CM.Disp.UpdateBotBarTime = function() {
- if (CM.Config.BotBar == 1) {
- var count = 0;
-
- for (var i in CM.Cache.Objects) {
- count++;
- var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].getPrice(), (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
- CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text;
- }
- }
-}
-
/********
* Section: Functions related to the Timer Bar
- * TODO: Annotate functions */
+/**
+ * This function creates the TimerBar and appends it to l('wrapper')
+ * It is called by CM.DelayInit()
+ */
CM.Disp.CreateTimerBar = function() {
CM.Disp.TimerBar = document.createElement('div');
CM.Disp.TimerBar.id = 'CMTimerBar';
@@ -1437,118 +1428,98 @@ CM.Disp.CreateTimerBar = function() {
CM.Disp.TimerBar.style.fontWeight = 'bold';
CM.Disp.TimerBar.style.backgroundColor = 'black';
- var bar = function(name, bars, time) {
- var div = document.createElement('div');
- div.style.width = '100%';
- div.style.height = '10px';
- div.style.margin = 'auto';
- div.style.position = 'absolute';
- div.style.left = '0px';
- div.style.top = '0px';
- div.style.right = '0px';
- div.style.bottom = '0px';
+ CM.Disp.TimerBars = {};
+ CM.Disp.BuffTimerBars = {};
- var type = document.createElement('span');
- type.style.display = 'inline-block';
- type.style.textAlign = 'right';
- type.style.width = '108px';
- type.style.marginRight = '5px';
- type.style.verticalAlign = 'text-top';
- type.textContent = name;
- div.appendChild(type);
+ // Create standard Golden Cookie bar
+ CM.Disp.TimerBars['CMTimerBarGC'] = CM.Disp.TimerBarCreateBar('CMTimerBarGC',
+ 'Next Cookie',
+ [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}]
+ );
+ CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarGC'])
- for (var i = 0; i < bars.length; i++) {
- var colorBar = document.createElement('span');
- colorBar.id = bars[i].id
- colorBar.style.display = 'inline-block';
- colorBar.style.height = '10px';
- if (bars.length - 1 == i) {
- colorBar.style.borderTopRightRadius = '10px';
- colorBar.style.borderBottomRightRadius = '10px';
- }
- if (typeof bars[i].color !== 'undefined') {
- colorBar.className = CM.Disp.colorBackPre + bars[i].color;
- }
- div.appendChild(colorBar);
- }
-
- var timer = document.createElement('span');
- timer.id = time;
- timer.style.marginLeft = '5px';
- timer.style.verticalAlign = 'text-top';
- div.appendChild(timer);
- return div
- }
-
- CM.Disp.TimerBarGC = document.createElement('div');
- CM.Disp.TimerBarGC.id = 'CMTimerBarGC';
- CM.Disp.TimerBarGC.style.height = '12px';
- CM.Disp.TimerBarGC.style.margin = '0px 10px';
- CM.Disp.TimerBarGC.style.position = 'relative';
- CM.Disp.TimerBarGC.appendChild(bar('Next Cookie', [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}], 'CMTimerBarGCTime'));
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarGC);
-
- CM.Disp.TimerBarRen = document.createElement('div');
- CM.Disp.TimerBarRen.id = 'CMTimerBarRen';
- CM.Disp.TimerBarRen.style.height = '12px';
- CM.Disp.TimerBarRen.style.margin = '0px 10px';
- CM.Disp.TimerBarRen.style.position = 'relative';
- CM.Disp.TimerBarRen.appendChild(bar('Next Reindeer', [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}], 'CMTimerBarRenTime'));
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarRen);
-
- CM.Disp.TimerBarBuff1 = document.createElement('div');
- CM.Disp.TimerBarBuff1.id = 'CMTimerBarBuff1';
- CM.Disp.TimerBarBuff1.style.height = '12px';
- CM.Disp.TimerBarBuff1.style.margin = '0px 10px';
- CM.Disp.TimerBarBuff1.style.position = 'relative';
- CM.Disp.TimerBarBuff1.appendChild(bar('', [{id: 'CMTimerBarBuff1Bar'}], 'CMTimerBarBuff1Time'));
- CM.Disp.TimerBarBuff1.firstChild.firstChild.id = 'CMTimerBarBuff1Type';
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff1);
-
- CM.Disp.TimerBarBuff2 = document.createElement('div');
- CM.Disp.TimerBarBuff2.id = 'CMTimerBarBuff2';
- CM.Disp.TimerBarBuff2.style.height = '12px';
- CM.Disp.TimerBarBuff2.style.margin = '0px 10px';
- CM.Disp.TimerBarBuff2.style.position = 'relative';
- CM.Disp.TimerBarBuff2.appendChild(bar('', [{id: 'CMTimerBarBuff2Bar'}], 'CMTimerBarBuff2Time'));
- CM.Disp.TimerBarBuff2.firstChild.firstChild.id = 'CMTimerBarBuff2Type';
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff2);
+ // Create standard Reindeer bar
+ CM.Disp.TimerBars['CMTimerBarRen'] = CM.Disp.TimerBarCreateBar('CMTimerBarRen',
+ 'Next Reindeer',
+ [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}]
+ );
+ CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarRen'])
l('wrapper').appendChild(CM.Disp.TimerBar);
}
-CM.Disp.ToggleTimerBar = function() {
- if (CM.Config.TimerBar == 1) {
- CM.Disp.TimerBar.style.display = '';
+/**
+ * This function creates an indivudual timer for the timer bar
+ * It is called by CM.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
+ */
+CM.Disp.TimerBarCreateBar = function(id, name, bars) {
+ timerBar = document.createElement('div');
+ timerBar.id = 'CMTimerBarGC';
+ timerBar.style.height = '12px';
+ timerBar.style.margin = '0px 10px';
+ timerBar.style.position = 'relative';
+
+ var div = document.createElement('div');
+ div.style.width = '100%';
+ div.style.height = '10px';
+ div.style.margin = 'auto';
+ div.style.position = 'absolute';
+ div.style.left = '0px';
+ div.style.top = '0px';
+ div.style.right = '0px';
+ div.style.bottom = '0px';
+
+ var type = document.createElement('span');
+ type.style.display = 'inline-block';
+ type.style.textAlign = 'right';
+ type.style.width = '108px';
+ type.style.marginRight = '5px';
+ type.style.verticalAlign = 'text-top';
+ type.textContent = name;
+ div.appendChild(type);
+
+ for (var i = 0; i < bars.length; i++) {
+ var colorBar = document.createElement('span');
+ colorBar.id = bars[i].id
+ colorBar.style.display = 'inline-block';
+ colorBar.style.height = '10px';
+ if (bars.length - 1 == i) {
+ colorBar.style.borderTopRightRadius = '10px';
+ colorBar.style.borderBottomRightRadius = '10px';
+ }
+ if (typeof bars[i].color !== 'undefined') {
+ colorBar.className = CM.Disp.colorBackPre + bars[i].color;
+ }
+ div.appendChild(colorBar);
}
- else {
- CM.Disp.TimerBar.style.display = 'none';
- }
- CM.Disp.UpdateBotTimerBarDisplay();
-}
-
-CM.Disp.ToggleTimerBarPos = function() {
- if (CM.Config.TimerBarPos == 0) {
- CM.Disp.TimerBar.style.width = '30%';
- CM.Disp.TimerBar.style.bottom = '';
- l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft'));
- }
- else {
- CM.Disp.TimerBar.style.width = '100%';
- CM.Disp.TimerBar.style.bottom = '0px';
- l('wrapper').appendChild(CM.Disp.TimerBar);
- }
- CM.Disp.UpdateBotTimerBarDisplay();
+
+ var timer = document.createElement('span');
+ timer.id = id + 'Time';
+ timer.style.marginLeft = '5px';
+ timer.style.verticalAlign = 'text-top';
+ div.appendChild(timer);
+
+ timerBar.appendChild(div);
+
+ return timerBar;
}
+/**
+ * This function creates an indivudual timer for the timer bar
+ * It is called by CM.Loop()
+ */
CM.Disp.UpdateTimerBar = function() {
if (CM.Config.TimerBar == 1) {
// label width: 113, timer width: 26, div margin: 20
var maxWidth = CM.Disp.TimerBar.offsetWidth - 159;
- var count = 0;
+ var numberOfTimers = 0;
+ // Regulates visibility of Golden Cookie timer
if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) {
- CM.Disp.TimerBarGC.style.display = '';
+ CM.Disp.TimerBars['CMTimerBarGC'].style.display = '';
l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px';
if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) {
l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px';
@@ -1560,107 +1531,96 @@ CM.Disp.UpdateTimerBar = function() {
}
l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px';
l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarGC.style.display = 'none';
+ numberOfTimers++;
}
+ else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none';
+ // Regulates visibility of Reinder timer
if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) {
- CM.Disp.TimerBarRen.style.display = '';
+ CM.Disp.TimerBars['CMTimerBarRen'].style.display = '';
l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px';
l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px';
l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps);
- count++;
+ numberOfTimers++;
}
else {
- CM.Disp.TimerBarRen.style.display = 'none';
+ CM.Disp.TimerBars['CMTimerBarRen'].style.display = 'none';
}
- var buffCount = 0;
+ // On every frame all buff-timers are deleted and re-created
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.BuffTimerBars[i].remove()
+ }
+ CM.Disp.BuffTimerBars = {}
for (var i in Game.buffs) {
if (Game.buffs[i]) {
- buffCount++;
- CM.Disp['TimerBarBuff' + buffCount].style.display = '';
- l('CMTimerBarBuff' + buffCount + 'Type').textContent = Game.buffs[i].name;
+ timer = CM.Disp.TimerBarCreateBar(Game.buffs[i].name, Game.buffs[i].name, [{id: Game.buffs[i].name + 'Bar'}])
+ timer.style.display = '';
var classColor = '';
+ // Gives specific timers specific colors
if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') {
classColor = CM.Disp.buffColors[Game.buffs[i].name];
}
- else {
- classColor = CM.Disp.colorPurple;
- }
- l('CMTimerBarBuff' + buffCount + 'Bar').className = CM.Disp.colorBackPre + classColor;
- l('CMTimerBarBuff' + buffCount + 'Bar').style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px';
- l('CMTimerBarBuff' + buffCount + 'Time').textContent = Math.ceil(Game.buffs[i].time / Game.fps);
- count++;
- if (buffCount == 2) {
- break;
- }
+ else classColor = CM.Disp.colorPurple;
+ timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor;
+ timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px';
+ timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps);
+ numberOfTimers++;
+ CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer
}
}
- if (buffCount < 2) {
- CM.Disp.TimerBarBuff2.style.display = 'none';
- if (buffCount < 1) {
- CM.Disp.TimerBarBuff1.style.display = 'none';
- }
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.TimerBar.appendChild(CM.Disp.BuffTimerBars[i])
}
- /*if (Game.frenzy > 0) {
- CM.Disp.TimerBarBuff1.style.display = '';
- if (Game.frenzyPower == 7) {
- l('CMTimerBarBuff1Type').textContent = 'Frenzy';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorYellow;
+ if (numberOfTimers != 0) {
+ var height = 48 / numberOfTimers;
+ for (var i in CM.Disp.TimerBars) {
+ CM.Disp.TimerBars[i].style.height = height + 'px';
}
- else if (Game.frenzyPower == 0.5) {
- l('CMTimerBarBuff1Type').textContent = 'Clot';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorRed;
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.BuffTimerBars[i].style.height = height + 'px';
}
- else if (Game.frenzyPower == 15) {
- l('CMTimerBarBuff1Type').textContent = 'Dragon Harvest';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBrown;
- }
- else {
- l('CMTimerBarBuff1Type').textContent = 'Blood Frenzy';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorGreen;
- }
- l('CMTimerBarBuff1Bar').style.width = Math.round(Game.frenzy * maxWidth / Game.frenzyMax) + 'px';
- l('CMTimerBarBuff1Time').textContent = Math.ceil(Game.frenzy / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarBuff1.style.display = 'none';
- }
-
- if (Game.clickFrenzy > 0) {
- CM.Disp.TimerBarBuff2.style.display = '';
- if (Game.clickFrenzyPower == 777) {
- l('CMTimerBarBuff2Type').textContent = 'Click Frenzy';
- l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBlue;
- }
- else {
- l('CMTimerBarBuff2Type').textContent = 'Dragonflight';
- l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorPink;
- }
- l('CMTimerBarBuff2Bar').style.width = Math.round(Game.clickFrenzy * maxWidth / Game.clickFrenzyMax) + 'px';
- l('CMTimerBarBuff2Time').textContent = Math.ceil(Game.clickFrenzy / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarBuff2.style.display = 'none';
- }*/
-
- if (count != 0) {
- var height = 48 / count;
- CM.Disp.TimerBarGC.style.height = height + 'px';
- CM.Disp.TimerBarRen.style.height = height + 'px';
- CM.Disp.TimerBarBuff1.style.height = height + 'px';
- CM.Disp.TimerBarBuff2.style.height = height + 'px';
}
}
}
-CM.Disp.UpdateBotTimerBarDisplay = function() {
+/**
+ * This function changes the visibility of the timer bar
+ * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar
+ */
+CM.Disp.ToggleTimerBar = function() {
+ if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = '';
+ else CM.Disp.TimerBar.style.display = 'none';
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/**
+ * This function changes the position of the timer bar
+ * It is called by a change in CM.Config.TimerBarPos
+ */
+CM.Disp.ToggleTimerBarPos = function() {
+ if (CM.Config.TimerBarPos == 0) {
+ CM.Disp.TimerBar.style.width = '30%';
+ CM.Disp.TimerBar.style.bottom = '';
+ l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft'));
+ }
+ else {
+ CM.Disp.TimerBar.style.width = '100%';
+ CM.Disp.TimerBar.style.bottom = '0px';
+ l('wrapper').appendChild(CM.Disp.TimerBar);
+ }
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/********
+ * Section: Functions related to the both the bottom and timer bar
+
+/**
+ * This function changes the position of both the bottom and timer bar
+ * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar()
+ */
+CM.Disp.UpdateBotTimerBarPosition = function() {
if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) {
CM.Disp.BotBar.style.bottom = '48px';
l('game').style.bottom = '118px';
@@ -1688,20 +1648,19 @@ CM.Disp.UpdateBotTimerBarDisplay = function() {
/********
* Section: Functions related to column of buildings/objects
- * TODO: Annotate functions */
+/**
+ * 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.Config.SortBuildings is set
+ * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale()
+ * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor
+ */
CM.Disp.UpdateBuildings = function() {
if (CM.Config.BuildColor == 1 && Game.buyMode == 1) {
var target = '';
- if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) {
- target = 'Objects10';
- }
- else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) {
- target = 'Objects100';
- }
- else {
- target = 'Objects';
- }
+ if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10';
+ else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100';
+ else target = 'Objects';
for (var i in CM.Cache[target]) {
l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color];
}
@@ -1755,8 +1714,44 @@ CM.Disp.UpdateBuildings = function() {
/********
* Section: Functions related to the Upgrade Bar
- * TODO: Annotate functions */
+/**
+ * This function toggles the upgrade bar and the colours of upgrades
+ * It is called by a change in CM.Config.UpBarColor
+ */
+CM.Disp.ToggleUpgradeBarAndColor = function() {
+ if (CM.Config.UpBarColor == 1) { // Colours and bar on
+ CM.Disp.UpgradeBar.style.display = '';
+ CM.Disp.UpdateUpgrades();
+ }
+ else if (CM.Config.UpBarColor == 2) {// Colours on and bar off
+ CM.Disp.UpgradeBar.style.display = 'none';
+ CM.Disp.UpdateUpgrades();
+ }
+ else { // Colours and bar off
+ CM.Disp.UpgradeBar.style.display = 'none';
+ Game.RebuildUpgrades();
+ }
+}
+
+/**
+ * This function toggles the position of the upgrade bar from fixed or non-fixed mode
+ * It is called by a change in CM.Config.UpgradeBarFixedPos
+ */
+CM.Disp.ToggleUpgradeBarFixedPos = function() {
+ if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling
+ CM.Disp.UpgradeBar.style.position = 'sticky';
+ CM.Disp.UpgradeBar.style.top = '0px';
+ }
+ else {
+ CM.Disp.UpgradeBar.style.position = ''; // Possible to scroll offscreen
+ }
+}
+
+/**
+ * This function creates the upgrade bar above the upgrade-section in the right section of the screen
+ * The number (.textContent) of upgrades gets updated by CM.Disp.UpdateUpgrades()
+ */
CM.Disp.CreateUpgradeBar = function() {
CM.Disp.UpgradeBar = document.createElement('div');
CM.Disp.UpgradeBar.id = 'CMUpgradeBar';
@@ -1769,6 +1764,34 @@ CM.Disp.CreateUpgradeBar = function() {
CM.Disp.UpgradeBar.onmouseout = function() { Game.tooltip.hide(); };
var placeholder = document.createElement('div');
+ placeholder.appendChild(CM.Disp.CreateUpgradeBarLegend());
+ CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');};
+
+ var upgradeNumber = function(id, color) {
+ var span = document.createElement('span');
+ span.id = id;
+ span.className = CM.Disp.colorTextPre + color;
+ span.style.width = '14.28571428571429%';
+ span.style.display = 'inline-block';
+ span.textContent = '0';
+ return span;
+ }
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray));
+
+ l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]);
+}
+
+/**
+ * This function creates the legend for the upgrade bar, it is called by CM.Disp.CreateUpgradeBar
+ * @returns {object} legend The legend-object to be added
+ */
+CM.Disp.CreateUpgradeBarLegend = function() {
var legend = document.createElement('div');
legend.style.minWidth = '330px';
legend.style.marginBottom = '4px';
@@ -1799,59 +1822,35 @@ CM.Disp.CreateUpgradeBar = function() {
legend.appendChild(legendLine(CM.Disp.colorRed, 'Same as worst PP building'));
legend.appendChild(legendLine(CM.Disp.colorPurple, 'Worse than worst PP building'));
legend.appendChild(legendLine(CM.Disp.colorGray, 'Negative or infinity PP'));
- placeholder.appendChild(legend);
-
- CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');};
-
- var upgradeNumber = function(id, color) {
- var span = document.createElement('span');
- span.id = id;
- span.className = CM.Disp.colorTextPre + color;
- span.style.width = '14.28571428571429%';
- span.style.display = 'inline-block';
- span.textContent = '0';
- return span;
- }
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray));
-
- l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]);
-}
-
-CM.Disp.ToggleUpBarColor = function() {
- if (CM.Config.UpBarColor == 1) {
- CM.Disp.UpgradeBar.style.display = '';
- CM.Disp.UpdateUpgrades();
- }
- else if (CM.Config.UpBarColor == 2) {
- CM.Disp.UpgradeBar.style.display = 'none';
- CM.Disp.UpdateUpgrades();
- }
- else {
- CM.Disp.UpgradeBar.style.display = 'none';
- Game.RebuildUpgrades();
- }
-}
-
-CM.Disp.ToggleUpgradeBarFixedPos = function() {
- if (CM.Config.UpgradeBarFixedPos == 1) {
- CM.Disp.UpgradeBar.style.position = 'sticky';
- CM.Disp.UpgradeBar.style.top = '0px';
- }
- else {
- CM.Disp.UpgradeBar.style.position = '';
- }
+ return legend;
}
/********
* Section: Functions related to the flashes/sound/notifications
- * TODO: Annotate functions */
+/**
+ * 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()
+ */
+CM.Disp.CreateWhiteScreen = function() {
+ CM.Disp.WhiteScreen = document.createElement('div');
+ CM.Disp.WhiteScreen.id = 'CMWhiteScreen';
+ CM.Disp.WhiteScreen.style.width = '100%';
+ CM.Disp.WhiteScreen.style.height = '100%';
+ CM.Disp.WhiteScreen.style.backgroundColor = 'white';
+ CM.Disp.WhiteScreen.style.display = 'none';
+ CM.Disp.WhiteScreen.style.zIndex = '9999999999';
+ CM.Disp.WhiteScreen.style.position = 'absolute';
+ l('wrapper').appendChild(CM.Disp.WhiteScreen);
+}
+
+/**
+ * This function creates a flash depending on configs. It is called by all functions
+ * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {number} mode Sets the intensity of the flash, used to recursively dim flash
+ * All calls of function have use mode == 3
+ * @param {string} config The setting in CM.Config that is checked before creating the flash
+ */
CM.Disp.Flash = function(mode, config) {
if ((CM.Config[config] == 1 && mode == 3) || mode == 1) {
CM.Disp.WhiteScreen.style.opacity = '0.5';
@@ -1867,11 +1866,16 @@ CM.Disp.Flash = function(mode, config) {
CM.Disp.WhiteScreen.style.opacity = '1';
setTimeout(function() {CM.Disp.Flash(1, config);}, 1000/Game.fps);
}
- else if (mode == 0) {
- CM.Disp.WhiteScreen.style.display = 'none';
- }
+ else if (mode == 0) CM.Disp.WhiteScreen.style.display = 'none';
}
+/**
+ * This function plays a sound depending on configs. It is called by all functions
+ * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL)
+ * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound
+ * @param {string} volConfig The setting in CM.Config that is checked to determine volume
+ */
CM.Disp.PlaySound = function(url, sndConfig, volConfig) {
if (CM.Config[sndConfig] == 1) {
var sound = new realAudio(url);
@@ -1880,17 +1884,26 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) {
}
}
+/**
+ * This function creates a notifcation depending on configs. It is called by all functions
+ * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification
+ * @param {string} title The title of the to-be created notifications
+ * @param {string} message The text of the to-be created notifications
+ */
CM.Disp.Notification = function(notifyConfig, title, message) {
if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') {
var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'
- var notification = new Notification(title, {body: message, badge: CookieIcon});
+ notification = new Notification(title, {body: message, badge: CookieIcon});
}
}
/********
* Section: Functions related to updating the tab in the browser's tab-bar
- * TODO: Annotate functions */
+/**
+ * This function creates the Favicon, it is called by CM.DelayInit()
+ */
CM.Disp.CreateFavicon = function() {
CM.Disp.Favicon = document.createElement('link');
CM.Disp.Favicon.id = 'CMFavicon';
@@ -1899,20 +1912,23 @@ CM.Disp.CreateFavicon = function() {
document.getElementsByTagName('head')[0].appendChild(CM.Disp.Favicon);
}
+/**
+ * This function updates the Favicon depending on whether a Golden Cookie has spawned
+ * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon
+ * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie
+ */
CM.Disp.UpdateFavicon = function() {
if (CM.Config.Favicon == 1) {
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
- }
- else {
- CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
- }
- }
- else {
- CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
+ if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
+ else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
}
+ else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
}
+/**
+ * This function updates the tab title
+ * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies
+ */
CM.Disp.UpdateTitle = function() {
if (Game.OnAscend || CM.Config.Title == 0) {
document.title = CM.Cache.Title;
@@ -1920,63 +1936,53 @@ CM.Disp.UpdateTitle = function() {
else if (CM.Config.Title == 1) {
var addFC = false;
var addSP = false;
-
var titleGC;
var titleFC;
var titleSP;
- if (CM.Disp.lastGoldenCookieState) {
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
- else {
- titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
+
+ if (CM.Cache.spawnedGoldenShimmer) {
+ if (CM.Cache.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
+ else titleGC = '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
}
else if (!Game.Has('Golden switch [off]')) {
titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']';
}
- else {
- titleGC = '[GS]'
- }
- if (CM.Disp.lastTickerFortuneState) {
+ else titleGC = '[GS]'
+
+ if (CM.Main.lastTickerFortuneState) {
addFC = true;
titleFC = '[F]';
}
+
if (Game.season == 'christmas') {
addSP = true;
- if (CM.Disp.lastSeasonPopupState) {
- titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
- }
+ if (CM.Main.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']';
else {
titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']';
}
}
+ // Remove previous timers and add current cookies
var str = CM.Cache.Title;
if (str.charAt(0) == '[') {
str = str.substring(str.lastIndexOf(']') + 1);
}
-
document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str;
}
else if (CM.Config.Title == 2) {
var str = '';
var spawn = false;
- if (CM.Disp.lastGoldenCookieState) {
+ if (CM.Cache.spawnedGoldenShimmer) {
spawn = true;
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
- else {
- str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
+ if (CM.Cache.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
+ else str += '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
}
- if (CM.Disp.lastTickerFortuneState) {
+ if (CM.Main.lastTickerFortuneState) {
spawn = true;
str += '[F]';
}
- if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) {
- str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
+ if (Game.season == 'christmas' && CM.Main.lastSeasonPopupState) {
+ str += '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']';
spawn = true;
}
if (spawn) str += ' - ';
@@ -1989,8 +1995,12 @@ CM.Disp.UpdateTitle = function() {
/********
* Section: Functions related to the Golden Cookie Timers
- * TODO: Annotate functions */
+/**
+ * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie
+ * It is called by CM.Main.CheckGoldenCookie()
+ * @param {object} cookie A Golden Cookie object
+ */
CM.Disp.CreateGCTimer = function(cookie) {
GCTimer = document.createElement('div');
GCTimer.id = 'GCTimer' + cookie.id
@@ -2004,6 +2014,7 @@ CM.Disp.CreateGCTimer = function(cookie) {
GCTimer.style.fontSize = '35px';
GCTimer.style.cursor = 'pointer';
GCTimer.style.display = 'block';
+ if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none';
GCTimer.style.left = cookie.l.style.left;
GCTimer.style.top = cookie.l.style.top;
GCTimer.onclick = function () {cookie.pop();};
@@ -2014,160 +2025,35 @@ CM.Disp.CreateGCTimer = function(cookie) {
l('shimmers').appendChild(GCTimer);
}
+/**
+ * This function toggles GC Timers are visible
+ * It is called by a change in CM.Config.GCTimer
+ */
CM.Disp.ToggleGCTimer = function() {
if (CM.Config.GCTimer == 1) {
- if (CM.Disp.lastGoldenCookieState) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'block';
- CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left;
- CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top;
- }
+ for (var i in CM.Disp.GCTimers) {
+ CM.Disp.GCTimers[i].style.display = 'block';
+ CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left;
+ CM.Disp.GCTimers[i].style.top = CM.Cache.goldenShimmersByID[i].l.style.top;
}
}
else {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'none';
- }
- }
-}
-
-/********
- * Section: Functions related to checking for changes in Minigames/GC's/Ticker
- * TODO: Annotate functions
- * TODO: Possibly move this section */
-
-CM.Disp.CheckGoldenCookie = function() {
- CM.Disp.FindShimmer();
- for (var i in CM.Disp.GCTimers) {
- if (typeof CM.Disp.goldenShimmersByID[i] == "undefined") {
- CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
- // TODO remove delete here
- delete CM.Disp.GCTimers[i];
- }
- }
- if (CM.Disp.lastGoldenCookieState != Game.shimmerTypes['golden'].n) {
- CM.Disp.lastGoldenCookieState = Game.shimmerTypes['golden'].n;
- if (CM.Disp.lastGoldenCookieState) {
- if (CM.Disp.lastSpawnedGoldenCookieState < CM.Disp.currSpawnedGoldenCookieState) {
- CM.Disp.Flash(3, 'GCFlash');
- CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume');
- CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
- }
- CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState
- CM.Disp.UpdateFavicon();
-
- if (CM.Config.GCTimer == 1) {
- for (var i in Game.shimmers) {
- if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") {
- CM.Disp.CreateGCTimer(Game.shimmers[i]);
- }
- }
- }
- }
- else if (CM.Config.GCTimer == 1) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'none';
- }
- }
- }
- else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.opacity = CM.Disp.goldenShimmersByID[i].l.style.opacity;
- CM.Disp.GCTimers[i].style.transform = CM.Disp.goldenShimmersByID[i].l.style.transform;
- CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Disp.goldenShimmersByID[i].life / Game.fps);
- }
- }
-}
-
-CM.Disp.CheckTickerFortune = function() {
- if (CM.Disp.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) {
- CM.Disp.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune');
- if (CM.Disp.lastTickerFortuneState) {
- CM.Disp.Flash(3, 'FortuneFlash');
- CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
- CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.")
- }
- }
-}
-
-CM.Disp.CheckSeasonPopup = function() {
- if (CM.Disp.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) {
- CM.Disp.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned;
- if (CM.Disp.lastSeasonPopupState && Game.season=='christmas') {
- // Needed for some of the functions to use the right object
- for (var i in Game.shimmers) {
- if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') {
- CM.Disp.seasonPopShimmer = Game.shimmers[i];
- break;
- }
- }
-
- CM.Disp.Flash(3, 'SeaFlash');
- CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume');
- CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!")
- }
- }
-}
-
-CM.Disp.CheckGardenTick = function() {
- if (Game.Objects['Farm'].minigameLoaded && CM.Disp.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) {
- if (CM.Disp.lastGardenNextStep != 0 && CM.Disp.lastGardenNextStep < Date.now()) {
- CM.Disp.Flash(3, 'GardFlash');
- CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume');
- }
- CM.Disp.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep;
- }
-}
-
-CM.Disp.CheckMagicMeter = function() {
- if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) {
- var minigame = Game.Objects['Wizard tower'].minigame;
- if (minigame.magic < minigame.magicM) {
- CM.Disp.lastMagicBarFull = false;
- }
- else if (!CM.Disp.lastMagicBarFull) {
- CM.Disp.lastMagicBarFull = true;
- CM.Disp.Flash(3, 'MagicFlash');
- CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume');
- CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!")
- }
- }
-}
-
-CM.Disp.CheckWrinklerCount = function() {
- if (Game.elderWrath > 0) {
- var CurrentWrinklers = 0;
- for (var i in Game.wrinklers) {
- if (Game.wrinklers[i].phase == 2) CurrentWrinklers++;
- }
- if (CurrentWrinklers > CM.Disp.lastWrinklerCount) {
- CM.Disp.lastWrinklerCount = CurrentWrinklers
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) {
- CM.Disp.Flash(3, 'WrinklerMaxFlash');
- } else {
- CM.Disp.Flash(3, 'WrinklerFlash');
- }
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) {
- CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
- } else {
- CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
- }
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.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.Disp.lastWrinklerCount = CurrentWrinklers
- }
+ for (var i in CM.Disp.GCTimers) CM.Disp.GCTimers[i].style.display = 'none';
}
}
/********
* Section: Functions related to Tooltips
- * TODO: Annotate functions */
-CM.Disp.CreateTooltip = function(placeholder, text, minWidth) {
+/**
+ * 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()
+ * @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
+ */
+CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) {
CM.Disp[placeholder] = document.createElement('div');
var desc = document.createElement('div');
desc.style.minWidth = minWidth;
@@ -2179,33 +2065,216 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) {
CM.Disp[placeholder].appendChild(desc);
}
-CM.Disp.UpdateTooltipLocation = function() {
- if (Game.tooltip.origin == 'store') {
- var warnOffset = 0;
- if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4;
- Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px';
+/**
+ * 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();}');
+ }
}
- // Kept for future possible use if the code changes again
- /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
- Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px';
- }*/
}
-CM.Disp.CreateTooltipWarn = function() {
+/**
+ * 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
+ *
+ */
+CM.Disp.ReplaceTooltipUpgrade = function() {
+ CM.Disp.TooltipUpgradeBackup = [];
+ for (var i in Game.UpgradesInStore) {
+ var me = Game.UpgradesInStore[i];
+ if (l('upgrade' + i).onmouseover != null) {
+ CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover;
+ eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + 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'
+ * 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()
+ * @param {string} type Type of tooltip (b, u, s or g)
+ * @param {string} name Name of the object/item the tooltip relates to
+ * @returns {string} l('tooltip').innerHTML The HTML of the l('tooltip')-object
+ */
+CM.Disp.Tooltip = function(type, name) {
+ if (type == 'b') { // Buildings
+ l('tooltip').innerHTML = Game.Objects[name].tooltip();
+ // Adds amortization info to the list of info per building
+ if (CM.Config.TooltipAmor == 1) {
+ var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount);
+ var amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
+ if (amortizeAmount > 0) {
+ l('tooltip').innerHTML = l('tooltip').innerHTML
+ .split('so far')
+ .join('so far
• ' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')');
+ }
+ }
+ if (Game.buyMode == -1) {
+ /*
+ * Fix sell price displayed in the object tooltip.
+ *
+ * The buildings sell price displayed by the game itself (without any mod) is incorrect.
+ * The following line of code fixes this issue, and can be safely removed when the game gets fixed.
+ *
+ * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262
+ */
+ l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1)));
+ }
+ }
+ else if (type == 'u') { // Upgrades
+ if (!Game.UpgradesInStore[name]) return '';
+ l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store');
+ }
+ else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps
+ else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire
+
+ // Adds area for extra tooltip-sections
+ var area = document.createElement('div');
+ area.id = 'CMTooltipArea';
+ l('tooltip').appendChild(area);
+
+ // Sets global variables used by CM.Disp.UpdateTooltip()
+ CM.Disp.tooltipType = type;
+ CM.Disp.tooltipName = name;
+
+ CM.Disp.UpdateTooltip();
+
+ return l('tooltip').innerHTML;
+}
+
+/**
+ * This function creates a tooltipBox object which contains all CookieMonster added tooltip information.
+ * It is called by all CM.Disp.UpdateTooltip functions.
+ * @returns {object} div An object containing the stylized box
+ */
+CM.Disp.TooltipCreateTooltipBox = function() {
+ l('tooltip').firstChild.style.paddingBottom = '4px'; // Sets padding on base-tooltip
+ var tooltipBox = document.createElement('div');
+ tooltipBox.style.border = '1px solid';
+ tooltipBox.style.padding = '4px';
+ tooltipBox.style.margin = '0px -4px';
+ tooltipBox.id = 'CMTooltipBorder';
+ tooltipBox.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
+ return tooltipBox
+}
+
+/**
+ * This function creates a header object for tooltips.
+ * It is called by all CM.Disp.UpdateTooltip functions.
+ * @param {string} text Title of header
+ * @returns {object} div An object containing the stylized header
+ */
+CM.Disp.TooltipCreateHeader = function(text) {
+ var div = document.createElement('div');
+ div.style.fontWeight = 'bold';
+ div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
+ div.textContent = text;
+ return div;
+}
+
+/**
+ * This function appends the sections for Bonus Income, PP and Time left (to achiev) to the tooltip-object
+ * It is called by CM.Disp.UpdateTooltipBuilding() and CM.Disp.UpdateTooltipUpgrade()
+ * The actual data is added by the Update-functions themselves
+ * @param {object} tooltip Object of a TooltipBox, normally created by a call to CM.Disp.TooltipCreateTooltipBox()
+ */
+CM.Disp.TooltipCreateCalculationSection = function(tooltip) {
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Income'));
+ var income = document.createElement('div');
+ income.style.marginBottom = '4px';
+ income.style.color = 'white';
+ income.id = 'CMTooltipIncome';
+ tooltip.appendChild(income);
+
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period'));
+ var pp = document.createElement('div');
+ pp.style.marginBottom = '4px';
+ pp.id = 'CMTooltipPP';
+ tooltip.appendChild(pp);
+
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Time Left'));
+ var time = document.createElement('div');
+ time.id = 'CMTooltipTime';
+ tooltip.appendChild(time);
+
+ if (CM.Disp.tooltipType == 'b') {
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Production left till next achievement'));
+ tooltip.lastChild.id = 'CMTooltipProductionHeader'; // Assign a id in order to hid when no achiev's are left
+ var production = document.createElement('div');
+ production.id = 'CMTooltipProduction';
+ tooltip.appendChild(production);
+ }
+}
+
+/**
+ * This function creates the tooltip objectm for warnings
+ * It is called by CM.Disp.UpdateTooltipWarnings() whenever the tooltip type is 'b' or 'u'
+ * The object is also removed by CM.Disp.UpdateTooltipWarnings() when type is 's' or 'g'
+ * @returns {object} CM.Disp.TooltipWarn The Warnings-tooltip object
+ */
+CM.Disp.TooltipCreateWarningSection = function() {
CM.Disp.TooltipWarn = document.createElement('div');
CM.Disp.TooltipWarn.style.position = 'absolute';
- CM.Disp.TooltipWarn.style.display = 'none';
+ CM.Disp.TooltipWarn.style.display = 'block';
CM.Disp.TooltipWarn.style.left = 'auto';
CM.Disp.TooltipWarn.style.bottom = 'auto';
+ CM.Disp.TooltipWarn.id = "CMDispTooltipWarningParent";
var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) {
var box = document.createElement('div');
box.id = boxId;
box.style.display = 'none';
- box.style.WebkitTransition = 'opacity 0.1s ease-out';
- box.style.MozTransition = 'opacity 0.1s ease-out';
- box.style.MsTransition = 'opacity 0.1s ease-out';
- box.style.OTransition = 'opacity 0.1s ease-out';
+ // TODO: This is very old code and can probably be removed
+ //box.style.WebkitTransition = 'opacity 0.1s ease-out';
+ //box.style.MozTransition = 'opacity 0.1s ease-out';
+ //box.style.MsTransition = 'opacity 0.1s ease-out';
+ //box.style.OTransition = 'opacity 0.1s ease-out';
box.style.transition = 'opacity 0.1s ease-out';
box.className = CM.Disp.colorBorderPre + color;
box.style.padding = '2px';
@@ -2231,441 +2300,310 @@ CM.Disp.CreateTooltipWarn = function() {
CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText'));
CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px';
CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText'));
-
-
- l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn);
+
+ return CM.Disp.TooltipWarn;
}
-CM.Disp.ToggleToolWarnPos = function() {
- if (CM.Config.ToolWarnPos == 0) {
- CM.Disp.TooltipWarn.style.top = 'auto';
- CM.Disp.TooltipWarn.style.margin = '4px -4px';
- CM.Disp.TooltipWarn.style.padding = '3px 4px';
- }
- else {
- CM.Disp.TooltipWarn.style.right = 'auto';
- CM.Disp.TooltipWarn.style.margin = '4px';
- CM.Disp.TooltipWarn.style.padding = '4px 3px';
- }
-}
-
-CM.Disp.AddTooltipBuild = function() {
- CM.Disp.TooltipBuildBack = [];
- for (var i in Game.Objects) {
- var me = Game.Objects[i];
- if (l('product' + me.id).onmouseover != null) {
- CM.Disp.TooltipBuildBack[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 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()
+ */
+CM.Disp.UpdateTooltip = function() {
+ CM.Sim.CopyData();
+ if (l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea')) {
+ l('CMTooltipArea').innerHTML = '';
+ tooltipBox = CM.Disp.TooltipCreateTooltipBox();
+ l('CMTooltipArea').appendChild(tooltipBox);
+
+ if (CM.Disp.tooltipType == 'b') {
+ CM.Disp.UpdateTooltipBuilding();
}
- }
-}
-
-CM.Disp.AddTooltipUpgrade = function() {
- CM.Disp.TooltipUpgradeBack = [];
- for (var i in Game.UpgradesInStore) {
- var me = Game.UpgradesInStore[i];
- if (l('upgrade' + i).onmouseover != null) {
- CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover;
- eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}');
+ else if (CM.Disp.tooltipType == 'u') {
+ CM.Disp.UpdateTooltipUpgrade();
}
+ else if (CM.Disp.tooltipType === 's') {
+ CM.Disp.UpdateTooltipSugarLump();
+ }
+ else if (CM.Disp.tooltipType === 'g') {
+ CM.Disp.UpdateTooltipGrimoire();
+ }
+ CM.Disp.UpdateTooltipWarnings();
}
}
-CM.Disp.AddTooltipGrimoire = function() {
- if (Game.Objects['Wizard tower'].minigameLoaded) {
- CM.Disp.TooltipGrimoireBack = [];
- for (var i in Game.Objects['Wizard tower'].minigame.spellsById) {
- if (l('grimoireSpell' + i).onmouseover != null) {
- CM.Disp.TooltipGrimoireBack[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 adds extra info to the Building tooltips
+ * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip()
+ */
+CM.Disp.UpdateTooltipBuilding = function() {
+ if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
+ tooltipBox = l('CMTooltipBorder');
+ CM.Disp.TooltipCreateCalculationSection(tooltipBox);
+
+ var target = '';
+ // TODO: Change the Cache code and variables to use Objects1, Objectes10, Objects100
+ // That would depreciate this target setting code
+ if (Game.buyMode == 1 && Game.buyBulk == 10) target = 'Objects10'
+ else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100';
+ else target = 'Objects';
+
+ var price = Game.Objects[CM.Disp.tooltipName].bulkPrice
+ CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus;
+
+
+ if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
+ l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2);
+ var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000);
+ if (isFinite(increase) && increase != 0) {
+ l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
}
+ l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
+ l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
+ l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
+ var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ l('CMTooltipTime').textContent = timeColor.text;
+ l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
+ }
+
+ // Add "production left till next achievement"-bar
+ for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) {
+ if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) {
+ var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i]
+ break
+ }
+ }
+ if (typeof nextProductionAchiev != "undefined") {
+ l('CMTooltipTime').style.marginBottom = '4px';
+ l('CMTooltipProductionHeader').style.display = "";
+ l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName;
+ l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15);
+ l('CMTooltipProduction').style.color = "white";
+ } else {
+ l('CMTooltipProductionHeader').style.display = "none";
+ l('CMTooltipTime').style.marginBottom = '0px';
}
}
}
/**
- * This function improves Sugar Lump tooltip by adding extra infromation.
- * @constructor
+ * This function adds extra info to the Upgrade tooltips
+ * It is called when Upgrade tooltips are created or refreshed by CM.Disp.UpdateTooltip()
*/
-CM.Disp.AddTooltipLump = function() {
- if (Game.canLumps()) {
- CM.Disp.TooltipLumpBack = 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();}');
- }
-};
+CM.Disp.UpdateTooltipUpgrade = function() {
+ tooltipBox = l('CMTooltipBorder');
+ CM.Disp.TooltipCreateCalculationSection(tooltipBox);
-CM.Disp.Tooltip = function(type, name) {
- if (type == 'b') {
- l('tooltip').innerHTML = Game.Objects[name].tooltip();
- if (CM.Config.TooltipAmor == 1) {
- var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount);
- var amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
- if (amortizeAmount > 0) {
- l('tooltip').innerHTML = l('tooltip').innerHTML
- .split('so far')
- .join('so far
• ' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')');
- }
- }
- if (Game.buyMode == 1) {
- var target = '';
- var change = false;
- if (Game.buyBulk == 10) {
- target = 'Objects10';
- change = true;
- }
- else if (Game.buyBulk == 100) {
- target = 'Objects100';
- change = true;
- }
- if (change) {
- l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price));
- }
- }
- else if (Game.buyMode == -1) {
- /*
- * Fix sell price displayed in the object tooltip.
- *
- * The buildings sell price displayed by the game itself (without any mod) is incorrect.
- * The following line of code fixes this issue, and can be safely removed when the game gets fixed.
- *
- * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262
- */
- l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1)));
+ CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
+ price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
+
+ if (CM.Config.TooltipBuildUp == 1) {
+ l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2);
+ var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000);
+ if (isFinite(increase) && increase != 0) {
+ l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
}
+ l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
+ l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
+ l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
+ var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ l('CMTooltipTime').textContent = timeColor.text;
+ l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
}
- else if (type == 'u') {
- if (!Game.UpgradesInStore[name]) return '';
- l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store');
- }
- else if (type === 's') {
- // Sugar Lump
- l('tooltip').innerHTML = Game.lumpTooltip();
- }
- else { // Grimoire
- l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)();
- }
-
- var area = document.createElement('div');
- area.id = 'CMTooltipArea';
- l('tooltip').appendChild(area);
-
- if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) {
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var tooltip = document.createElement('div');
- tooltip.style.border = '1px solid';
- tooltip.style.padding = '4px';
- tooltip.style.margin = '0px -4px';
- tooltip.id = 'CMTooltipBorder';
-
- var header = function(text) {
- var div = document.createElement('div');
- div.style.fontWeight = 'bold';
- div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- div.textContent = text;
- return div;
- }
-
- tooltip.appendChild(header('Bonus Income'));
- var income = document.createElement('div');
- income.style.marginBottom = '4px';
- income.style.color = 'white';
- income.id = 'CMTooltipIncome';
- tooltip.appendChild(income);
- tooltip.appendChild(header('Payback Period'));
- var pp = document.createElement('div');
- pp.style.marginBottom = '4px';
- pp.id = 'CMTooltipPP';
- tooltip.appendChild(pp);
- tooltip.appendChild(header('Time Left'));
- var time = document.createElement('div');
- time.id = 'CMTooltipTime';
- tooltip.appendChild(time);
- if (type == 'b') {
- tooltip.appendChild(header('Production left till next achievement'));
- tooltip.lastChild.id = 'CMTooltipProductionHeader';
- var production = document.createElement('div');
- production.id = 'CMTooltipProduction';
- tooltip.appendChild(production);
- }
-
- area.appendChild(tooltip);
- }
-
- CM.Disp.tooltipType = type;
- CM.Disp.tooltipName = name;
-
- CM.Disp.UpdateTooltip();
-
- return l('tooltip').innerHTML;
}
-CM.Disp.UpdateTooltip = function() {
- CM.Sim.CopyData();
- if (l('tooltipAnchor').style.display != 'none') {
+/**
+ * This function adds extra info to the Sugar Lump tooltip
+ * It is called when the Sugar Lump tooltip is created or refreshed by CM.Disp.UpdateTooltip()
+ * It adds to the additional information to l('CMTooltipArea')
+ */
+CM.Disp.UpdateTooltipSugarLump = function() {
+ if (CM.Config.TooltipLump === 1) {
+ tooltipBox = l('CMTooltipBorder');
- if (l('CMTooltipArea') != null) {
- if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') {
- // Error checking
- if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) {
- return;
- }
- var price;
- var bonus;
- if (CM.Disp.tooltipType == 'b') {
- var target = '';
- if (Game.buyMode == 1 && Game.buyBulk == 10) {
- target = 'Objects10';
- price = CM.Cache[target][CM.Disp.tooltipName].price;
- }
- else if (Game.buyMode == 1 && Game.buyBulk == 100) {
- target = 'Objects100';
- price = CM.Cache[target][CM.Disp.tooltipName].price;
- }
- else {
- target = 'Objects';
- price = Game.Objects[CM.Disp.tooltipName].getPrice();
- }
- bonus = CM.Cache[target][CM.Disp.tooltipName].bonus;
- if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
- l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
- l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
- l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
- }
- if (CM.Config.TooltipBuildUp) {
- for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) {
- if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) {
- var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i]
- break
- }
- }
- if (typeof nextProductionAchiev != "undefined") {
- l('CMTooltipTime').style.marginBottom = '4px';
- l('CMTooltipProductionHeader').style.display = "";
- l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName;
- l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15);
- l('CMTooltipProduction').style.color = "white";
- } else {
- l('CMTooltipProductionHeader').style.display = "none";
- l('CMTooltipTime').style.marginBottom = '0px';
- }
- }
- }
- else { // Upgrades
- bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
- price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
- if (CM.Config.TooltipBuildUp == 1) {
- l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
- l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
- l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
- }
- }
- if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- l('CMTooltipIncome').textContent = Beautify(bonus, 2);
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump'));
- var increase = Math.round(bonus / Game.cookiesPs * 10000);
- if (isFinite(increase) && increase != 0) {
- l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
- }
+ var lumpType = document.createElement('div');
+ lumpType.id = 'CMTooltipTime';
+ tooltipBox.appendChild(lumpType);
+ var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType);
+ lumpType.textContent = lumpColor.text;
+ lumpType.className = CM.Disp.colorTextPre + lumpColor.color;
+ }
+}
- var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
- l('CMTooltipTime').textContent = timeColor.text;
- l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
- }
+/**
+ * This function adds extra info to the Grimoire tooltips
+ * It is called when Grimoire tooltips are created or refreshed by CM.Disp.UpdateTooltip()
+ * It adds to the additional information to l('CMTooltipArea')
+ */
+CM.Disp.UpdateTooltipGrimoire = function() {
+ var minigame = Game.Objects['Wizard tower'].minigame;
+ var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]);
- if (CM.Config.ToolWarnPos == 0) {
- CM.Disp.TooltipWarn.style.right = '0px';
- }
- else {
- CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px';
- }
- CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px';
+ if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) {
+ tooltipBox = l('CMTooltipBorder');
- if (CM.Config.ToolWarnLucky == 1) {
- CM.Disp.TooltipWarn.style.display = 'block';
- var limitLucky = CM.Cache.Lucky;
- if (CM.Config.ToolWarnBon == 1) {
- var bonusNoFren = bonus;
- bonusNoFren /= CM.Sim.getCPSBuffMult();
- limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
- }
- var limitLuckyFrenzy = limitLucky * 7;
- var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
- if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- if (amount < limitLucky) {
- l('CMDispTooltipWarnLucky').style.display = '';
- l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
- l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
- }
- else if (amount < limitLuckyFrenzy) {
- l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
- l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
- l('CMDispTooltipWarnLucky').style.display = 'none';
- }
- } else {
- l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- }
+ // Time left till enough magic for spell
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Time Left'));
+ var time = document.createElement('div');
+ time.id = 'CMTooltipTime';
+ tooltipBox.appendChild(time);
+ var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost));
+ time.textContent = timeColor.text;
+ time.className = CM.Disp.colorTextPre + timeColor.color;
+
+ // Time left untill magic spent is recovered
+ if (spellCost <= minigame.magic) {
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Recover Time'));
+ var recover = document.createElement('div');
+ recover.id = 'CMTooltipRecover';
+ tooltipBox.appendChild(recover);
+ var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic));
+ recover.textContent = recoverColor.text;
+ recover.className = CM.Disp.colorTextPre + recoverColor.color;
+ }
+
+ // Extra information on cookies gained when spell is Conjure Baked Goods (Name == 0)
+ if (CM.Disp.tooltipName == 0) {
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained/lost'));
+ var conjure = document.createElement('div');
+ conjure.id = 'CMTooltipConjure';
+ tooltipBox.appendChild(conjure);
+ var reward = document.createElement('span');
+ reward.style.color = "#33FF00"
+ reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2)
+ conjure.appendChild(reward)
+ var seperator = document.createElement('span');
+ seperator.textContent = ' / '
+ conjure.appendChild(seperator)
+ var loss = document.createElement('span');
+ loss.style.color = "red"
+ loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2);
+ conjure.appendChild(loss)
+ }
+
+ l('CMTooltipArea').appendChild(tooltipBox);
+ }
+}
+
+/**
+ * This function updates the warnings section of the building and upgrade tooltips
+ * It is called by CM.Disp.UpdateTooltip()
+ */
+CM.Disp.UpdateTooltipWarnings = function() {
+ if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") {
+ if (document.getElementById("tooltipWarn") == null) {
+ warningTooltip = CM.Disp.TooltipCreateWarningSection();
+ l('tooltipAnchor').appendChild(warningTooltip);
+ }
+
+ if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px';
+ else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px';
+
+ CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px';
+
+ if (CM.Config.ToolWarnLucky == 1) {
+ var limitLucky = CM.Cache.Lucky;
+ if (CM.Config.ToolWarnBon == 1) {
+ var bonusNoFren = CM.Disp.TooltipBonusIncome;
+ bonusNoFren /= CM.Sim.getCPSBuffMult();
+ limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
+ }
+ var limitLuckyFrenzy = limitLucky * 7;
+ var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
+ if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
+ if (amount < limitLucky) {
+ l('CMDispTooltipWarnLucky').style.display = '';
+ l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')';
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
+ l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
}
- else {
+ else if (amount < limitLuckyFrenzy) {
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
+ l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
}
-
- if (CM.Config.ToolWarnConjure == 1) {
- CM.Disp.TooltipWarn.style.display = 'block';
- var limitLucky = CM.Cache.Lucky;
- if (CM.Config.ToolWarnBon == 1) {
- var bonusNoFren = bonus;
- bonusNoFren /= CM.Sim.getCPSBuffMult();
- limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
- }
- var limitConjure = limitLucky * 2;
- var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
- if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- l('CMDispTooltipWarnConjure').style.display = '';
- l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')';
- } else {
- l('CMDispTooltipWarnConjure').style.display = 'none';
- }
- }
- else {
- l('CMDispTooltipWarnConjure').style.display = 'none';
- }
- }
- else if (CM.Disp.tooltipType === 's') {
- // Adding information about Sugar Lumps.
-
- CM.Disp.TooltipWarn.style.display = 'none';
- l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- l('CMDispTooltipWarnConjure').style.display = 'none';
-
- if (CM.Config.TooltipLump === 1) {
- l('CMTooltipArea').innerHTML = '';
-
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var lumpTooltip = document.createElement('div');
- lumpTooltip.style.border = '1px solid';
- lumpTooltip.style.padding = '4px';
- lumpTooltip.style.margin = '0px -4px';
- lumpTooltip.id = 'CMTooltipBorder';
- lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
-
- var lumpHeader = document.createElement('div');
- lumpHeader.style.fontWeight = 'bold';
- lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- lumpHeader.textContent = 'Current Sugar Lump';
-
- lumpTooltip.appendChild(lumpHeader);
- var lumpType = document.createElement('div');
- lumpType.id = 'CMTooltipTime';
- lumpTooltip.appendChild(lumpType);
- var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType);
- lumpType.textContent = lumpColor.text;
- lumpType.className = CM.Disp.colorTextPre + lumpColor.color;
-
- l('CMTooltipArea').appendChild(lumpTooltip);
- }
- }
- else if (CM.Disp.tooltipType === 'g') {
- // Grimoire
- CM.Disp.TooltipWarn.style.display = 'none';
+ } else {
l('CMDispTooltipWarnLucky').style.display = 'none';
l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- l('CMDispTooltipWarnConjure').style.display = 'none';
-
- var minigame = Game.Objects['Wizard tower'].minigame;
- var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]);
-
- if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) {
- l('CMTooltipArea').innerHTML = '';
-
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var tooltip = document.createElement('div');
- tooltip.style.border = '1px solid';
- tooltip.style.padding = '4px';
- tooltip.style.margin = '0px -4px';
- tooltip.id = 'CMTooltipBorder';
- tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
-
- var header = function(text) {
- var div = document.createElement('div');
- div.style.fontWeight = 'bold';
- div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- div.textContent = text;
- return div;
- }
-
- tooltip.appendChild(header('Time Left'));
- var time = document.createElement('div');
- time.id = 'CMTooltipTime';
- tooltip.appendChild(time);
- var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost));
- time.textContent = timeColor.text;
- time.className = CM.Disp.colorTextPre + timeColor.color;
-
- if (spellCost <= minigame.magic) {
- tooltip.appendChild(header('Recover Time'));
- var recover = document.createElement('div');
- recover.id = 'CMTooltipRecover';
- tooltip.appendChild(recover);
- var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic));
- recover.textContent = recoverColor.text;
- recover.className = CM.Disp.colorTextPre + recoverColor.color;
- }
-
- // Extra information when spell is Conjure Baked Goods (Name == 0)
- if (CM.Disp.tooltipName == 0) {
- tooltip.appendChild(header('Cookies to be gained/lost'));
- var conjure = document.createElement('div');
- conjure.id = 'CMTooltipConjure';
- tooltip.appendChild(conjure);
- var reward = document.createElement('span');
- reward.style.color = "#33FF00"
- reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2)
- conjure.appendChild(reward)
- var seperator = document.createElement('span');
- seperator.textContent = ' / '
- conjure.appendChild(seperator)
- var loss = document.createElement('span');
- loss.style.color = "red"
- loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2);
- conjure.appendChild(loss)
- }
-
- l('CMTooltipArea').appendChild(tooltip);
- }
}
}
else {
- CM.Disp.TooltipWarn.style.display = 'none';
+ l('CMDispTooltipWarnLucky').style.display = 'none';
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
+ }
+
+ if (CM.Config.ToolWarnConjure == 1) {
+ var limitLucky = CM.Cache.Lucky;
+ if (CM.Config.ToolWarnBon == 1) {
+ var bonusNoFren = CM.Disp.TooltipBonusIncome;
+ bonusNoFren /= CM.Sim.getCPSBuffMult();
+ limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
+ }
+ var limitConjure = limitLucky * 2;
+ var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
+ if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
+ l('CMDispTooltipWarnConjure').style.display = '';
+ l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')';
+ } else {
+ l('CMDispTooltipWarnConjure').style.display = 'none';
+ }
+ }
+ else {
+ l('CMDispTooltipWarnConjure').style.display = 'none';
+ }
+ }
+ else {
+ if (l('CMDispTooltipWarningParent') != null) {
+ l('CMDispTooltipWarningParent').remove();
}
}
}
-CM.Disp.DrawTooltipWarn = function() {
- if (CM.Config.ToolWarnLucky == 1) {
- l('CMDispTooltipWarnLucky').style.opacity = '0';
- l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0';
+/**
+ * This function updates the location of the tooltip
+ * It is called by Game.tooltip.update() because of CM.ReplaceNative()
+ */
+CM.Disp.UpdateTooltipLocation = function() {
+ if (Game.tooltip.origin == 'store') {
+ var warnOffset = 0;
+ if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") {
+ warnOffset = CM.Disp.TooltipWarn.clientHeight - 4;
+ }
+ Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px';
}
- if (CM.Config.ToolWarnConjure == 1) {
- l('CMDispTooltipWarnConjure').style.opacity = '0';
- }
-}
-
-CM.Disp.UpdateTooltipWarn = function() {
- if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) {
- l('CMDispTooltipWarnLucky').style.opacity = '1';
- l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1';
- }
- if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) {
- l('CMDispTooltipWarnConjure').style.opacity = '1';
+ // Kept for future possible use if the code changes again
+ /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
+ Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px';
+ }*/
+}
+
+/**
+ * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection()
+ * It is called by a change in CM.Config.ToolWarnPos
+ */
+CM.Disp.ToggleToolWarnPos = function() {
+ if (typeof CM.Disp.TooltipWarn != "undefined") {
+ if (CM.Config.ToolWarnPos == 0) {
+ CM.Disp.TooltipWarn.style.top = 'auto';
+ CM.Disp.TooltipWarn.style.margin = '4px -4px';
+ CM.Disp.TooltipWarn.style.padding = '3px 4px';
+ }
+ else {
+ CM.Disp.TooltipWarn.style.right = 'auto';
+ CM.Disp.TooltipWarn.style.margin = '4px';
+ CM.Disp.TooltipWarn.style.padding = '4px 3px';
+ }
}
}
+/**
+ * This function checks and create a tooltip for the wrinklers
+ * It is called by CM.Loop()
+ * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w")
+ */
CM.Disp.CheckWrinklerTooltip = function() {
- if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) {
+ if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect
var showingTooltip = false;
for (var i in Game.wrinklers) {
var me = Game.wrinklers[i];
@@ -2697,6 +2635,11 @@ 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()
+ * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip()
+ */
CM.Disp.UpdateWrinklerTooltip = function() {
if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) {
var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked;
@@ -2719,6 +2662,10 @@ CM.Disp.UpdateWrinklerTooltip = function() {
* Section: General functions related to the Options/Stats pages
* TODO: Annotate functions */
+/**
+ * This function adds the calll the functions to add extra info to the stats and options pages
+ * It is called by Game.UpdateMenu()
+ */
CM.Disp.AddMenu = function() {
var title = function() {
var div = document.createElement('div');
@@ -2734,52 +2681,96 @@ CM.Disp.AddMenu = function() {
if (CM.Config.Stats) {
CM.Disp.AddMenuStats(title);
}
-
- if (CM.Config.MissingUpgrades) {
- CM.Disp.AddMissingUpgrades();
- }
}
}
+/**
+ * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens
+ * It is called by CM.Loop()
+ */
CM.Disp.RefreshMenu = function() {
if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu();
}
/********
- * Section: Functions related to the Options page
- * TODO: Annotate functions */
-
-CM.Disp.AddMenuPref = function(title) {
- var header = function(text, config) {
- var div = document.createElement('div');
- div.className = 'listing';
- div.style.padding = '5px 16px';
- div.style.opacity = '0.7';
- div.style.fontSize = '17px';
- div.style.fontFamily = '\"Kavoon\", Georgia, serif';
- div.appendChild(document.createTextNode(text + ' '));
- var span = document.createElement('span');
- span.style.cursor = 'pointer';
- span.style.display = 'inline-block';
- span.style.height = '14px';
- span.style.width = '14px';
- span.style.borderRadius = '7px';
- span.style.textAlign = 'center';
- span.style.backgroundColor = '#C0C0C0';
- span.style.color = 'black';
- span.style.fontSize = '13px';
- span.style.verticalAlign = 'middle';
- span.textContent = CM.Config.MenuPref[config] ? '-' : '+';
- span.onclick = function() {CM.ToggleMenuConfig(config); Game.UpdateMenu();};
- div.appendChild(span);
- return div;
- }
+ * Section: Functions related to the Options/Preferences page
+/**
+ * This function adds the options/settings of CookieMonster to the options page
+ * It is called by CM.Disp.AddMenu
+ * @param {function} title A function that returns the title of CookieMonster pre-styled
+ */
+CM.Disp.AddMenuPref = function(title) {
var frag = document.createDocumentFragment();
-
frag.appendChild(title());
- var listing = function(config) {
+ for (var group in CM.ConfigGroups) {
+ groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group)
+ frag.appendChild(groupObject)
+ if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed
+ for (var option in CM.ConfigData) {
+ if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option))
+ }
+ }
+ }
+
+ var resDef = document.createElement('div');
+ resDef.className = 'listing';
+ var resDefBut = document.createElement('a');
+ resDefBut.className = 'option';
+ resDefBut.onclick = function() {CM.RestoreDefault();};
+ resDefBut.textContent = 'Restore Default';
+ resDef.appendChild(resDefBut);
+ frag.appendChild(resDef);
+
+ l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]);
+
+ // TODO: What does this do? @DanielNoord
+ CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick;
+ eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();'));
+ //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();};
+}
+
+/**
+ * This function creates a header-object for the options page
+ * It is called by CM.Disp.AddMenuPref()
+ * @param {string} config The name of the Config-group
+ * @param {string} text The to-be displayed name of the header
+ * @returns {object} div The header object
+ */
+CM.Disp.CreatePrefHeader = function(config, text) {
+ var div = document.createElement('div');
+ div.className = 'listing';
+ div.style.padding = '5px 16px';
+ div.style.opacity = '0.7';
+ div.style.fontSize = '17px';
+ div.style.fontFamily = '\"Kavoon\", Georgia, serif';
+ div.appendChild(document.createTextNode(text + ' '));
+ var span = document.createElement('span'); // Creates the +/- button
+ span.style.cursor = 'pointer';
+ span.style.display = 'inline-block';
+ span.style.height = '14px';
+ span.style.width = '14px';
+ span.style.borderRadius = '7px';
+ span.style.textAlign = 'center';
+ span.style.backgroundColor = '#C0C0C0';
+ span.style.color = 'black';
+ span.style.fontSize = '13px';
+ span.style.verticalAlign = 'middle';
+ span.textContent = CM.Config.OptionsPref[config] ? '-' : '+';
+ span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();};
+ div.appendChild(span);
+ return div;
+}
+
+/**
+ * This function creates an option-object for the options page
+ * It is called by CM.Disp.AddMenuPref()
+ * @param {string} config The name of the option
+ * @returns {object} div The option object
+ */
+CM.Disp.CreatePrefOption = function(config) {
+ if (CM.ConfigData[config].type == "bool") {
var div = document.createElement('div');
div.className = 'listing';
var a = document.createElement('a');
@@ -2798,8 +2789,7 @@ CM.Disp.AddMenuPref = function(title) {
div.appendChild(label);
return div;
}
-
- var vol = function(config) {
+ else if (CM.ConfigData[config].type == "vol") {
var volConfig = config;
var volume = document.createElement('div');
volume.className = 'listing';
@@ -2822,8 +2812,7 @@ CM.Disp.AddMenuPref = function(title) {
volume.appendChild(volLabel);
return volume;
}
-
- var url = function(config) {
+ else if (CM.ConfigData[config].type == "url") {
var div = document.createElement('div');
div.className = 'listing';
var span = document.createElement('span');
@@ -2854,18 +2843,7 @@ CM.Disp.AddMenuPref = function(title) {
div.appendChild(label);
return div;
}
-
- frag.appendChild(header('Bars/Colors', 'BarsColors'));
- if (CM.Config.MenuPref.BarsColors) {
- frag.appendChild(listing('BotBar'));
- frag.appendChild(listing('TimerBar'));
- frag.appendChild(listing('TimerBarPos'));
- frag.appendChild(listing('SortBuildings'));
- frag.appendChild(listing('SortUpgrades'));
- frag.appendChild(listing('BuildColor'));
- frag.appendChild(listing('BulkBuildColor'));
- frag.appendChild(listing('ColorPPBulkMode'));
- frag.appendChild(listing('UpBarColor'));
+ else if (CM.ConfigData[config].type == "color") {
for (var i = 0; i < CM.Disp.colors.length; i++) {
var div = document.createElement('div');
div.className = 'listing';
@@ -2880,101 +2858,9 @@ CM.Disp.AddMenuPref = function(title) {
var label = document.createElement('label');
label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]];
div.appendChild(label);
- frag.appendChild(div);
+ return div;
}
- frag.appendChild(listing('UpgradeBarFixedPos'));
}
-
- frag.appendChild(header('Calculation', 'Calculation'));
- if (CM.Config.MenuPref.Calculation) {
- frag.appendChild(listing('CalcWrink'));
- frag.appendChild(listing('CPSMode'));
- frag.appendChild(listing('AvgCPSHist'));
- frag.appendChild(listing('AvgClicksHist'));
- frag.appendChild(listing('ToolWarnBon'));
- }
-
- frag.appendChild(header('Notification', 'Notification'));
- if (CM.Config.MenuPref.Notification) {
- frag.appendChild(listing('GCNotification'));
- frag.appendChild(listing('GCFlash'));
- frag.appendChild(listing('GCSound'));
- frag.appendChild(vol('GCVolume'));
- frag.appendChild(url('GCSoundURL'));
- frag.appendChild(listing('GCTimer'));
- frag.appendChild(listing('Favicon'));
- frag.appendChild(listing('FortuneNotification'));
- frag.appendChild(listing('FortuneFlash'));
- frag.appendChild(listing('FortuneSound'));
- frag.appendChild(vol('FortuneVolume'));
- frag.appendChild(url('FortuneSoundURL'));
- frag.appendChild(listing('SeaNotification'));
- frag.appendChild(listing('SeaFlash'));
- frag.appendChild(listing('SeaSound'));
- frag.appendChild(vol('SeaVolume'));
- frag.appendChild(url('SeaSoundURL'));
- frag.appendChild(listing('GardFlash'));
- frag.appendChild(listing('GardSound'));
- frag.appendChild(vol('GardVolume'));
- frag.appendChild(url('GardSoundURL'));
- frag.appendChild(listing('MagicNotification'));
- frag.appendChild(listing('MagicFlash'));
- frag.appendChild(listing('MagicSound'));
- frag.appendChild(vol('MagicVolume'));
- frag.appendChild(url('MagicSoundURL'));
- frag.appendChild(listing('WrinklerNotification'));
- frag.appendChild(listing('WrinklerFlash'));
- frag.appendChild(listing('WrinklerSound'));
- frag.appendChild(vol('WrinklerVolume'));
- frag.appendChild(url('WrinklerSoundURL'));
- frag.appendChild(listing('WrinklerMaxNotification'));
- frag.appendChild(listing('WrinklerMaxFlash'));
- frag.appendChild(listing('WrinklerMaxSound'));
- frag.appendChild(vol('WrinklerMaxVolume'));
- frag.appendChild(url('WrinklerMaxSoundURL'));
- frag.appendChild(listing('Title'));
- }
-
- frag.appendChild(header('Tooltip', 'Tooltip'));
- if (CM.Config.MenuPref.Tooltip) {
- frag.appendChild(listing('TooltipBuildUp'));
- frag.appendChild(listing('TooltipAmor'));
- frag.appendChild(listing('ToolWarnLucky'));
- frag.appendChild(listing('ToolWarnConjure'));
- frag.appendChild(listing('ToolWarnPos'));
- frag.appendChild(listing('TooltipGrim'));
- frag.appendChild(listing('ToolWrink'));
- frag.appendChild(listing('TooltipLump'));
- }
-
- frag.appendChild(header('Statistics', 'Statistics'));
- if (CM.Config.MenuPref.Statistics) {
- frag.appendChild(listing('Stats'));
- frag.appendChild(listing('MissingUpgrades'));
- frag.appendChild(listing('UpStats'));
- frag.appendChild(listing('TimeFormat'));
- frag.appendChild(listing('SayTime'));
- frag.appendChild(listing('GrimoireBar'));
- }
-
- frag.appendChild(header('Other', 'Other'));
- if (CM.Config.MenuPref.Other) {
- frag.appendChild(listing('Scale'));
- var resDef = document.createElement('div');
- resDef.className = 'listing';
- var resDefBut = document.createElement('a');
- resDefBut.className = 'option';
- resDefBut.onclick = function() {CM.RestoreDefault();};
- resDefBut.textContent = 'Restore Default';
- resDef.appendChild(resDefBut);
- frag.appendChild(resDef);
- }
-
- l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]);
-
- CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick;
- eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();'));
- //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();};
}
/********
@@ -2982,34 +2868,8 @@ CM.Disp.AddMenuPref = function(title) {
* TODO: Annotate functions */
CM.Disp.AddMenuStats = function(title) {
- var header = function(text, config) {
- var div = document.createElement('div');
- div.className = 'listing';
- div.style.padding = '5px 16px';
- div.style.opacity = '0.7';
- div.style.fontSize = '17px';
- div.style.fontFamily = '\"Kavoon\", Georgia, serif';
- div.appendChild(document.createTextNode(text + ' '));
- var span = document.createElement('span');
- span.style.cursor = 'pointer';
- span.style.display = 'inline-block';
- span.style.height = '14px';
- span.style.width = '14px';
- span.style.borderRadius = '7px';
- span.style.textAlign = 'center';
- span.style.backgroundColor = '#C0C0C0';
- span.style.color = 'black';
- span.style.fontSize = '13px';
- span.style.verticalAlign = 'middle';
- span.textContent = CM.Config.StatsPref[config] ? '-' : '+';
- span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();};
- div.appendChild(span);
- return div;
- }
-
var stats = document.createElement('div');
stats.className = 'subsection';
-
stats.appendChild(title());
var listing = function(name, text) {
@@ -3085,7 +2945,7 @@ CM.Disp.AddMenuStats = function(title) {
var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder';
- stats.appendChild(header('Lucky Cookies', 'Lucky'));
+ stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky'));
if (CM.Config.StatsPref.Lucky) {
var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : '';
@@ -3129,7 +2989,7 @@ CM.Disp.AddMenuStats = function(title) {
stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''))));
}
- stats.appendChild(header('Chain Cookies', 'Chain'));
+ stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain'));
if (CM.Config.StatsPref.Chain) {
var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : '';
@@ -3202,7 +3062,7 @@ CM.Disp.AddMenuStats = function(title) {
stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath))));
}
- stats.appendChild(header('Conjure Baked Goods', 'Conjure'));
+ stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure'));
if (CM.Config.StatsPref.Conjure) {
var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30);
@@ -3227,7 +3087,7 @@ CM.Disp.AddMenuStats = function(title) {
var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below
- stats.appendChild(header('Prestige', 'Prestige'));
+ stats.appendChild(CreateStatsHeader('Prestige', 'Prestige'));
if (CM.Config.StatsPref.Prestige) {
var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)));
var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0));
@@ -3305,7 +3165,7 @@ CM.Disp.AddMenuStats = function(title) {
}
if (Game.cpsSucked > 0) {
- stats.appendChild(header('Wrinklers', 'Wrink'));
+ stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink'));
if (CM.Config.StatsPref.Wrink) {
var popAllFrag = document.createDocumentFragment();
popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' '));
@@ -3358,7 +3218,7 @@ CM.Disp.AddMenuStats = function(title) {
var centEgg = Game.Has('Century egg');
if (Game.season == 'christmas' || specDisp || choEgg || centEgg) {
- stats.appendChild(header('Season Specials', 'Sea'));
+ stats.appendChild(CreateStatsHeader('Season Specials', 'Sea'));
if (CM.Config.StatsPref.Sea) {
if (specDisp) {
if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook)));
@@ -3378,7 +3238,7 @@ CM.Disp.AddMenuStats = function(title) {
}
}
- stats.appendChild(header('Miscellaneous', 'Misc'));
+ stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc'));
if (CM.Config.StatsPref.Misc) {
stats.appendChild(listing(
'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')',
@@ -3402,6 +3262,42 @@ CM.Disp.AddMenuStats = function(title) {
}
l('menu').insertBefore(stats, l('menu').childNodes[2]);
+
+ if (CM.Config.MissingUpgrades) {
+ CM.Disp.AddMissingUpgrades();
+ }
+}
+
+/**
+ * This function creates a header-object for the stats page
+ * It is called by CM.Disp.AddMenuStats()
+ * @param {string} config The name of the Config-group
+ * @param {string} text The to-be displayed name of the header
+ * @returns {object} div The header object
+ */
+CM.Disp.CreateStatsHeader = function(text, config) {
+ var div = document.createElement('div');
+ div.className = 'listing';
+ div.style.padding = '5px 16px';
+ div.style.opacity = '0.7';
+ div.style.fontSize = '17px';
+ div.style.fontFamily = '\"Kavoon\", Georgia, serif';
+ div.appendChild(document.createTextNode(text + ' '));
+ var span = document.createElement('span');
+ span.style.cursor = 'pointer';
+ span.style.display = 'inline-block';
+ span.style.height = '14px';
+ span.style.width = '14px';
+ span.style.borderRadius = '7px';
+ span.style.textAlign = 'center';
+ span.style.backgroundColor = '#C0C0C0';
+ span.style.color = 'black';
+ span.style.fontSize = '13px';
+ span.style.verticalAlign = 'middle';
+ span.textContent = CM.Config.StatsPref[config] ? '-' : '+';
+ span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();};
+ div.appendChild(span);
+ return div;
}
CM.Disp.AddMissingUpgrades = function() {
@@ -3483,11 +3379,35 @@ CM.Disp.AddMissingUpgrades = function() {
/********
* Section: Variables used in Disp functions
- * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */
+ */
+/**
+ * This list is used to make some very basic tooltips.
+ * It is used by CM.DelayInit() in the call of CM.Disp.CreateSimpleTooltip()
+ * @item {string} placeholder
+ * @item {string} text
+ * @item {string} minWidth
+ */
+CM.Disp.TooltipText = [
+ ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'],
+ ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'],
+ ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'],
+ ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'],
+ ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'],
+ ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'],
+ ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px']
+];
+
+/**
+ * These are variables used to create DOM object names and id (e.g., 'CMTextTooltip)
+ */
CM.Disp.colorTextPre = 'CMText';
CM.Disp.colorBackPre = 'CMBack';
CM.Disp.colorBorderPre = 'CMBorder';
+
+/**
+ * These are variables which can be set in the options by the user to standardize colours throughout CookieMonster
+ */
CM.Disp.colorBlue = 'Blue';
CM.Disp.colorGreen = 'Green';
CM.Disp.colorYellow = 'Yellow';
@@ -3498,43 +3418,28 @@ CM.Disp.colorGray = 'Gray';
CM.Disp.colorPink = 'Pink';
CM.Disp.colorBrown = 'Brown';
CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown];
+
+
+/**
+ * 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};
-CM.Disp.lastGoldenCookieState = 0;
-CM.Disp.lastSpawnedGoldenCookieState = 0;
-CM.Disp.currSpawnedGoldenCookieState
-CM.Disp.lastTickerFortuneState = 0;
-CM.Disp.lastSeasonPopupState = 0;
-CM.Disp.lastGardenNextStep = 0;
-CM.Disp.lastMagicBarFull = 0;
-CM.Disp.lastWrinklerCount = 0;
-CM.Disp.goldenShimmersByID = {};
-CM.Disp.spawnedGoldenShimmer = 0;
CM.Disp.GCTimers = {};
-CM.Disp.seasonPopShimmer;
CM.Disp.lastAscendState = -1;
+/**
+ * These lists are used in the stats page to show
+ * average cookies per {CM.Disp.cookieTimes/CM.Disp.clickTimes} seconds
+ */
CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800];
CM.Disp.clickTimes = [1, 5, 10, 15, 30];
-CM.Disp.metric = ['M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
-CM.Disp.shortScale = ['M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
-
+/**
+ * These are variables with base-values that get initalized when initliazing CookieMonster
+ * TODO: See if these can be removed or moved
+ */
CM.Disp.TooltipWrinklerArea = 0;
CM.Disp.TooltipWrinkler = -1;
-CM.Disp.TooltipWrinklerCache = [];
-for (var i in Game.wrinklers) {
- CM.Disp.TooltipWrinklerCache[i] = 0;
-}
-
-CM.Disp.TooltipText = [
- ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'],
- ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'],
- ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'],
- ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'],
- ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'],
- ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'],
- ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px']
-];
/********
* Main *
********/
@@ -3555,14 +3460,12 @@ CM.ReplaceNative = function() {
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.Disp.DrawTooltipWarn();
}
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.UpdateTooltipWarn();
CM.Disp.UpdateTooltipLocation();
}
@@ -3588,10 +3491,12 @@ CM.ReplaceNative = function() {
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();
- CM.Disp.AddTooltipUpgrade();
+ CM.Disp.ReplaceTooltipUpgrade();
Game.CalculateGains();
}
@@ -3702,14 +3607,15 @@ CM.Loop = function() {
CM.Cache.RemakePP();
// Update colors
- CM.Disp.UpdateBotBarOther();
CM.Disp.UpdateBuildings();
CM.Disp.UpdateUpgrades();
// Redraw timers
- CM.Disp.UpdateBotBarTime();
CM.Disp.UpdateTimerBar();
+ // Update Bottom Bar
+ CM.Disp.UpdateBotBar();
+
// Update Tooltip
CM.Disp.UpdateTooltip();
@@ -3721,23 +3627,13 @@ CM.Loop = function() {
CM.Disp.RefreshMenu();
}
- // Check Golden Cookies
- CM.Disp.CheckGoldenCookie();
-
- // Check Fortune Cookies
- CM.Disp.CheckTickerFortune();
-
- // Check Season Popup
- CM.Disp.CheckSeasonPopup();
-
- // Check Garden Tick
- CM.Disp.CheckGardenTick();
-
- // Check Grimoire Meter
- CM.Disp.CheckMagicMeter();
-
- // Check Wrinklers
- CM.Disp.CheckWrinklerCount();
+ // 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.UpdateAvgCPS()
@@ -3770,13 +3666,12 @@ CM.DelayInit = function() {
CM.Disp.CreateWhiteScreen();
CM.Disp.CreateFavicon();
for (var i in CM.Disp.TooltipText) {
- CM.Disp.CreateTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]);
+ CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]);
}
- CM.Disp.CreateTooltipWarn();
- CM.Disp.AddTooltipBuild();
- CM.Disp.AddTooltipGrimoire();
- CM.Disp.AddTooltipLump();
- CM.Disp.AddWrinklerAreaDetect();
+ CM.Disp.ReplaceTooltipBuild();
+ CM.Disp.ReplaceTooltipGrimoire();
+ CM.Disp.ReplaceTooltipLump();
+ CM.Main.AddWrinklerAreaDetect();
CM.Cache.InitCookiesDiff();
CM.ReplaceNative();
CM.ReplaceNativeGrimoire();
@@ -3793,9 +3688,197 @@ CM.DelayInit = function() {
Game.Win('Third-party');
}
+/********
+ * Section: Functions related to checking for changes in Minigames/GC's/Ticker
+ * TODO: Annotate functions
+ * TODO: Possibly move this section */
+
+/**
+ * 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 (var i in 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.Loop
+ * TODO: Remove the delete function, as it does not delete correctly and crowds CM.Disp.GCTimers
+ */
+CM.Main.CheckGoldenCookie = function() {
+ CM.Main.FindShimmer();
+ for (var i in CM.Disp.GCTimers) {
+ if (typeof CM.Cache.goldenShimmersByID[i] == "undefined") {
+ CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
+ // TODO remove delete here
+ 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.Config.GCSoundURL, 'GCSound', 'GCVolume');
+ CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
+ }
+ CM.Disp.UpdateFavicon();
+
+ for (var i in Game.shimmers) {
+ if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") {
+ CM.Disp.CreateGCTimer(Game.shimmers[i]);
+ }
+ }
+ }
+ CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState
+ if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0;
+ }
+ else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) {
+ for (var i in 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.Loop
+ */
+CM.Main.CheckSeasonPopup = function() {
+ if (CM.Main.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) {
+ CM.Main.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned;
+ for (var i in 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.Config.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.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.Config.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.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.Config.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.Loop
+ */
+CM.Main.CheckMagicMeter = function() {
+ if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) {
+ var 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.Config.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.Loop
+ */
+CM.Main.CheckWrinklerCount = function() {
+ if (Game.elderWrath > 0) {
+ var CurrentWrinklers = 0;
+ for (var 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.Config.WrinklerMaxFlash) {
+ CM.Disp.Flash(3, 'WrinklerMaxFlash');
+ } else {
+ CM.Disp.Flash(3, 'WrinklerFlash');
+ }
+ if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) {
+ CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
+ } else {
+ CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
+ }
+ if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.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.DelayInit
+ * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips
+ * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc.
+ */
+CM.Main.AddWrinklerAreaDetect = function() {
+ l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;};
+ l('backgroundLeftCanvas').onmouseout = function() {
+ CM.Disp.TooltipWrinklerArea = 0;
+ Game.tooltip.hide();
+ for (var i in Game.wrinklers) {
+ CM.Disp.TooltipWrinklerCache[i] = 0;
+ }
+ };
+}
+
CM.HasReplaceNativeGrimoireLaunch = false;
CM.HasReplaceNativeGrimoireDraw = false;
+CM.Main.lastGoldenCookieState = 0;
+CM.Main.lastSpawnedGoldenCookieState = 0;
+CM.Main.currSpawnedGoldenCookieState
+CM.Main.lastTickerFortuneState = 0;
+CM.Main.lastSeasonPopupState = 0;
+CM.Main.lastGardenNextStep = 0;
+CM.Main.lastMagicBarFull = 0;
+CM.Main.lastWrinklerCount = 0;
+
CM.ConfigDefault = {
BotBar: 1,
TimerBar: 1,
@@ -3862,7 +3945,7 @@ CM.ConfigDefault = {
SayTime: 1,
GrimoireBar: 1,
Scale: 2,
- MenuPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1},
+ OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1},
StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1},
Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'},
SortBuildings: 0,
@@ -3993,7 +4076,7 @@ CM.Sim.eff = function(name) {
return CM.Sim.effs[name]
}
else {
- return Game.effs[name];
+ return CM.Sim.effs[name];
}
}
@@ -4127,7 +4210,7 @@ CM.Sim.CalculateGains = function() {
var mult = 1;
// Include minigame effects
var effs={};
- for (var i in CM.Cache.Objects) {
+ for (var i in Game.Objects) {
// TODO Store minigames and effects in Cache
// Include possibility of new/modded building and new/modded minigames
if (CM.Sim.Objects[i].minigameLoaded && CM.Sim.Objects[i].minigame.effs) {
diff --git a/src/Cache.js b/src/Cache.js
index 3498447..b3a08ed 100644
--- a/src/Cache.js
+++ b/src/Cache.js
@@ -2,6 +2,9 @@
* Cache *
*********/
+/********
+ * Section: UNSORTED */
+
CM.Cache.AddQueue = function() {
CM.Cache.Queue = document.createElement('script');
CM.Cache.Queue.type = 'text/javascript';
@@ -524,4 +527,6 @@ CM.Cache.MissingCookies = Game.Upgrades;
CM.Cache.UpgradesOwned = -1;
CM.Cache.MissingUpgradesString = null;
CM.Cache.MissingCookiesString = null;
-
+CM.Cache.seasonPopShimmer;
+CM.Cache.goldenShimmersByID = {};
+CM.Cache.spawnedGoldenShimmer = 0;
diff --git a/src/Config.js b/src/Config.js
index 5ff8665..8a00a3e 100644
--- a/src/Config.js
+++ b/src/Config.js
@@ -51,7 +51,7 @@ CM.LoadConfig = function() {
if (mod) CM.SaveConfig(CM.Config);
CM.Loop(); // Do loop once
for (var i in CM.ConfigDefault) {
- if (i != 'StatsPref' && i != 'MenuPref' && typeof CM.ConfigData[i].func !== 'undefined') {
+ if (i != 'StatsPref' && i != 'OptionsPref' && typeof CM.ConfigData[i].func !== 'undefined') {
CM.ConfigData[i].func();
}
}
@@ -114,12 +114,12 @@ CM.ToggleStatsConfig = function(config) {
CM.SaveConfig(CM.Config);
}
-CM.ToggleMenuConfig = function(config) {
- if (CM.Config.MenuPref[config] == 0) {
- CM.Config.MenuPref[config]++;
+CM.ToggleOptionsConfig = function(config) {
+ if (CM.Config.OptionsPref[config] == 0) {
+ CM.Config.OptionsPref[config]++;
}
else {
- CM.Config.MenuPref[config]--;
+ CM.Config.OptionsPref[config]--;
}
CM.SaveConfig(CM.Config);
}
@@ -151,107 +151,4 @@ CM.CheckNotificationPermissions = function(ToggleOnOff) {
}
}
}
-}
-
-CM.ConfigData.BotBar = {label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}};
-CM.ConfigData.TimerBar = {label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}};
-CM.ConfigData.TimerBarPos = {label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}};
-CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}};
-CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
-CM.ConfigData.ColorPPBulkMode = {label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
-CM.ConfigData.UpBarColor = {label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpBarColor();}};
-CM.ConfigData.Colors = {
- desc: {
- Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels',
- Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
- Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels',
- Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels',
- Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels',
- Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels',
- Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
- Pink: 'Color Pink. Used for Dragonflight bar',
- Brown: 'Color Brown. Used for Dragon Harvest bar'
- },
- func: function() {CM.Disp.UpdateColors();}
-};
-CM.ConfigData.UpgradeBarFixedPos = {label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}};
-CM.ConfigData.CalcWrink = {label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true};
-CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false};
-CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
-CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
-CM.ConfigData.ToolWarnBon = {label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
-CM.ConfigData.GCNotification = {label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}};
-CM.ConfigData.GCFlash = {label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true};
-CM.ConfigData.GCSound = {label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true};
-CM.ConfigData.GCVolume = {label: [], desc: 'Volume of the Golden Cookie sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.GCVolume.label[i] = i + '%';
-}
-CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
-CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}};
-CM.ConfigData.Favicon = {label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}};
-CM.ConfigData.FortuneNotification = {label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}};
-CM.ConfigData.FortuneFlash = {label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true};
-CM.ConfigData.FortuneSound = {label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true};
-CM.ConfigData.FortuneVolume = {label: [], desc: 'Volume of the Fortune Cookie sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.FortuneVolume.label[i] = i + '%';
-}
-CM.ConfigData.FortuneSoundURL = {label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'};
-CM.ConfigData.SeaNotification = {label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}};
-CM.ConfigData.SeaFlash = {label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true};
-CM.ConfigData.SeaSound = {label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true};
-CM.ConfigData.SeaVolume = {label: [], desc: 'Volume of the Season Special sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.SeaVolume.label[i] = i + '%';
-}
-CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'};
-CM.ConfigData.GardFlash = {label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true};
-CM.ConfigData.GardSound = {label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true};
-CM.ConfigData.GardVolume = {label: [], desc: 'Volume of the Garden Tick sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.GardVolume.label[i] = i + '%';
-}
-CM.ConfigData.GardSoundURL = {label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'};
-CM.ConfigData.MagicNotification = {label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}};
-CM.ConfigData.MagicFlash = {label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true};
-CM.ConfigData.MagicSound = {label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true};
-CM.ConfigData.MagicVolume = {label: [], desc: 'Volume of the Max Magic sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.MagicVolume.label[i] = i + '%';
-}
-CM.ConfigData.MagicSoundURL = {label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'};
-CM.ConfigData.WrinklerNotification = {label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}};
-CM.ConfigData.WrinklerFlash = {label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true};
-CM.ConfigData.WrinklerSound = {label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true};
-CM.ConfigData.WrinklerVolume = {label: [], desc: 'Volume of the Wrinkler sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.WrinklerVolume.label[i] = i + '%';
-}
-CM.ConfigData.WrinklerSoundURL = {label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'};
-CM.ConfigData.WrinklerMaxNotification = {label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}};
-CM.ConfigData.WrinklerMaxFlash = {label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true};
-CM.ConfigData.WrinklerMaxSound = {label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true};
-CM.ConfigData.WrinklerMaxVolume = {label: [], desc: 'Volume of the Wrinkler Max sound'};
-for (var i = 0; i < 101; i++) {
- CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%';
-}
-CM.ConfigData.WrinklerMaxSoundURL = {label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'};
-CM.ConfigData.Title = {label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true};
-CM.ConfigData.TooltipBuildUp = {label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true};
-CM.ConfigData.TooltipAmor = {label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true};
-CM.ConfigData.ToolWarnLucky = {label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true};
-CM.ConfigData.ToolWarnConjure = {label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true};
-CM.ConfigData.ToolWarnPos = {label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}};
-CM.ConfigData.TooltipGrim = {label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true};
-CM.ConfigData.ToolWrink = {label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true};
-CM.ConfigData.TooltipLump = {label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true};
-CM.ConfigData.Stats = {label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
-CM.ConfigData.MissingUpgrades = {label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true};
-CM.ConfigData.UpStats = {label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false};
-CM.ConfigData.TimeFormat = {label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false};
-CM.ConfigData.SayTime = {label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}};
-CM.ConfigData.GrimoireBar = {label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true};
-CM.ConfigData.Scale = {label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};
-CM.ConfigData.SortBuildings = {label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}};
-CM.ConfigData.SortUpgrades = {label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
+}
\ No newline at end of file
diff --git a/src/Data.js b/src/Data.js
index f5a8bde..24a727e 100644
--- a/src/Data.js
+++ b/src/Data.js
@@ -31,3 +31,145 @@ CM.Data.HalloCookies = ['Skull cookies', 'Ghost cookies', 'Bat cookies', 'Slime
CM.Data.ChristCookies = ['Christmas tree biscuits', 'Snowflake biscuits', 'Snowman biscuits', 'Holly biscuits', 'Candy cane biscuits', 'Bell biscuits', 'Present biscuits'];
CM.Data.ValCookies = ['Pure heart biscuits', 'Ardent heart biscuits', 'Sour heart biscuits', 'Weeping heart biscuits', 'Golden heart biscuits', 'Eternal heart biscuits', 'Prism heart biscuits'];
+
+/********
+ * Section: Data for the various scales used by CookieMonster */
+CM.Data.metric = ['', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
+CM.Data.shortScale = ['', 'M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
+
+/********
+ * Section: An array containing all Config groups and their to-be displayed title */
+
+CM.ConfigGroups = {
+ BarsColors: "Bars/Colors",
+ Calculation: "Calculation",
+ Notification: "Notification",
+ Tooltip: "Tooltips",
+ Statistics: "Statitics",
+ Other: "Other"},
+
+/********
+ * Section: An array (CM.ConfigData) containing all Config options
+ *
+ * Each array has the following items
+ * @item {string} type The type of option (bool(ean), vol(ume), url or color)
+ * @item {string} group The options-group the option belongs to
+ * @item {[string, ...]} label A list of the various configurations of the option
+ * @item {string} desc Description to be used in options menu
+ * @item {boolean} toggle Whether it should be displayed as a grey/white toggle in the options menu
+ * @item {function} func A function to be called when the option is toggled
+ */
+
+// Barscolors
+CM.ConfigData.BotBar = {type: 'bool', group: 'BarsColors', label: ['Bottom Bar OFF', 'Bottom Bar ON'], desc: 'Building Information', toggle: true, func: function() {CM.Disp.ToggleBotBar();}};
+CM.ConfigData.TimerBar = {type: 'bool', group: 'BarsColors', label: ['Timer Bar OFF', 'Timer Bar ON'], desc: 'Timers of Golden Cookie, Season Popup, Frenzy (Normal, Clot, Elder), Click Frenzy', toggle: true, func: function() {CM.Disp.ToggleTimerBar();}};
+CM.ConfigData.TimerBarPos = {type: 'bool', group: 'BarsColors', label: ['Timer Bar Position (Top Left)', 'Timer Bar Position (Bottom)'], desc: 'Placement of the Timer Bar', toggle: false, func: function() {CM.Disp.ToggleTimerBarPos();}};
+CM.ConfigData.SortBuildings = {type: 'bool', group: 'BarsColors', label: ['Sort Buildings: Default', 'Sort Buildings: PP'], desc: 'Sort the display of buildings in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateBuildings();}};
+CM.ConfigData.SortUpgrades = {type: 'bool', group: 'BarsColors', label: ['Sort Upgrades: Default', 'Sort Upgrades: PP'], desc: 'Sort the display of upgrades in either default order or by PP', toggle: false, func: function () { CM.Disp.UpdateUpgrades();}};
+CM.ConfigData.BuildColor = {type: 'bool', group: 'BarsColors', label: ['Building Colors OFF', 'Building Colors ON'], desc: 'Color code buildings', toggle: true, func: function() {CM.Disp.UpdateBuildings();}};
+CM.ConfigData.BulkBuildColor = {type: 'bool', group: 'BarsColors', label: ['Bulk Building Colors (Single Building Color)', 'Bulk Building Colors (Calculated Bulk Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
+CM.ConfigData.ColorPPBulkMode = {type: 'bool', group: 'BarsColors', label: ['Color of PP (Compared to Single)', 'Color of PP (Compared to Bulk)'], desc: 'Color PP-values based on comparison with single purchase or with selected bulk-buy mode', toggle: false};
+CM.ConfigData.UpBarColor = {type: 'bool', group: 'BarsColors', label: ['Upgrade Colors/Bar OFF', 'Upgrade Colors with Bar ON', 'Upgrade Colors without Bar ON'], desc: 'Color code upgrades and optionally add a counter bar', toggle: false, func: function() {CM.Disp.ToggleUpgradeBarAndColor();}};
+CM.ConfigData.Colors = { type: 'color', group: 'BarsColors',
+ desc: {
+ Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels',
+ Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
+ Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels',
+ Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels',
+ Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels',
+ Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels',
+ Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
+ Pink: 'Color Pink. Used for Dragonflight bar',
+ Brown: 'Color Brown. Used for Dragon Harvest bar'
+ },
+ func: function() {CM.Disp.UpdateColors();}
+};
+CM.ConfigData.UpgradeBarFixedPos = {type: 'bool', group: 'BarsColors', label: ['Upgrade Bar Fixed Position OFF', 'Upgrade Bar Fixed Position ON'], desc: 'Lock the upgrade bar at top of the screen to prevent it from moving ofscreen when scrolling', toggle: true, func: function() {CM.Disp.ToggleUpgradeBarFixedPos();}};
+
+// Calculation
+CM.ConfigData.CalcWrink = {type: 'bool', group: 'Calculation', label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinklers', toggle: true};
+CM.ConfigData.CPSMode = {type: 'bool', group: 'Calculation', label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false};
+CM.ConfigData.AvgCPSHist = {type: 'bool', group: 'Calculation', label: ['Average CPS for past 10s', 'Average CPS for past 15s', 'Average CPS for past 30s', 'Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
+CM.ConfigData.AvgClicksHist = {type: 'bool', group: 'Calculation', label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
+CM.ConfigData.ToolWarnBon = {type: 'bool', group: 'Calculation', label: ['Calculate Tooltip Warning With Bonus CPS OFF', 'Calculate Tooltip Warning With Bonus CPS ON'], desc: 'Calculate the warning with or without the bonus CPS you get from buying', toggle: true};
+
+// Notification
+CM.ConfigData.GCNotification = {type: 'bool', group: 'Notification', label: ['Golden Cookie Notification OFF', 'Golden Cookie Notification ON'], desc: 'Create a notification when Golden Cookie spawns', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.GCNotification);}};
+CM.ConfigData.GCFlash = {type: 'bool', group: 'Notification', label: ['Golden Cookie Flash OFF', 'Golden Cookie Flash ON'], desc: 'Flash screen on Golden Cookie', toggle: true};
+CM.ConfigData.GCSound = {type: 'bool', group: 'Notification', label: ['Golden Cookie Sound OFF', 'Golden Cookie Sound ON'], desc: 'Play a sound on Golden Cookie', toggle: true};
+CM.ConfigData.GCVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Golden Cookie sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.GCVolume.label[i] = i + '%';
+}
+CM.ConfigData.GCSoundURL = {type: 'url', group: 'Notification', label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
+CM.ConfigData.GCTimer = {type: 'bool', group: 'Notification', label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', toggle: true, func: function() {CM.Disp.ToggleGCTimer();}};
+CM.ConfigData.Favicon = {type: 'bool', group: 'Notification', label: ['Favicon OFF', 'Favicon ON'], desc: 'Update favicon with Golden/Wrath Cookie', toggle: true, func: function() {CM.Disp.UpdateFavicon();}};
+CM.ConfigData.FortuneNotification = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Notification OFF', 'Fortune Cookie Notification ON'], desc: 'Create a notification when Fortune Cookie is on the Ticker', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.FortuneNotification);}};
+CM.ConfigData.FortuneFlash = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Flash OFF', 'Fortune Cookie Flash ON'], desc: 'Flash screen on Fortune Cookie', toggle: true};
+CM.ConfigData.FortuneSound = {type: 'bool', group: 'Notification', label: ['Fortune Cookie Sound OFF', 'Fortune Cookie Sound ON'], desc: 'Play a sound on Fortune Cookie', toggle: true};
+CM.ConfigData.FortuneVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Fortune Cookie sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.FortuneVolume.label[i] = i + '%';
+}
+CM.ConfigData.FortuneSoundURL = {type: 'url', group: 'Notification', label: 'Fortune Cookie Sound URL:', desc: 'URL of the sound to be played when the Ticker has a Fortune Cookie'};
+CM.ConfigData.SeaNotification = {type: 'bool', group: 'Notification', label: ['Season Special Notification OFF', 'Season Special Notification ON'], desc: 'Create a notification on Season Popup', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.SeaNotification);}};
+CM.ConfigData.SeaFlash = {type: 'bool', group: 'Notification', label: ['Season Special Flash OFF', 'Season Special Flash ON'], desc: 'Flash screen on Season Popup', toggle: true};
+CM.ConfigData.SeaSound = {type: 'bool', group: 'Notification', label: ['Season Special Sound OFF', 'Season Special Sound ON'], desc: 'Play a sound on Season Popup', toggle: true};
+CM.ConfigData.SeaVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Season Special sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.SeaVolume.label[i] = i + '%';
+}
+CM.ConfigData.SeaSoundURL = {type: 'url', group: 'Notification', label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns'};
+CM.ConfigData.GardFlash = {type: 'bool', group: 'Notification', label: ['Garden Tick Flash OFF', 'Garden Tick Flash ON'], desc: 'Flash screen on Garden Tick', toggle: true};
+CM.ConfigData.GardSound = {type: 'bool', group: 'Notification', label: ['Garden Tick Sound OFF', 'Garden Tick Sound ON'], desc: 'Play a sound on Garden Tick', toggle: true};
+CM.ConfigData.GardVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Garden Tick sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.GardVolume.label[i] = i + '%';
+}
+CM.ConfigData.GardSoundURL = {type: 'url', group: 'Notification', label: 'Garden Tick Sound URL:', desc: 'URL of the sound to be played when the garden ticks'};
+CM.ConfigData.MagicNotification = {type: 'bool', group: 'Notification', label: ['Magic Max Notification OFF', 'Magic Max Notification ON'], desc: 'Create a notification when magic reaches maximum', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.MagicNotification);}};
+CM.ConfigData.MagicFlash = {type: 'bool', group: 'Notification', label: ['Magic Max Flash OFF', 'Magic Max Flash ON'], desc: 'Flash screen when magic reaches maximum', toggle: true};
+CM.ConfigData.MagicSound = {type: 'bool', group: 'Notification', label: ['Magic Max Sound OFF', 'Magic Max Sound ON'], desc: 'Play a sound when magic reaches maximum', toggle: true};
+CM.ConfigData.MagicVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Max Magic sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.MagicVolume.label[i] = i + '%';
+}
+CM.ConfigData.MagicSoundURL = {type: 'url', group: 'Notification', label: 'Magic Max Sound URL:', desc: 'URL of the sound to be played when magic reaches maxium'};
+CM.ConfigData.WrinklerNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Notification OFF', 'Wrinkler Notification ON'], desc: 'Create a notification when a Wrinkler appears', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerNotification);}};
+CM.ConfigData.WrinklerFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Flash OFF', 'Wrinkler Flash ON'], desc: 'Flash screen when a Wrinkler appears', toggle: true};
+CM.ConfigData.WrinklerSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Sound OFF', 'Wrinkler Sound ON'], desc: 'Play a sound when a Wrinkler appears', toggle: true};
+CM.ConfigData.WrinklerVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.WrinklerVolume.label[i] = i + '%';
+}
+CM.ConfigData.WrinklerSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Sound URL:', desc: 'URL of the sound to be played when a Wrinkler appears'};
+CM.ConfigData.WrinklerMaxNotification = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Notification OFF', 'Wrinkler Max Notification ON'], desc: 'Create a notification when the maximum amount of Wrinklers has appeared', toggle: true, func: function () {CM.CheckNotificationPermissions(CM.Config.WrinklerMaxNotification);}};
+CM.ConfigData.WrinklerMaxFlash = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Flash OFF', 'Wrinkler Max Flash ON'], desc: 'Flash screen when the maximum amount of Wrinklers has appeared', toggle: true};
+CM.ConfigData.WrinklerMaxSound = {type: 'bool', group: 'Notification', label: ['Wrinkler Max Sound OFF', 'Wrinkler Max Sound ON'], desc: 'Play a sound when the maximum amount of Wrinklers has appeared', toggle: true};
+CM.ConfigData.WrinklerMaxVolume = {type: 'vol', group: 'Notification', label: [], desc: 'Volume of the Wrinkler Max sound'};
+for (var i = 0; i < 101; i++) {
+ CM.ConfigData.WrinklerMaxVolume.label[i] = i + '%';
+}
+CM.ConfigData.WrinklerMaxSoundURL = {type: 'url', group: 'Notification', label: 'Wrinkler Max Sound URL:', desc: 'URL of the sound to be played when the maximum amount of Wrinklers has appeared'};
+CM.ConfigData.Title = {type: 'bool', group: 'Notification', label: ['Title OFF', 'Title ON', 'Title Pinned Tab Highlight'], desc: 'Update title with Golden Cookie/Season Popup timers; pinned tab highlight only changes the title when a Golden Cookie/Season Popup spawns', toggle: true};
+
+// Tooltip
+CM.ConfigData.TooltipBuildUp = {type: 'bool', group: 'Tooltip', label: ['Buildings/Upgrades Tooltip Information OFF', 'Buildings/Upgrades Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades', toggle: true};
+CM.ConfigData.TooltipAmor = {type: 'bool', group: 'Tooltip', label: ['Buildings Tooltip Amortization Information OFF', 'Buildings Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true};
+CM.ConfigData.ToolWarnLucky = {type: 'bool', group: 'Tooltip', label: ['Tooltip Lucky Warning OFF', 'Tooltip Lucky Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true};
+CM.ConfigData.ToolWarnConjure = {type: 'bool', group: 'Tooltip', label: ['Tooltip Conjure Warning OFF', 'Tooltip Conjure Warning ON'], desc: 'A warning when buying if it will put the bank under the amount needed for max "Conjure Baked Goods" rewards', toggle: true};
+CM.ConfigData.ToolWarnPos = {type: 'bool', group: 'Tooltip', label: ['Tooltip Warning Position (Left)', 'Tooltip Warning Position (Bottom)'], desc: 'Placement of the warning boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnPos();}};
+CM.ConfigData.TooltipGrim = {type: 'bool', group: 'Tooltip', label: ['Grimoire Tooltip Information OFF', 'Grimoire Tooltip Information ON'], desc: 'Extra information in tooltip for grimoire', toggle: true};
+CM.ConfigData.ToolWrink = {type: 'bool', group: 'Tooltip', label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true};
+CM.ConfigData.TooltipLump = {type: 'bool', group: 'Tooltip', label: ['Sugar Lump Tooltip OFF', 'Sugar Lump Tooltip ON'], desc: 'Shows the current Sugar Lump type in Sugar lump tooltip.', toggle: true};
+
+// Statistics
+CM.ConfigData.Stats = {type: 'bool', group: 'Statistics', label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
+CM.ConfigData.MissingUpgrades = {type: 'bool', group: 'Statistics', label: ['Missing Upgrades OFF', 'Missing Upgrades ON'], desc: 'Shows Missing upgrades in Stats Menu. This feature can be laggy for users with a low amount of unlocked achievements.', toggle: true};
+CM.ConfigData.UpStats = {type: 'bool', group: 'Statistics', label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false};
+CM.ConfigData.TimeFormat = {type: 'bool', group: 'Statistics', label: ['Time XXd, XXh, XXm, XXs', 'Time XX:XX:XX:XX:XX'], desc: 'Change the time format', toggle: false};
+CM.ConfigData.SayTime = {type: 'bool', group: 'Statistics', label: ['Format Time OFF', 'Format Time ON'], desc: 'Change how time is displayed in statistics', toggle: true, func: function() {CM.Disp.ToggleSayTime();}};
+CM.ConfigData.GrimoireBar = {type: 'bool', group: 'Statistics', label: ['Grimoire Magic Meter Timer OFF', 'Grimoire Magic Meter Timer ON'], desc: 'A timer on how long before the Grimoire magic meter is full', toggle: true};
+
+// Statistics
+CM.ConfigData.Scale = {type: 'bool', group: 'Other', label: ['Game\'s Setting Scale', 'Metric', 'Short Scale', 'Scientific Notation', 'Engineering Notation'], desc: 'Change how long numbers are handled', toggle: false, func: function() {CM.Disp.RefreshScale();}};
\ No newline at end of file
diff --git a/src/Disp.js b/src/Disp.js
index c1dd66d..35e7a12 100644
--- a/src/Disp.js
+++ b/src/Disp.js
@@ -2,49 +2,25 @@
* Disp *
********/
+/********
+ * Please make sure to annotate your code correctly. See the options page section for some examples.
+ * Only put functions related to graphics and displays in this file.
+ * All calculations and data should be put in others. */
+
/********
* Section: Unsorted functions
* TODO: Annotate most functions
* TODO: Sort functionsn in relevant (new) sections or files */
-CM.Disp.GetTimeColor = function(price, bank, cps, time) {
- var color;
- var text;
- if (bank >= price) {
- color = CM.Disp.colorGreen;
- if (CM.Config.TimeFormat) {
- text = '00:00:00:00:00';
- }
- else {
- text = 'Done!';
- }
- }
- else {
- if (typeof time !== 'undefined') {
- var time = time;
- }
- else {
- var time = (price - bank) / cps;
- }
- text = CM.Disp.FormatTime(time);
- if (time > 300) {
- color = CM.Disp.colorRed;
- }
- else if (time > 60) {
- color = CM.Disp.colorOrange;
- }
- else {
- color = CM.Disp.colorYellow;
- }
- }
- return {text: text, color: color};
+CM.Disp.TooltipWrinklerCache = [];
+for (var i in Game.wrinklers) {
+ CM.Disp.TooltipWrinklerCache[i] = 0;
}
/**
* This function returns Name and Color as object for sugar lump type that is given as input param.
* @param type Sugar Lump Type.
* @returns {{text: string, color: string}}
- * @constructor
*/
CM.Disp.GetLumpColor = function(type) {
var name = "";
@@ -112,20 +88,7 @@ CM.Disp.AddJscolor = function() {
document.head.appendChild(CM.Disp.Jscolor);
}
-CM.Disp.CreateCssArea = function() {
- CM.Disp.Css = document.createElement('style');
- CM.Disp.Css.type = 'text/css';
- document.head.appendChild(CM.Disp.Css);
-
- // 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";
-}
CM.Disp.UpdateUpgrades = function() {
if (CM.Config.UpBarColor > 0) {
@@ -207,31 +170,6 @@ CM.Disp.UpdateColors = function() {
CM.Disp.UpdateBuildings(); // Class has been already set
}
-CM.Disp.CreateWhiteScreen = function() {
- CM.Disp.WhiteScreen = document.createElement('div');
- CM.Disp.WhiteScreen.id = 'CMWhiteScreen';
- CM.Disp.WhiteScreen.style.width = '100%';
- CM.Disp.WhiteScreen.style.height = '100%';
- CM.Disp.WhiteScreen.style.backgroundColor = 'white';
- CM.Disp.WhiteScreen.style.display = 'none';
- CM.Disp.WhiteScreen.style.zIndex = '9999999999';
- CM.Disp.WhiteScreen.style.position = 'absolute';
-
- l('wrapper').appendChild(CM.Disp.WhiteScreen);
-}
-
-CM.Disp.FindShimmer = function() {
- CM.Disp.currSpawnedGoldenCookieState = 0
- CM.Disp.goldenShimmersByID = {}
- for (var i in Game.shimmers) {
- CM.Disp.goldenShimmersByID[Game.shimmers[i].id] = Game.shimmers[i]
- if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'golden') {
- CM.Disp.spawnedGoldenShimmer = Game.shimmers[i];
- CM.Disp.currSpawnedGoldenCookieState += 1;
- }
- }
-}
-
CM.Disp.CollectWrinklers = function() {
for (var i in Game.wrinklers) {
if (Game.wrinklers[i].sucked > 0 && Game.wrinklers[i].type == 0) {
@@ -261,16 +199,7 @@ CM.Disp.CalculateGrimoireRefillTime = function(currentMagic, maxMagic, targetMag
return count / Game.fps;
}
-CM.Disp.AddWrinklerAreaDetect = function() {
- l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;};
- l('backgroundLeftCanvas').onmouseout = function() {
- CM.Disp.TooltipWrinklerArea = 0;
- Game.tooltip.hide();
- for (var i in Game.wrinklers) {
- CM.Disp.TooltipWrinklerCache[i] = 0;
- }
- };
-}
+
CM.Disp.UpdateAscendState = function() {
if (Game.OnAscend) {
@@ -313,19 +242,34 @@ CM.Disp.RefreshScale = function() {
Game.RefreshStore();
Game.RebuildUpgrades();
- CM.Disp.UpdateBotBarOther();
+ CM.Disp.UpdateBotBar();
CM.Disp.UpdateBuildings();
CM.Disp.UpdateUpgrades();
}
+
+CM.Disp.CreateCssArea = function() {
+ CM.Disp.Css = document.createElement('style');
+ CM.Disp.Css.type = 'text/css';
+
+ document.head.appendChild(CM.Disp.Css);
+
+ // 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";
+}
+
/********
- * Section: General functions to format or beautify strings
- * TODO: Annotate most functions */
+ * Section: General functions to format or beautify strings */
/**
* This function returns time as a string depending on TimeFormat setting
- * @param {number} time Time as number
- * @param {number} longFormat 1 or 0
- * @return {string}
+ * @param {number} time Time to be formatted
+ * @param {number} longFormat 1 or 0
+ * @returns {string} Formatted time
*/
CM.Disp.FormatTime = function(time, longFormat) {
if (time == Infinity) return time;
@@ -353,118 +297,209 @@ CM.Disp.FormatTime = function(time, longFormat) {
return str;
}
-CM.Disp.Beautify = function(num, frac) {
- if (CM.Config.Scale != 0 && isFinite(num)) {
+/**
+ * This function returns the color to be used for time-strings
+ * @param {number} time Time to be coloured
+ * @returns {{string, string}} {text, color} Both the formatted time and color as strings in an array
+ */
+CM.Disp.GetTimeColor = function(time) {
+ var color;
+ var text;
+ if (time < 0) {
+ if (CM.Config.TimeFormat) text = '00:00:00:00:00';
+ else text = 'Done!';
+ color = CM.Disp.colorGreen;
+ }
+ else {
+ text = CM.Disp.FormatTime(time);
+ if (time > 300) color = CM.Disp.colorRed;
+ else if (time > 60) color = CM.Disp.colorOrange;
+ else color = CM.Disp.colorYellow;
+ }
+ return {text: text, color: color};
+}
+
+/**
+ * This function returns formats number based on the Scale setting
+ * @param {number} num Number to be beautified
+ * @param {any} frac Used in some scenario's by CM.Backup.Beautify (Game's original function)
+ * @param {number} forced Used to force (type 3) in certains cases
+ * @returns {string} Formatted number
+ * TODO: Add functionality to choose amount of decimals and separators
+ */
+CM.Disp.Beautify = function(num, frac, forced) {
+ var decimals = 3; // This can be used to implement function to let user choose amount of decimals
+ if (CM.Config.Scale == 0) {
+ return CM.Backup.Beautify(num, frac);
+ }
+ else if (isFinite(num)) {
var answer = '';
- var negative = false;
if (num < 0) {
num = Math.abs(num);
- negative = true;
+ var negative = true;
}
-
- if (CM.Config.Scale == 3) {
- if (num >= 999999) {
- var count = 0;
- while (num >= 10) {
- count++;
- num /= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
- }
+ num = num.toString();
+ var timesTenToPowerThree = Math.trunc(Math.log10(num) / 3)
+ if (num == "0") {
+ return num
}
- else if (CM.Config.Scale == 4) {
- if (um >= 999999) {
- var count = 0;
- while (num >= 1000) {
- count++;
- num /= 1000;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + (count * 3);
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 1000;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + (count * 3);
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
+ else if (-1 < timesTenToPowerThree && timesTenToPowerThree < 2) {
+ answer = Math.round(num * 100) / 100;
+ }
+ else if (CM.Config.Scale == 3 && !forced || forced == 3) { // Scientific notation, 123456789 => 1.235E+8
+ answer = num[0] + '.'
+ i = 0;
+ while (i < decimals - 1) {
+ answer += num[i + 2]; // num has a 0-based index and [1] is a '.'
+ i++;
}
+ answer += Math.round(num[i + 2] + '.' + num[i + 3]);
+ answer += 'E+' + Math.trunc(Math.log10(num));
}
else {
- for (var i = (CM.Disp.shortScale.length - 1); i >= 0; i--) {
- if (i < CM.Disp.metric.length && CM.Config.Scale == 1) {
- // Revert to Scientific Notation from e27
- if (Math.log10(num) > 27) {
- if (num >= 999999) {
- var count = 0;
- while (num >= 10) {
- count++;
- num /= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E+' + count;
- }
- else if (num < -999999 && num != 0) {
- var count = 0;
- while (num < 1) {
- count++;
- num *= 10;
- }
- answer = +(Math.round(num + "e+2") + "e-2") + 'E-' + count;
- }
- else {
- answer = CM.Backup.Beautify(num, frac);
- }
- }
- else if (num >= Math.pow(1000, i + 2)) {
- answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ' ' + CM.Disp.metric[i];
- break;
- }
+ var restOfNumber = (num / Math.pow(10, (timesTenToPowerThree * 3))).toString();
+ numbersToAdd = (restOfNumber.indexOf('.') > -1 ? restOfNumber.indexOf('.') + 1 + decimals : (restOfNumber.length))
+ i = 0
+ while (i < numbersToAdd - 1) {
+ answer += restOfNumber[i];
+ i++
+ }
+ answer += (i + 1 < restOfNumber.length ? Math.round(restOfNumber[i] + '.' + restOfNumber[i + 1]) : restOfNumber[i]);
+
+ // answer is now "xxx.xx" (e.g., 123456789 would be 123.46)
+ if (CM.Config.Scale == 1 && !forced || forced == 1) { // Metric scale, 123456789 => 123.457 M
+ if (timesTenToPowerThree - 1 < CM.Data.metric.length) {
+ answer += ' ' + CM.Data.metric[timesTenToPowerThree - 1]
}
- else if (CM.Config.Scale == 2) {
- if (num >= Math.pow(1000, i + 2)) {
- answer = (Math.round(num / Math.pow(1000, i + 1)) / 1000) + ' ' + CM.Disp.shortScale[i];
- break;
- }
+ else { // If number is too large, revert to scientific notation
+ return CM.Disp.Beautify(num, 0, 3);
}
}
+ else if (CM.Config.Scale == 2 && !forced || forced == 2) { // Short scale, 123456789 => 123.457 M
+ if (timesTenToPowerThree < CM.Data.shortScale.length + 1) {
+ answer += ' ' + CM.Data.shortScale[timesTenToPowerThree - 1];
+ }
+ else { // If number is too large, revert to scientific notation
+ return CM.Disp.Beautify(num, 0, 3);
+ }
+ }
+ else if (CM.Config.Scale == 4 && !forced || forced == 4) { // Engineering notation, 123456789 => 123.457E+6
+ answer += 'E+' + (timesTenToPowerThree * 3);
+ }
}
if (answer == '') {
- answer = CM.Backup.Beautify(num, frac);
+ console.log("Could not beautify number with CM.Disp.Beautify");
+ answer = CM.Backup.Beautify(num, frac);
}
-
- if (negative) {
- answer = '-' + answer;
- }
- return answer;
+ if (negative) answer = '-' + answer;
+ return answer.toString();
+ }
+ else if (num == Infinity) {
+ return "Infinity";
}
else {
+ console.log("Could not beautify number with CM.Disp.Beautify");
return CM.Backup.Beautify(num, frac);
}
}
/********
- * Section: Functions related to the Bottom Bar
- * TODO: Annotate functions */
+ * Section: Functions related to the Bottom Bar */
/**
- * Extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building.
- *
+ * This function toggle the bottom bar
+ * It is called by CM.Disp.UpdateAscendState() and a change in CM.Config.BotBar
+ */
+CM.Disp.ToggleBotBar = function() {
+ if (CM.Config.BotBar == 1) {
+ CM.Disp.BotBar.style.display = '';
+ CM.Disp.UpdateBotBar();
+ }
+ else {
+ CM.Disp.BotBar.style.display = 'none';
+ }
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/**
+ * This function creates the bottom bar and appends it to l('wrapper')
+ * It is called by CM.DelayInit and a change in CM.Config.BotBar
+ */
+CM.Disp.CreateBotBar = function() {
+ CM.Disp.BotBar = document.createElement('div');
+ CM.Disp.BotBar.id = 'CMBotBar';
+ CM.Disp.BotBar.style.height = '69px';
+ CM.Disp.BotBar.style.width = '100%';
+ CM.Disp.BotBar.style.position = 'absolute';
+ CM.Disp.BotBar.style.display = 'none';
+ CM.Disp.BotBar.style.backgroundColor = '#262224';
+ // This is old code for very old browsersand should not be needed anymore
+ //CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)';
+ //CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)';
+ //CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)';
+ CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)';
+ CM.Disp.BotBar.style.borderTop = '1px solid black';
+ CM.Disp.BotBar.style.overflow = 'auto';
+ CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
+
+ var table = CM.Disp.BotBar.appendChild(document.createElement('table'));
+ table.style.width = '100%';
+ table.style.textAlign = 'center';
+ table.style.whiteSpace = 'nowrap';
+ var tbody = table.appendChild(document.createElement('tbody'));
+
+ var firstCol = function(text, color) {
+ var td = document.createElement('td');
+ td.style.textAlign = 'right';
+ td.className = CM.Disp.colorTextPre + color;
+ td.textContent = text;
+ return td;
+ }
+ var type = tbody.appendChild(document.createElement('tr'));
+ type.style.fontWeight = 'bold';
+ type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow));
+ var bonus = tbody.appendChild(document.createElement('tr'));
+ bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue));
+ var pp = tbody.appendChild(document.createElement('tr'));
+ pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue));
+ var time = tbody.appendChild(document.createElement('tr'));
+ time.appendChild(firstCol('Time Left', CM.Disp.colorBlue));
+
+ for (var i in Game.Objects) {
+ CM.Disp.CreateBotBarBuildingColumn(i);
+ }
+
+ l('wrapper').appendChild(CM.Disp.BotBar);
+}
+
+/**
+ * This function updates the bonus-, pp-, and time-rows in the the bottom bar
+ * It is called by CM.Loop()
+ */
+CM.Disp.UpdateBotBar = function() {
+ if (CM.Config.BotBar == 1) {
+ var count = 0;
+ for (var i in CM.Cache.Objects) {
+ var target = 'Objects';
+ if (Game.buyBulk == 10) {target = 'Objects10';}
+ if (Game.buyBulk == 100) {target = 'Objects100';}
+ count++;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2);
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2);
+ var timeColor = CM.Disp.GetTimeColor((Game.Objects[i].bulkPrice - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color;
+ CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text;
+ }
+ }
+}
+
+/**
+ * This function extends the bottom bar (created by CM.Disp.CreateBotBar) with a column for the given building.
* This function is called by CM.Disp.CreateBotBar on initialization of Cookie Monster,
* and also in CM.Sim.CopyData if a new building (added by another mod) is discovered.
+ * @param {string} buildingName Objectname to be added (e.g., "Cursor")
*/
CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
if(!CM.Disp.BotBar) {
@@ -490,101 +525,13 @@ CM.Disp.CreateBotBarBuildingColumn = function(buildingName) {
time.appendChild(document.createElement('td'));
}
-CM.Disp.CreateBotBar = function() {
- CM.Disp.BotBar = document.createElement('div');
- CM.Disp.BotBar.id = 'CMBotBar';
- CM.Disp.BotBar.style.height = '69px';
- CM.Disp.BotBar.style.width = '100%';
- CM.Disp.BotBar.style.position = 'absolute';
- CM.Disp.BotBar.style.display = 'none';
- CM.Disp.BotBar.style.backgroundColor = '#262224';
- CM.Disp.BotBar.style.backgroundImage = '-moz-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = '-o-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = '-webkit-linear-gradient(top, #4d4548, #000000)';
- CM.Disp.BotBar.style.backgroundImage = 'linear-gradient(to bottom, #4d4548, #000000)';
- CM.Disp.BotBar.style.borderTop = '1px solid black';
- CM.Disp.BotBar.style.overflow = 'auto';
- CM.Disp.BotBar.style.textShadow = '-1px 0 black, 0 1px black, 1px 0 black, 0 -1px black';
-
- var table = CM.Disp.BotBar.appendChild(document.createElement('table'));
- table.style.width = '100%';
- table.style.textAlign = 'center';
- table.style.whiteSpace = 'nowrap';
- // TODO figure a better way
- //table.style.tableLayout = 'fixed';
- //table.style.overflow = 'hidden';
- var tbody = table.appendChild(document.createElement('tbody'));
-
- var firstCol = function(text, color) {
- var td = document.createElement('td');
- td.style.textAlign = 'right';
- td.className = CM.Disp.colorTextPre + color;
- td.textContent = text;
- return td;
- }
-
- var type = tbody.appendChild(document.createElement('tr'));
- type.style.fontWeight = 'bold';
- type.appendChild(firstCol(CM.VersionMajor + '.' + CM.VersionMinor, CM.Disp.colorYellow));
- var bonus = tbody.appendChild(document.createElement('tr'));
- bonus.appendChild(firstCol('Bonus Income', CM.Disp.colorBlue));
- var pp = tbody.appendChild(document.createElement('tr'));
- pp.appendChild(firstCol('Payback Period', CM.Disp.colorBlue));
- var time = tbody.appendChild(document.createElement('tr'));
- time.appendChild(firstCol('Time Left', CM.Disp.colorBlue));
-
- for (var i in Game.Objects) {
- CM.Disp.CreateBotBarBuildingColumn(i);
- }
-
- l('wrapper').appendChild(CM.Disp.BotBar);
-}
-
-CM.Disp.ToggleBotBar = function() {
- if (CM.Config.BotBar == 1) {
- CM.Disp.BotBar.style.display = '';
- CM.Disp.UpdateBotBarOther();
- }
- else {
- CM.Disp.BotBar.style.display = 'none';
- }
- CM.Disp.UpdateBotTimerBarDisplay();
-}
-
-CM.Disp.UpdateBotBarOther = function() {
- if (CM.Config.BotBar == 1) {
- var count = 0;
-
- for (var i in CM.Cache.Objects) {
- var target = 'Objects';
- if (Game.buyBulk == 10) {target = 'Objects10';}
- if (Game.buyBulk == 100) {target = 'Objects100';}
- count++;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[0].childNodes[count].childNodes[1].textContent = Game.Objects[i].amount;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[1].childNodes[count].textContent = Beautify(CM.Cache[target][i].bonus, 2);
- CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].className = CM.Disp.colorTextPre + CM.Cache[target][i].color;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[2].childNodes[count].textContent = Beautify(CM.Cache[target][i].pp, 2);
- }
- }
-}
-
-CM.Disp.UpdateBotBarTime = function() {
- if (CM.Config.BotBar == 1) {
- var count = 0;
-
- for (var i in CM.Cache.Objects) {
- count++;
- var timeColor = CM.Disp.GetTimeColor(Game.Objects[i].getPrice(), (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
- CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].className = CM.Disp.colorTextPre + timeColor.color;
- CM.Disp.BotBar.firstChild.firstChild.childNodes[3].childNodes[count].textContent = timeColor.text;
- }
- }
-}
-
/********
* Section: Functions related to the Timer Bar
- * TODO: Annotate functions */
+/**
+ * This function creates the TimerBar and appends it to l('wrapper')
+ * It is called by CM.DelayInit()
+ */
CM.Disp.CreateTimerBar = function() {
CM.Disp.TimerBar = document.createElement('div');
CM.Disp.TimerBar.id = 'CMTimerBar';
@@ -595,118 +542,98 @@ CM.Disp.CreateTimerBar = function() {
CM.Disp.TimerBar.style.fontWeight = 'bold';
CM.Disp.TimerBar.style.backgroundColor = 'black';
- var bar = function(name, bars, time) {
- var div = document.createElement('div');
- div.style.width = '100%';
- div.style.height = '10px';
- div.style.margin = 'auto';
- div.style.position = 'absolute';
- div.style.left = '0px';
- div.style.top = '0px';
- div.style.right = '0px';
- div.style.bottom = '0px';
+ CM.Disp.TimerBars = {};
+ CM.Disp.BuffTimerBars = {};
- var type = document.createElement('span');
- type.style.display = 'inline-block';
- type.style.textAlign = 'right';
- type.style.width = '108px';
- type.style.marginRight = '5px';
- type.style.verticalAlign = 'text-top';
- type.textContent = name;
- div.appendChild(type);
+ // Create standard Golden Cookie bar
+ CM.Disp.TimerBars['CMTimerBarGC'] = CM.Disp.TimerBarCreateBar('CMTimerBarGC',
+ 'Next Cookie',
+ [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}]
+ );
+ CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarGC'])
- for (var i = 0; i < bars.length; i++) {
- var colorBar = document.createElement('span');
- colorBar.id = bars[i].id
- colorBar.style.display = 'inline-block';
- colorBar.style.height = '10px';
- if (bars.length - 1 == i) {
- colorBar.style.borderTopRightRadius = '10px';
- colorBar.style.borderBottomRightRadius = '10px';
- }
- if (typeof bars[i].color !== 'undefined') {
- colorBar.className = CM.Disp.colorBackPre + bars[i].color;
- }
- div.appendChild(colorBar);
- }
-
- var timer = document.createElement('span');
- timer.id = time;
- timer.style.marginLeft = '5px';
- timer.style.verticalAlign = 'text-top';
- div.appendChild(timer);
- return div
- }
-
- CM.Disp.TimerBarGC = document.createElement('div');
- CM.Disp.TimerBarGC.id = 'CMTimerBarGC';
- CM.Disp.TimerBarGC.style.height = '12px';
- CM.Disp.TimerBarGC.style.margin = '0px 10px';
- CM.Disp.TimerBarGC.style.position = 'relative';
- CM.Disp.TimerBarGC.appendChild(bar('Next Cookie', [{id: 'CMTimerBarGCMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarGCBar', color: CM.Disp.colorPurple}], 'CMTimerBarGCTime'));
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarGC);
-
- CM.Disp.TimerBarRen = document.createElement('div');
- CM.Disp.TimerBarRen.id = 'CMTimerBarRen';
- CM.Disp.TimerBarRen.style.height = '12px';
- CM.Disp.TimerBarRen.style.margin = '0px 10px';
- CM.Disp.TimerBarRen.style.position = 'relative';
- CM.Disp.TimerBarRen.appendChild(bar('Next Reindeer', [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}], 'CMTimerBarRenTime'));
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarRen);
-
- CM.Disp.TimerBarBuff1 = document.createElement('div');
- CM.Disp.TimerBarBuff1.id = 'CMTimerBarBuff1';
- CM.Disp.TimerBarBuff1.style.height = '12px';
- CM.Disp.TimerBarBuff1.style.margin = '0px 10px';
- CM.Disp.TimerBarBuff1.style.position = 'relative';
- CM.Disp.TimerBarBuff1.appendChild(bar('', [{id: 'CMTimerBarBuff1Bar'}], 'CMTimerBarBuff1Time'));
- CM.Disp.TimerBarBuff1.firstChild.firstChild.id = 'CMTimerBarBuff1Type';
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff1);
-
- CM.Disp.TimerBarBuff2 = document.createElement('div');
- CM.Disp.TimerBarBuff2.id = 'CMTimerBarBuff2';
- CM.Disp.TimerBarBuff2.style.height = '12px';
- CM.Disp.TimerBarBuff2.style.margin = '0px 10px';
- CM.Disp.TimerBarBuff2.style.position = 'relative';
- CM.Disp.TimerBarBuff2.appendChild(bar('', [{id: 'CMTimerBarBuff2Bar'}], 'CMTimerBarBuff2Time'));
- CM.Disp.TimerBarBuff2.firstChild.firstChild.id = 'CMTimerBarBuff2Type';
- CM.Disp.TimerBar.appendChild(CM.Disp.TimerBarBuff2);
+ // Create standard Reindeer bar
+ CM.Disp.TimerBars['CMTimerBarRen'] = CM.Disp.TimerBarCreateBar('CMTimerBarRen',
+ 'Next Reindeer',
+ [{id: 'CMTimerBarRenMinBar', color: CM.Disp.colorGray}, {id: 'CMTimerBarRenBar', color: CM.Disp.colorOrange}]
+ );
+ CM.Disp.TimerBar.appendChild(CM.Disp.TimerBars['CMTimerBarRen'])
l('wrapper').appendChild(CM.Disp.TimerBar);
}
-CM.Disp.ToggleTimerBar = function() {
- if (CM.Config.TimerBar == 1) {
- CM.Disp.TimerBar.style.display = '';
+/**
+ * This function creates an indivudual timer for the timer bar
+ * It is called by CM.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
+ */
+CM.Disp.TimerBarCreateBar = function(id, name, bars) {
+ timerBar = document.createElement('div');
+ timerBar.id = 'CMTimerBarGC';
+ timerBar.style.height = '12px';
+ timerBar.style.margin = '0px 10px';
+ timerBar.style.position = 'relative';
+
+ var div = document.createElement('div');
+ div.style.width = '100%';
+ div.style.height = '10px';
+ div.style.margin = 'auto';
+ div.style.position = 'absolute';
+ div.style.left = '0px';
+ div.style.top = '0px';
+ div.style.right = '0px';
+ div.style.bottom = '0px';
+
+ var type = document.createElement('span');
+ type.style.display = 'inline-block';
+ type.style.textAlign = 'right';
+ type.style.width = '108px';
+ type.style.marginRight = '5px';
+ type.style.verticalAlign = 'text-top';
+ type.textContent = name;
+ div.appendChild(type);
+
+ for (var i = 0; i < bars.length; i++) {
+ var colorBar = document.createElement('span');
+ colorBar.id = bars[i].id
+ colorBar.style.display = 'inline-block';
+ colorBar.style.height = '10px';
+ if (bars.length - 1 == i) {
+ colorBar.style.borderTopRightRadius = '10px';
+ colorBar.style.borderBottomRightRadius = '10px';
+ }
+ if (typeof bars[i].color !== 'undefined') {
+ colorBar.className = CM.Disp.colorBackPre + bars[i].color;
+ }
+ div.appendChild(colorBar);
}
- else {
- CM.Disp.TimerBar.style.display = 'none';
- }
- CM.Disp.UpdateBotTimerBarDisplay();
-}
-
-CM.Disp.ToggleTimerBarPos = function() {
- if (CM.Config.TimerBarPos == 0) {
- CM.Disp.TimerBar.style.width = '30%';
- CM.Disp.TimerBar.style.bottom = '';
- l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft'));
- }
- else {
- CM.Disp.TimerBar.style.width = '100%';
- CM.Disp.TimerBar.style.bottom = '0px';
- l('wrapper').appendChild(CM.Disp.TimerBar);
- }
- CM.Disp.UpdateBotTimerBarDisplay();
+
+ var timer = document.createElement('span');
+ timer.id = id + 'Time';
+ timer.style.marginLeft = '5px';
+ timer.style.verticalAlign = 'text-top';
+ div.appendChild(timer);
+
+ timerBar.appendChild(div);
+
+ return timerBar;
}
+/**
+ * This function creates an indivudual timer for the timer bar
+ * It is called by CM.Loop()
+ */
CM.Disp.UpdateTimerBar = function() {
if (CM.Config.TimerBar == 1) {
// label width: 113, timer width: 26, div margin: 20
var maxWidth = CM.Disp.TimerBar.offsetWidth - 159;
- var count = 0;
+ var numberOfTimers = 0;
+ // Regulates visibility of Golden Cookie timer
if (Game.shimmerTypes['golden'].spawned == 0 && !Game.Has('Golden switch [off]')) {
- CM.Disp.TimerBarGC.style.display = '';
+ CM.Disp.TimerBars['CMTimerBarGC'].style.display = '';
l('CMTimerBarGCMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['golden'].minTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px';
if (Game.shimmerTypes['golden'].minTime == Game.shimmerTypes['golden'].maxTime) {
l('CMTimerBarGCMinBar').style.borderTopRightRadius = '10px';
@@ -718,107 +645,96 @@ CM.Disp.UpdateTimerBar = function() {
}
l('CMTimerBarGCBar').style.width = Math.round(Math.min(Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].minTime, Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) * maxWidth / Game.shimmerTypes['golden'].maxTime) + 'px';
l('CMTimerBarGCTime').textContent = Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarGC.style.display = 'none';
+ numberOfTimers++;
}
+ else CM.Disp.TimerBars['CMTimerBarGC'].style.display = 'none';
+ // Regulates visibility of Reinder timer
if (Game.season == 'christmas' && Game.shimmerTypes['reindeer'].spawned == 0) {
- CM.Disp.TimerBarRen.style.display = '';
+ CM.Disp.TimerBars['CMTimerBarRen'].style.display = '';
l('CMTimerBarRenMinBar').style.width = Math.round(Math.max(0, Game.shimmerTypes['reindeer'].minTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px';
l('CMTimerBarRenBar').style.width = Math.round(Math.min(Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].minTime, Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) * maxWidth / Game.shimmerTypes['reindeer'].maxTime) + 'px';
l('CMTimerBarRenTime').textContent = Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps);
- count++;
+ numberOfTimers++;
}
else {
- CM.Disp.TimerBarRen.style.display = 'none';
+ CM.Disp.TimerBars['CMTimerBarRen'].style.display = 'none';
}
- var buffCount = 0;
+ // On every frame all buff-timers are deleted and re-created
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.BuffTimerBars[i].remove()
+ }
+ CM.Disp.BuffTimerBars = {}
for (var i in Game.buffs) {
if (Game.buffs[i]) {
- buffCount++;
- CM.Disp['TimerBarBuff' + buffCount].style.display = '';
- l('CMTimerBarBuff' + buffCount + 'Type').textContent = Game.buffs[i].name;
+ timer = CM.Disp.TimerBarCreateBar(Game.buffs[i].name, Game.buffs[i].name, [{id: Game.buffs[i].name + 'Bar'}])
+ timer.style.display = '';
var classColor = '';
+ // Gives specific timers specific colors
if (typeof CM.Disp.buffColors[Game.buffs[i].name] !== 'undefined') {
classColor = CM.Disp.buffColors[Game.buffs[i].name];
}
- else {
- classColor = CM.Disp.colorPurple;
- }
- l('CMTimerBarBuff' + buffCount + 'Bar').className = CM.Disp.colorBackPre + classColor;
- l('CMTimerBarBuff' + buffCount + 'Bar').style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px';
- l('CMTimerBarBuff' + buffCount + 'Time').textContent = Math.ceil(Game.buffs[i].time / Game.fps);
- count++;
- if (buffCount == 2) {
- break;
- }
+ else classColor = CM.Disp.colorPurple;
+ timer.lastChild.children[1].className = CM.Disp.colorBackPre + classColor;
+ timer.lastChild.children[1].style.width = Math.round(Game.buffs[i].time * maxWidth / Game.buffs[i].maxTime) + 'px';
+ timer.lastChild.children[2].textContent = Math.ceil(Game.buffs[i].time / Game.fps);
+ numberOfTimers++;
+ CM.Disp.BuffTimerBars[Game.buffs[i].name] = timer
}
}
- if (buffCount < 2) {
- CM.Disp.TimerBarBuff2.style.display = 'none';
- if (buffCount < 1) {
- CM.Disp.TimerBarBuff1.style.display = 'none';
- }
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.TimerBar.appendChild(CM.Disp.BuffTimerBars[i])
}
- /*if (Game.frenzy > 0) {
- CM.Disp.TimerBarBuff1.style.display = '';
- if (Game.frenzyPower == 7) {
- l('CMTimerBarBuff1Type').textContent = 'Frenzy';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorYellow;
+ if (numberOfTimers != 0) {
+ var height = 48 / numberOfTimers;
+ for (var i in CM.Disp.TimerBars) {
+ CM.Disp.TimerBars[i].style.height = height + 'px';
}
- else if (Game.frenzyPower == 0.5) {
- l('CMTimerBarBuff1Type').textContent = 'Clot';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorRed;
+ for (var i in CM.Disp.BuffTimerBars) {
+ CM.Disp.BuffTimerBars[i].style.height = height + 'px';
}
- else if (Game.frenzyPower == 15) {
- l('CMTimerBarBuff1Type').textContent = 'Dragon Harvest';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBrown;
- }
- else {
- l('CMTimerBarBuff1Type').textContent = 'Blood Frenzy';
- l('CMTimerBarBuff1Bar').className = CM.Disp.colorBackPre + CM.Disp.colorGreen;
- }
- l('CMTimerBarBuff1Bar').style.width = Math.round(Game.frenzy * maxWidth / Game.frenzyMax) + 'px';
- l('CMTimerBarBuff1Time').textContent = Math.ceil(Game.frenzy / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarBuff1.style.display = 'none';
- }
-
- if (Game.clickFrenzy > 0) {
- CM.Disp.TimerBarBuff2.style.display = '';
- if (Game.clickFrenzyPower == 777) {
- l('CMTimerBarBuff2Type').textContent = 'Click Frenzy';
- l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorBlue;
- }
- else {
- l('CMTimerBarBuff2Type').textContent = 'Dragonflight';
- l('CMTimerBarBuff2Bar').className = CM.Disp.colorBackPre + CM.Disp.colorPink;
- }
- l('CMTimerBarBuff2Bar').style.width = Math.round(Game.clickFrenzy * maxWidth / Game.clickFrenzyMax) + 'px';
- l('CMTimerBarBuff2Time').textContent = Math.ceil(Game.clickFrenzy / Game.fps);
- count++;
- }
- else {
- CM.Disp.TimerBarBuff2.style.display = 'none';
- }*/
-
- if (count != 0) {
- var height = 48 / count;
- CM.Disp.TimerBarGC.style.height = height + 'px';
- CM.Disp.TimerBarRen.style.height = height + 'px';
- CM.Disp.TimerBarBuff1.style.height = height + 'px';
- CM.Disp.TimerBarBuff2.style.height = height + 'px';
}
}
}
-CM.Disp.UpdateBotTimerBarDisplay = function() {
+/**
+ * This function changes the visibility of the timer bar
+ * It is called by CM.Disp.UpdateAscendState() or a change in CM.Config.TimerBar
+ */
+CM.Disp.ToggleTimerBar = function() {
+ if (CM.Config.TimerBar == 1) CM.Disp.TimerBar.style.display = '';
+ else CM.Disp.TimerBar.style.display = 'none';
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/**
+ * This function changes the position of the timer bar
+ * It is called by a change in CM.Config.TimerBarPos
+ */
+CM.Disp.ToggleTimerBarPos = function() {
+ if (CM.Config.TimerBarPos == 0) {
+ CM.Disp.TimerBar.style.width = '30%';
+ CM.Disp.TimerBar.style.bottom = '';
+ l('game').insertBefore(CM.Disp.TimerBar, l('sectionLeft'));
+ }
+ else {
+ CM.Disp.TimerBar.style.width = '100%';
+ CM.Disp.TimerBar.style.bottom = '0px';
+ l('wrapper').appendChild(CM.Disp.TimerBar);
+ }
+ CM.Disp.UpdateBotTimerBarPosition();
+}
+
+/********
+ * Section: Functions related to the both the bottom and timer bar
+
+/**
+ * This function changes the position of both the bottom and timer bar
+ * It is called by CM.Disp.ToggleTimerBar(), CM.Disp.ToggleTimerBarPos() and CM.Disp.ToggleBotBar()
+ */
+CM.Disp.UpdateBotTimerBarPosition = function() {
if (CM.Config.BotBar == 1 && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 1) {
CM.Disp.BotBar.style.bottom = '48px';
l('game').style.bottom = '118px';
@@ -846,20 +762,19 @@ CM.Disp.UpdateBotTimerBarDisplay = function() {
/********
* Section: Functions related to column of buildings/objects
- * TODO: Annotate functions */
+/**
+ * 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.Config.SortBuildings is set
+ * The function is called by CM.Loop(), CM.Disp.UpdateColors() & CM.Disp.RefreshScale()
+ * And by changes in CM.Config.BuildColor, CM.Config.SortBuild & CM.ConfigData.BulkBuildColor
+ */
CM.Disp.UpdateBuildings = function() {
if (CM.Config.BuildColor == 1 && Game.buyMode == 1) {
var target = '';
- if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) {
- target = 'Objects10';
- }
- else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) {
- target = 'Objects100';
- }
- else {
- target = 'Objects';
- }
+ if (Game.buyBulk == 10 && CM.Config.BulkBuildColor == 1) target = 'Objects10';
+ else if (Game.buyBulk == 100 && CM.Config.BulkBuildColor == 1) target = 'Objects100';
+ else target = 'Objects';
for (var i in CM.Cache[target]) {
l('productPrice' + Game.Objects[i].id).style.color = CM.Config.Colors[CM.Cache[target][i].color];
}
@@ -913,8 +828,44 @@ CM.Disp.UpdateBuildings = function() {
/********
* Section: Functions related to the Upgrade Bar
- * TODO: Annotate functions */
+/**
+ * This function toggles the upgrade bar and the colours of upgrades
+ * It is called by a change in CM.Config.UpBarColor
+ */
+CM.Disp.ToggleUpgradeBarAndColor = function() {
+ if (CM.Config.UpBarColor == 1) { // Colours and bar on
+ CM.Disp.UpgradeBar.style.display = '';
+ CM.Disp.UpdateUpgrades();
+ }
+ else if (CM.Config.UpBarColor == 2) {// Colours on and bar off
+ CM.Disp.UpgradeBar.style.display = 'none';
+ CM.Disp.UpdateUpgrades();
+ }
+ else { // Colours and bar off
+ CM.Disp.UpgradeBar.style.display = 'none';
+ Game.RebuildUpgrades();
+ }
+}
+
+/**
+ * This function toggles the position of the upgrade bar from fixed or non-fixed mode
+ * It is called by a change in CM.Config.UpgradeBarFixedPos
+ */
+CM.Disp.ToggleUpgradeBarFixedPos = function() {
+ if (CM.Config.UpgradeBarFixedPos == 1) { // Fix to top of screen when scrolling
+ CM.Disp.UpgradeBar.style.position = 'sticky';
+ CM.Disp.UpgradeBar.style.top = '0px';
+ }
+ else {
+ CM.Disp.UpgradeBar.style.position = ''; // Possible to scroll offscreen
+ }
+}
+
+/**
+ * This function creates the upgrade bar above the upgrade-section in the right section of the screen
+ * The number (.textContent) of upgrades gets updated by CM.Disp.UpdateUpgrades()
+ */
CM.Disp.CreateUpgradeBar = function() {
CM.Disp.UpgradeBar = document.createElement('div');
CM.Disp.UpgradeBar.id = 'CMUpgradeBar';
@@ -927,6 +878,34 @@ CM.Disp.CreateUpgradeBar = function() {
CM.Disp.UpgradeBar.onmouseout = function() { Game.tooltip.hide(); };
var placeholder = document.createElement('div');
+ placeholder.appendChild(CM.Disp.CreateUpgradeBarLegend());
+ CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');};
+
+ var upgradeNumber = function(id, color) {
+ var span = document.createElement('span');
+ span.id = id;
+ span.className = CM.Disp.colorTextPre + color;
+ span.style.width = '14.28571428571429%';
+ span.style.display = 'inline-block';
+ span.textContent = '0';
+ return span;
+ }
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple));
+ CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray));
+
+ l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]);
+}
+
+/**
+ * This function creates the legend for the upgrade bar, it is called by CM.Disp.CreateUpgradeBar
+ * @returns {object} legend The legend-object to be added
+ */
+CM.Disp.CreateUpgradeBarLegend = function() {
var legend = document.createElement('div');
legend.style.minWidth = '330px';
legend.style.marginBottom = '4px';
@@ -957,59 +936,35 @@ CM.Disp.CreateUpgradeBar = function() {
legend.appendChild(legendLine(CM.Disp.colorRed, 'Same as worst PP building'));
legend.appendChild(legendLine(CM.Disp.colorPurple, 'Worse than worst PP building'));
legend.appendChild(legendLine(CM.Disp.colorGray, 'Negative or infinity PP'));
- placeholder.appendChild(legend);
-
- CM.Disp.UpgradeBar.onmouseover = function() {Game.tooltip.draw(this, escape(placeholder.innerHTML), 'store');};
-
- var upgradeNumber = function(id, color) {
- var span = document.createElement('span');
- span.id = id;
- span.className = CM.Disp.colorTextPre + color;
- span.style.width = '14.28571428571429%';
- span.style.display = 'inline-block';
- span.textContent = '0';
- return span;
- }
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarBlue', CM.Disp.colorBlue));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGreen', CM.Disp.colorGreen));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarYellow', CM.Disp.colorYellow));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarOrange', CM.Disp.colorOrange));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarRed', CM.Disp.colorRed));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarPurple', CM.Disp.colorPurple));
- CM.Disp.UpgradeBar.appendChild(upgradeNumber('CMUpgradeBarGray', CM.Disp.colorGray));
-
- l('upgrades').parentNode.insertBefore(CM.Disp.UpgradeBar, l('upgrades').parentNode.childNodes[3]);
-}
-
-CM.Disp.ToggleUpBarColor = function() {
- if (CM.Config.UpBarColor == 1) {
- CM.Disp.UpgradeBar.style.display = '';
- CM.Disp.UpdateUpgrades();
- }
- else if (CM.Config.UpBarColor == 2) {
- CM.Disp.UpgradeBar.style.display = 'none';
- CM.Disp.UpdateUpgrades();
- }
- else {
- CM.Disp.UpgradeBar.style.display = 'none';
- Game.RebuildUpgrades();
- }
-}
-
-CM.Disp.ToggleUpgradeBarFixedPos = function() {
- if (CM.Config.UpgradeBarFixedPos == 1) {
- CM.Disp.UpgradeBar.style.position = 'sticky';
- CM.Disp.UpgradeBar.style.top = '0px';
- }
- else {
- CM.Disp.UpgradeBar.style.position = '';
- }
+ return legend;
}
/********
* Section: Functions related to the flashes/sound/notifications
- * TODO: Annotate functions */
+/**
+ * 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()
+ */
+CM.Disp.CreateWhiteScreen = function() {
+ CM.Disp.WhiteScreen = document.createElement('div');
+ CM.Disp.WhiteScreen.id = 'CMWhiteScreen';
+ CM.Disp.WhiteScreen.style.width = '100%';
+ CM.Disp.WhiteScreen.style.height = '100%';
+ CM.Disp.WhiteScreen.style.backgroundColor = 'white';
+ CM.Disp.WhiteScreen.style.display = 'none';
+ CM.Disp.WhiteScreen.style.zIndex = '9999999999';
+ CM.Disp.WhiteScreen.style.position = 'absolute';
+ l('wrapper').appendChild(CM.Disp.WhiteScreen);
+}
+
+/**
+ * This function creates a flash depending on configs. It is called by all functions
+ * that check game-events and which have settings for Flashes (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {number} mode Sets the intensity of the flash, used to recursively dim flash
+ * All calls of function have use mode == 3
+ * @param {string} config The setting in CM.Config that is checked before creating the flash
+ */
CM.Disp.Flash = function(mode, config) {
if ((CM.Config[config] == 1 && mode == 3) || mode == 1) {
CM.Disp.WhiteScreen.style.opacity = '0.5';
@@ -1025,11 +980,16 @@ CM.Disp.Flash = function(mode, config) {
CM.Disp.WhiteScreen.style.opacity = '1';
setTimeout(function() {CM.Disp.Flash(1, config);}, 1000/Game.fps);
}
- else if (mode == 0) {
- CM.Disp.WhiteScreen.style.display = 'none';
- }
+ else if (mode == 0) CM.Disp.WhiteScreen.style.display = 'none';
}
+/**
+ * This function plays a sound depending on configs. It is called by all functions
+ * that check game-events and which have settings for sound (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {variable} url A variable that gives the url for the sound (e.g., CM.Config.GCSoundURL)
+ * @param {string} sndConfig The setting in CM.Config that is checked before creating the sound
+ * @param {string} volConfig The setting in CM.Config that is checked to determine volume
+ */
CM.Disp.PlaySound = function(url, sndConfig, volConfig) {
if (CM.Config[sndConfig] == 1) {
var sound = new realAudio(url);
@@ -1038,17 +998,26 @@ CM.Disp.PlaySound = function(url, sndConfig, volConfig) {
}
}
+/**
+ * This function creates a notifcation depending on configs. It is called by all functions
+ * that check game-events and which have settings for notifications (e.g., Golden Cookies appearing, Magic meter being full)
+ * @param {string} notifyConfig The setting in CM.Config that is checked before creating the notification
+ * @param {string} title The title of the to-be created notifications
+ * @param {string} message The text of the to-be created notifications
+ */
CM.Disp.Notification = function(notifyConfig, title, message) {
if (CM.Config[notifyConfig] == 1 && document.visibilityState == 'hidden') {
var CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico'
- var notification = new Notification(title, {body: message, badge: CookieIcon});
+ notification = new Notification(title, {body: message, badge: CookieIcon});
}
}
/********
* Section: Functions related to updating the tab in the browser's tab-bar
- * TODO: Annotate functions */
+/**
+ * This function creates the Favicon, it is called by CM.DelayInit()
+ */
CM.Disp.CreateFavicon = function() {
CM.Disp.Favicon = document.createElement('link');
CM.Disp.Favicon.id = 'CMFavicon';
@@ -1057,20 +1026,23 @@ CM.Disp.CreateFavicon = function() {
document.getElementsByTagName('head')[0].appendChild(CM.Disp.Favicon);
}
+/**
+ * This function updates the Favicon depending on whether a Golden Cookie has spawned
+ * It is called on every loop by CM.Main.CheckGoldenCookie() or by a change in CM.Config.Favicon
+ * By relying on CM.Cache.spawnedGoldenShimmer it only changes for non-user spawned cookie
+ */
CM.Disp.UpdateFavicon = function() {
if (CM.Config.Favicon == 1) {
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
- }
- else {
- CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
- }
- }
- else {
- CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
+ if (CM.Cache.spawnedGoldenShimmer.wrath) CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/wrathCookie.ico';
+ else CM.Disp.Favicon.href = 'https://aktanusa.github.io/CookieMonster/favicon/goldenCookie.ico';
}
+ else CM.Disp.Favicon.href = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
}
+/**
+ * This function updates the tab title
+ * It is called on every loop by Game.Logic() which also sets CM.Cache.Title to Game.cookies
+ */
CM.Disp.UpdateTitle = function() {
if (Game.OnAscend || CM.Config.Title == 0) {
document.title = CM.Cache.Title;
@@ -1078,63 +1050,53 @@ CM.Disp.UpdateTitle = function() {
else if (CM.Config.Title == 1) {
var addFC = false;
var addSP = false;
-
var titleGC;
var titleFC;
var titleSP;
- if (CM.Disp.lastGoldenCookieState) {
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- titleGC = '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
- else {
- titleGC = '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
+
+ if (CM.Cache.spawnedGoldenShimmer) {
+ if (CM.Cache.spawnedGoldenShimmer.wrath) titleGC = '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
+ else titleGC = '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
}
else if (!Game.Has('Golden switch [off]')) {
titleGC = '[' + Math.ceil((Game.shimmerTypes['golden'].maxTime - Game.shimmerTypes['golden'].time) / Game.fps) + ']';
}
- else {
- titleGC = '[GS]'
- }
- if (CM.Disp.lastTickerFortuneState) {
+ else titleGC = '[GS]'
+
+ if (CM.Main.lastTickerFortuneState) {
addFC = true;
titleFC = '[F]';
}
+
if (Game.season == 'christmas') {
addSP = true;
- if (CM.Disp.lastSeasonPopupState) {
- titleSP = '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
- }
+ if (CM.Main.lastSeasonPopupState) titleSP = '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']';
else {
titleSP = '[' + Math.ceil((Game.shimmerTypes['reindeer'].maxTime - Game.shimmerTypes['reindeer'].time) / Game.fps) + ']';
}
}
+ // Remove previous timers and add current cookies
var str = CM.Cache.Title;
if (str.charAt(0) == '[') {
str = str.substring(str.lastIndexOf(']') + 1);
}
-
document.title = titleGC + (addFC ? titleFC : '') + (addSP ? titleSP : '') + ' ' + str;
}
else if (CM.Config.Title == 2) {
var str = '';
var spawn = false;
- if (CM.Disp.lastGoldenCookieState) {
+ if (CM.Cache.spawnedGoldenShimmer) {
spawn = true;
- if (CM.Disp.spawnedGoldenShimmer.wrath) {
- str += '[W ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
- else {
- str += '[G ' + Math.ceil(CM.Disp.spawnedGoldenShimmer.life / Game.fps) + ']';
- }
+ if (CM.Cache.spawnedGoldenShimmer.wrath) str += '[W ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
+ else str += '[G ' + Math.ceil(CM.Cache.spawnedGoldenShimmer.life / Game.fps) + ']';
}
- if (CM.Disp.lastTickerFortuneState) {
+ if (CM.Main.lastTickerFortuneState) {
spawn = true;
str += '[F]';
}
- if (Game.season == 'christmas' && CM.Disp.lastSeasonPopupState) {
- str += '[R ' + Math.ceil(CM.Disp.seasonPopShimmer.life / Game.fps) + ']';
+ if (Game.season == 'christmas' && CM.Main.lastSeasonPopupState) {
+ str += '[R ' + Math.ceil(CM.Cache.seasonPopShimmer.life / Game.fps) + ']';
spawn = true;
}
if (spawn) str += ' - ';
@@ -1147,8 +1109,12 @@ CM.Disp.UpdateTitle = function() {
/********
* Section: Functions related to the Golden Cookie Timers
- * TODO: Annotate functions */
+/**
+ * This function creates a new Golden Cookie Timer and appends it CM.Disp.GCTimers based on the id of the cookie
+ * It is called by CM.Main.CheckGoldenCookie()
+ * @param {object} cookie A Golden Cookie object
+ */
CM.Disp.CreateGCTimer = function(cookie) {
GCTimer = document.createElement('div');
GCTimer.id = 'GCTimer' + cookie.id
@@ -1162,6 +1128,7 @@ CM.Disp.CreateGCTimer = function(cookie) {
GCTimer.style.fontSize = '35px';
GCTimer.style.cursor = 'pointer';
GCTimer.style.display = 'block';
+ if (CM.Config.GCTimer == 0) GCTimer.style.display = 'none';
GCTimer.style.left = cookie.l.style.left;
GCTimer.style.top = cookie.l.style.top;
GCTimer.onclick = function () {cookie.pop();};
@@ -1172,160 +1139,35 @@ CM.Disp.CreateGCTimer = function(cookie) {
l('shimmers').appendChild(GCTimer);
}
+/**
+ * This function toggles GC Timers are visible
+ * It is called by a change in CM.Config.GCTimer
+ */
CM.Disp.ToggleGCTimer = function() {
if (CM.Config.GCTimer == 1) {
- if (CM.Disp.lastGoldenCookieState) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'block';
- CM.Disp.GCTimers[i].style.left = CM.Disp.goldenShimmersByID[i].l.style.left;
- CM.Disp.GCTimers[i].style.top = CM.Disp.goldenShimmersByID[i].l.style.top;
- }
+ for (var i in CM.Disp.GCTimers) {
+ CM.Disp.GCTimers[i].style.display = 'block';
+ CM.Disp.GCTimers[i].style.left = CM.Cache.goldenShimmersByID[i].l.style.left;
+ CM.Disp.GCTimers[i].style.top = CM.Cache.goldenShimmersByID[i].l.style.top;
}
}
else {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'none';
- }
- }
-}
-
-/********
- * Section: Functions related to checking for changes in Minigames/GC's/Ticker
- * TODO: Annotate functions
- * TODO: Possibly move this section */
-
-CM.Disp.CheckGoldenCookie = function() {
- CM.Disp.FindShimmer();
- for (var i in CM.Disp.GCTimers) {
- if (typeof CM.Disp.goldenShimmersByID[i] == "undefined") {
- CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
- // TODO remove delete here
- delete CM.Disp.GCTimers[i];
- }
- }
- if (CM.Disp.lastGoldenCookieState != Game.shimmerTypes['golden'].n) {
- CM.Disp.lastGoldenCookieState = Game.shimmerTypes['golden'].n;
- if (CM.Disp.lastGoldenCookieState) {
- if (CM.Disp.lastSpawnedGoldenCookieState < CM.Disp.currSpawnedGoldenCookieState) {
- CM.Disp.Flash(3, 'GCFlash');
- CM.Disp.PlaySound(CM.Config.GCSoundURL, 'GCSound', 'GCVolume');
- CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
- }
- CM.Disp.lastSpawnedGoldenCookieState = CM.Disp.currSpawnedGoldenCookieState
- CM.Disp.UpdateFavicon();
-
- if (CM.Config.GCTimer == 1) {
- for (var i in Game.shimmers) {
- if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") {
- CM.Disp.CreateGCTimer(Game.shimmers[i]);
- }
- }
- }
- }
- else if (CM.Config.GCTimer == 1) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.display = 'none';
- }
- }
- }
- else if (CM.Config.GCTimer == 1 && CM.Disp.lastGoldenCookieState) {
- for (var i in CM.Disp.GCTimers) {
- CM.Disp.GCTimers[i].style.opacity = CM.Disp.goldenShimmersByID[i].l.style.opacity;
- CM.Disp.GCTimers[i].style.transform = CM.Disp.goldenShimmersByID[i].l.style.transform;
- CM.Disp.GCTimers[i].textContent = Math.ceil(CM.Disp.goldenShimmersByID[i].life / Game.fps);
- }
- }
-}
-
-CM.Disp.CheckTickerFortune = function() {
- if (CM.Disp.lastTickerFortuneState != (Game.TickerEffect && Game.TickerEffect.type == 'fortune')) {
- CM.Disp.lastTickerFortuneState = (Game.TickerEffect && Game.TickerEffect.type == 'fortune');
- if (CM.Disp.lastTickerFortuneState) {
- CM.Disp.Flash(3, 'FortuneFlash');
- CM.Disp.PlaySound(CM.Config.FortuneSoundURL, 'FortuneSound', 'FortuneVolume');
- CM.Disp.Notification('FortuneNotification', "Fortune Cookie found", "A Fortune Cookie has appeared on the Ticker.")
- }
- }
-}
-
-CM.Disp.CheckSeasonPopup = function() {
- if (CM.Disp.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) {
- CM.Disp.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned;
- if (CM.Disp.lastSeasonPopupState && Game.season=='christmas') {
- // Needed for some of the functions to use the right object
- for (var i in Game.shimmers) {
- if (Game.shimmers[i].spawnLead && Game.shimmers[i].type == 'reindeer') {
- CM.Disp.seasonPopShimmer = Game.shimmers[i];
- break;
- }
- }
-
- CM.Disp.Flash(3, 'SeaFlash');
- CM.Disp.PlaySound(CM.Config.SeaSoundURL, 'SeaSound', 'SeaVolume');
- CM.Disp.Notification('SeaNotification',"Reindeer sighted!", "A Reindeer has spawned. Click it now!")
- }
- }
-}
-
-CM.Disp.CheckGardenTick = function() {
- if (Game.Objects['Farm'].minigameLoaded && CM.Disp.lastGardenNextStep != Game.Objects['Farm'].minigame.nextStep) {
- if (CM.Disp.lastGardenNextStep != 0 && CM.Disp.lastGardenNextStep < Date.now()) {
- CM.Disp.Flash(3, 'GardFlash');
- CM.Disp.PlaySound(CM.Config.GardSoundURL, 'GardSound', 'GardVolume');
- }
- CM.Disp.lastGardenNextStep = Game.Objects['Farm'].minigame.nextStep;
- }
-}
-
-CM.Disp.CheckMagicMeter = function() {
- if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) {
- var minigame = Game.Objects['Wizard tower'].minigame;
- if (minigame.magic < minigame.magicM) {
- CM.Disp.lastMagicBarFull = false;
- }
- else if (!CM.Disp.lastMagicBarFull) {
- CM.Disp.lastMagicBarFull = true;
- CM.Disp.Flash(3, 'MagicFlash');
- CM.Disp.PlaySound(CM.Config.MagicSoundURL, 'MagicSound', 'MagicVolume');
- CM.Disp.Notification('MagicNotification', "Magic Meter full", "Your Magic Meter is full. Cast a spell!")
- }
- }
-}
-
-CM.Disp.CheckWrinklerCount = function() {
- if (Game.elderWrath > 0) {
- var CurrentWrinklers = 0;
- for (var i in Game.wrinklers) {
- if (Game.wrinklers[i].phase == 2) CurrentWrinklers++;
- }
- if (CurrentWrinklers > CM.Disp.lastWrinklerCount) {
- CM.Disp.lastWrinklerCount = CurrentWrinklers
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxFlash) {
- CM.Disp.Flash(3, 'WrinklerMaxFlash');
- } else {
- CM.Disp.Flash(3, 'WrinklerFlash');
- }
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) {
- CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
- } else {
- CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
- }
- if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.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.Disp.lastWrinklerCount = CurrentWrinklers
- }
+ for (var i in CM.Disp.GCTimers) CM.Disp.GCTimers[i].style.display = 'none';
}
}
/********
* Section: Functions related to Tooltips
- * TODO: Annotate functions */
-CM.Disp.CreateTooltip = function(placeholder, text, minWidth) {
+/**
+ * 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()
+ * @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
+ */
+CM.Disp.CreateSimpleTooltip = function(placeholder, text, minWidth) {
CM.Disp[placeholder] = document.createElement('div');
var desc = document.createElement('div');
desc.style.minWidth = minWidth;
@@ -1337,33 +1179,216 @@ CM.Disp.CreateTooltip = function(placeholder, text, minWidth) {
CM.Disp[placeholder].appendChild(desc);
}
-CM.Disp.UpdateTooltipLocation = function() {
- if (Game.tooltip.origin == 'store') {
- var warnOffset = 0;
- if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1) warnOffset = CM.Disp.TooltipWarn.clientHeight - 4;
- Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px';
+/**
+ * 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();}');
+ }
}
- // Kept for future possible use if the code changes again
- /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
- Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px';
- }*/
}
-CM.Disp.CreateTooltipWarn = function() {
+/**
+ * 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
+ *
+ */
+CM.Disp.ReplaceTooltipUpgrade = function() {
+ CM.Disp.TooltipUpgradeBackup = [];
+ for (var i in Game.UpgradesInStore) {
+ var me = Game.UpgradesInStore[i];
+ if (l('upgrade' + i).onmouseover != null) {
+ CM.Disp.TooltipUpgradeBackup[i] = l('upgrade' + i).onmouseover;
+ eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + 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'
+ * 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()
+ * @param {string} type Type of tooltip (b, u, s or g)
+ * @param {string} name Name of the object/item the tooltip relates to
+ * @returns {string} l('tooltip').innerHTML The HTML of the l('tooltip')-object
+ */
+CM.Disp.Tooltip = function(type, name) {
+ if (type == 'b') { // Buildings
+ l('tooltip').innerHTML = Game.Objects[name].tooltip();
+ // Adds amortization info to the list of info per building
+ if (CM.Config.TooltipAmor == 1) {
+ var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount);
+ var amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
+ if (amortizeAmount > 0) {
+ l('tooltip').innerHTML = l('tooltip').innerHTML
+ .split('so far')
+ .join('so far
• ' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor((buildPrice - Game.Objects[name].totalCookies) / (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')');
+ }
+ }
+ if (Game.buyMode == -1) {
+ /*
+ * Fix sell price displayed in the object tooltip.
+ *
+ * The buildings sell price displayed by the game itself (without any mod) is incorrect.
+ * The following line of code fixes this issue, and can be safely removed when the game gets fixed.
+ *
+ * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262
+ */
+ l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1)));
+ }
+ }
+ else if (type == 'u') { // Upgrades
+ if (!Game.UpgradesInStore[name]) return '';
+ l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store');
+ }
+ else if (type === 's') l('tooltip').innerHTML = Game.lumpTooltip(); // Sugar Lumps
+ else if (type === 'g') l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)(); // Grimoire
+
+ // Adds area for extra tooltip-sections
+ var area = document.createElement('div');
+ area.id = 'CMTooltipArea';
+ l('tooltip').appendChild(area);
+
+ // Sets global variables used by CM.Disp.UpdateTooltip()
+ CM.Disp.tooltipType = type;
+ CM.Disp.tooltipName = name;
+
+ CM.Disp.UpdateTooltip();
+
+ return l('tooltip').innerHTML;
+}
+
+/**
+ * This function creates a tooltipBox object which contains all CookieMonster added tooltip information.
+ * It is called by all CM.Disp.UpdateTooltip functions.
+ * @returns {object} div An object containing the stylized box
+ */
+CM.Disp.TooltipCreateTooltipBox = function() {
+ l('tooltip').firstChild.style.paddingBottom = '4px'; // Sets padding on base-tooltip
+ var tooltipBox = document.createElement('div');
+ tooltipBox.style.border = '1px solid';
+ tooltipBox.style.padding = '4px';
+ tooltipBox.style.margin = '0px -4px';
+ tooltipBox.id = 'CMTooltipBorder';
+ tooltipBox.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
+ return tooltipBox
+}
+
+/**
+ * This function creates a header object for tooltips.
+ * It is called by all CM.Disp.UpdateTooltip functions.
+ * @param {string} text Title of header
+ * @returns {object} div An object containing the stylized header
+ */
+CM.Disp.TooltipCreateHeader = function(text) {
+ var div = document.createElement('div');
+ div.style.fontWeight = 'bold';
+ div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
+ div.textContent = text;
+ return div;
+}
+
+/**
+ * This function appends the sections for Bonus Income, PP and Time left (to achiev) to the tooltip-object
+ * It is called by CM.Disp.UpdateTooltipBuilding() and CM.Disp.UpdateTooltipUpgrade()
+ * The actual data is added by the Update-functions themselves
+ * @param {object} tooltip Object of a TooltipBox, normally created by a call to CM.Disp.TooltipCreateTooltipBox()
+ */
+CM.Disp.TooltipCreateCalculationSection = function(tooltip) {
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Bonus Income'));
+ var income = document.createElement('div');
+ income.style.marginBottom = '4px';
+ income.style.color = 'white';
+ income.id = 'CMTooltipIncome';
+ tooltip.appendChild(income);
+
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Payback Period'));
+ var pp = document.createElement('div');
+ pp.style.marginBottom = '4px';
+ pp.id = 'CMTooltipPP';
+ tooltip.appendChild(pp);
+
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Time Left'));
+ var time = document.createElement('div');
+ time.id = 'CMTooltipTime';
+ tooltip.appendChild(time);
+
+ if (CM.Disp.tooltipType == 'b') {
+ tooltip.appendChild(CM.Disp.TooltipCreateHeader('Production left till next achievement'));
+ tooltip.lastChild.id = 'CMTooltipProductionHeader'; // Assign a id in order to hid when no achiev's are left
+ var production = document.createElement('div');
+ production.id = 'CMTooltipProduction';
+ tooltip.appendChild(production);
+ }
+}
+
+/**
+ * This function creates the tooltip objectm for warnings
+ * It is called by CM.Disp.UpdateTooltipWarnings() whenever the tooltip type is 'b' or 'u'
+ * The object is also removed by CM.Disp.UpdateTooltipWarnings() when type is 's' or 'g'
+ * @returns {object} CM.Disp.TooltipWarn The Warnings-tooltip object
+ */
+CM.Disp.TooltipCreateWarningSection = function() {
CM.Disp.TooltipWarn = document.createElement('div');
CM.Disp.TooltipWarn.style.position = 'absolute';
- CM.Disp.TooltipWarn.style.display = 'none';
+ CM.Disp.TooltipWarn.style.display = 'block';
CM.Disp.TooltipWarn.style.left = 'auto';
CM.Disp.TooltipWarn.style.bottom = 'auto';
+ CM.Disp.TooltipWarn.id = "CMDispTooltipWarningParent";
var create = function(boxId, color, labelTextFront, labelTextBack, deficitId) {
var box = document.createElement('div');
box.id = boxId;
box.style.display = 'none';
- box.style.WebkitTransition = 'opacity 0.1s ease-out';
- box.style.MozTransition = 'opacity 0.1s ease-out';
- box.style.MsTransition = 'opacity 0.1s ease-out';
- box.style.OTransition = 'opacity 0.1s ease-out';
+ // TODO: This is very old code and can probably be removed
+ //box.style.WebkitTransition = 'opacity 0.1s ease-out';
+ //box.style.MozTransition = 'opacity 0.1s ease-out';
+ //box.style.MsTransition = 'opacity 0.1s ease-out';
+ //box.style.OTransition = 'opacity 0.1s ease-out';
box.style.transition = 'opacity 0.1s ease-out';
box.className = CM.Disp.colorBorderPre + color;
box.style.padding = '2px';
@@ -1389,441 +1414,310 @@ CM.Disp.CreateTooltipWarn = function() {
CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnLuckyFrenzy', CM.Disp.colorYellow, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Lucky!" (Frenzy)', 'CMDispTooltipWarnLuckyFrenzyText'));
CM.Disp.TooltipWarn.lastChild.style.marginBottom = '4px';
CM.Disp.TooltipWarn.appendChild(create('CMDispTooltipWarnConjure', CM.Disp.colorPurple, 'Warning: ', 'Purchase of this item will put you under the number of Cookies required for "Conjure Baked Goods"', 'CMDispTooltipWarnConjureText'));
-
-
- l('tooltipAnchor').appendChild(CM.Disp.TooltipWarn);
+
+ return CM.Disp.TooltipWarn;
}
-CM.Disp.ToggleToolWarnPos = function() {
- if (CM.Config.ToolWarnPos == 0) {
- CM.Disp.TooltipWarn.style.top = 'auto';
- CM.Disp.TooltipWarn.style.margin = '4px -4px';
- CM.Disp.TooltipWarn.style.padding = '3px 4px';
- }
- else {
- CM.Disp.TooltipWarn.style.right = 'auto';
- CM.Disp.TooltipWarn.style.margin = '4px';
- CM.Disp.TooltipWarn.style.padding = '4px 3px';
- }
-}
-
-CM.Disp.AddTooltipBuild = function() {
- CM.Disp.TooltipBuildBack = [];
- for (var i in Game.Objects) {
- var me = Game.Objects[i];
- if (l('product' + me.id).onmouseover != null) {
- CM.Disp.TooltipBuildBack[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 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()
+ */
+CM.Disp.UpdateTooltip = function() {
+ CM.Sim.CopyData();
+ if (l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea')) {
+ l('CMTooltipArea').innerHTML = '';
+ tooltipBox = CM.Disp.TooltipCreateTooltipBox();
+ l('CMTooltipArea').appendChild(tooltipBox);
+
+ if (CM.Disp.tooltipType == 'b') {
+ CM.Disp.UpdateTooltipBuilding();
}
- }
-}
-
-CM.Disp.AddTooltipUpgrade = function() {
- CM.Disp.TooltipUpgradeBack = [];
- for (var i in Game.UpgradesInStore) {
- var me = Game.UpgradesInStore[i];
- if (l('upgrade' + i).onmouseover != null) {
- CM.Disp.TooltipUpgradeBack[i] = l('upgrade' + i).onmouseover;
- eval('l(\'upgrade\' + i).onmouseover = function() {if (!Game.mouseDown) {Game.setOnCrate(this); Game.tooltip.dynamic = 1; Game.tooltip.draw(this, function() {return CM.Disp.Tooltip(\'u\', \'' + i + '\');}, \'store\'); Game.tooltip.wobble();}}');
+ else if (CM.Disp.tooltipType == 'u') {
+ CM.Disp.UpdateTooltipUpgrade();
}
+ else if (CM.Disp.tooltipType === 's') {
+ CM.Disp.UpdateTooltipSugarLump();
+ }
+ else if (CM.Disp.tooltipType === 'g') {
+ CM.Disp.UpdateTooltipGrimoire();
+ }
+ CM.Disp.UpdateTooltipWarnings();
}
}
-CM.Disp.AddTooltipGrimoire = function() {
- if (Game.Objects['Wizard tower'].minigameLoaded) {
- CM.Disp.TooltipGrimoireBack = [];
- for (var i in Game.Objects['Wizard tower'].minigame.spellsById) {
- if (l('grimoireSpell' + i).onmouseover != null) {
- CM.Disp.TooltipGrimoireBack[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 adds extra info to the Building tooltips
+ * It is called when Building tooltips are created or refreshed by CM.Disp.UpdateTooltip()
+ */
+CM.Disp.UpdateTooltipBuilding = function() {
+ if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
+ tooltipBox = l('CMTooltipBorder');
+ CM.Disp.TooltipCreateCalculationSection(tooltipBox);
+
+ var target = '';
+ // TODO: Change the Cache code and variables to use Objects1, Objectes10, Objects100
+ // That would depreciate this target setting code
+ if (Game.buyMode == 1 && Game.buyBulk == 10) target = 'Objects10'
+ else if (Game.buyMode == 1 && Game.buyBulk == 100) target = 'Objects100';
+ else target = 'Objects';
+
+ var price = Game.Objects[CM.Disp.tooltipName].bulkPrice
+ CM.Disp.TooltipBonusIncome = CM.Cache[target][CM.Disp.tooltipName].bonus;
+
+
+ if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
+ l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2);
+ var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000);
+ if (isFinite(increase) && increase != 0) {
+ l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
}
+ l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
+ l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
+ l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
+ var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ l('CMTooltipTime').textContent = timeColor.text;
+ l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
+ }
+
+ // Add "production left till next achievement"-bar
+ for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) {
+ if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) {
+ var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i]
+ break
+ }
+ }
+ if (typeof nextProductionAchiev != "undefined") {
+ l('CMTooltipTime').style.marginBottom = '4px';
+ l('CMTooltipProductionHeader').style.display = "";
+ l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName;
+ l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15);
+ l('CMTooltipProduction').style.color = "white";
+ } else {
+ l('CMTooltipProductionHeader').style.display = "none";
+ l('CMTooltipTime').style.marginBottom = '0px';
}
}
}
/**
- * This function improves Sugar Lump tooltip by adding extra infromation.
- * @constructor
+ * This function adds extra info to the Upgrade tooltips
+ * It is called when Upgrade tooltips are created or refreshed by CM.Disp.UpdateTooltip()
*/
-CM.Disp.AddTooltipLump = function() {
- if (Game.canLumps()) {
- CM.Disp.TooltipLumpBack = 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();}');
- }
-};
+CM.Disp.UpdateTooltipUpgrade = function() {
+ tooltipBox = l('CMTooltipBorder');
+ CM.Disp.TooltipCreateCalculationSection(tooltipBox);
-CM.Disp.Tooltip = function(type, name) {
- if (type == 'b') {
- l('tooltip').innerHTML = Game.Objects[name].tooltip();
- if (CM.Config.TooltipAmor == 1) {
- var buildPrice = CM.Sim.BuildingGetPrice(Game.Objects[name], Game.Objects[name].basePrice, 0, Game.Objects[name].free, Game.Objects[name].amount);
- var amortizeAmount = buildPrice - Game.Objects[name].totalCookies;
- if (amortizeAmount > 0) {
- l('tooltip').innerHTML = l('tooltip').innerHTML
- .split('so far')
- .join('so far
• ' + Beautify(amortizeAmount) + ' ' + (Math.floor(amortizeAmount) == 1 ? 'cookie' : 'cookies') + ' left to amortize (' + CM.Disp.GetTimeColor(buildPrice, Game.Objects[name].totalCookies, (Game.Objects[name].storedTotalCps * Game.globalCpsMult)).text + ')');
- }
- }
- if (Game.buyMode == 1) {
- var target = '';
- var change = false;
- if (Game.buyBulk == 10) {
- target = 'Objects10';
- change = true;
- }
- else if (Game.buyBulk == 100) {
- target = 'Objects100';
- change = true;
- }
- if (change) {
- l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].getPrice())).join(Beautify(CM.Cache[target][name].price));
- }
- }
- else if (Game.buyMode == -1) {
- /*
- * Fix sell price displayed in the object tooltip.
- *
- * The buildings sell price displayed by the game itself (without any mod) is incorrect.
- * The following line of code fixes this issue, and can be safely removed when the game gets fixed.
- *
- * This issue is extensively detailed here: https://github.com/Aktanusa/CookieMonster/issues/359#issuecomment-735658262
- */
- l('tooltip').innerHTML = l('tooltip').innerHTML.split(Beautify(Game.Objects[name].bulkPrice)).join(Beautify(CM.Sim.BuildingSell(Game.Objects[name], Game.Objects[name].basePrice, Game.Objects[name].amount, Game.Objects[name].free, Game.buyBulk, 1)));
+ CM.Disp.TooltipBonusIncome = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
+ price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
+
+ if (CM.Config.TooltipBuildUp == 1) {
+ l('CMTooltipIncome').textContent = Beautify(CM.Disp.TooltipBonusIncome, 2);
+ var increase = Math.round(CM.Disp.TooltipBonusIncome / Game.cookiesPs * 10000);
+ if (isFinite(increase) && increase != 0) {
+ l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
}
+ l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
+ l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
+ l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
+ var timeColor = CM.Disp.GetTimeColor((price - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS());
+ l('CMTooltipTime').textContent = timeColor.text;
+ l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
}
- else if (type == 'u') {
- if (!Game.UpgradesInStore[name]) return '';
- l('tooltip').innerHTML = Game.crateTooltip(Game.UpgradesInStore[name], 'store');
- }
- else if (type === 's') {
- // Sugar Lump
- l('tooltip').innerHTML = Game.lumpTooltip();
- }
- else { // Grimoire
- l('tooltip').innerHTML = Game.Objects['Wizard tower'].minigame.spellTooltip(name)();
- }
-
- var area = document.createElement('div');
- area.id = 'CMTooltipArea';
- l('tooltip').appendChild(area);
-
- if (CM.Config.TooltipBuildUp == 1 && (type == 'u' || (type == 'b' && Game.buyMode == 1))) {
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var tooltip = document.createElement('div');
- tooltip.style.border = '1px solid';
- tooltip.style.padding = '4px';
- tooltip.style.margin = '0px -4px';
- tooltip.id = 'CMTooltipBorder';
-
- var header = function(text) {
- var div = document.createElement('div');
- div.style.fontWeight = 'bold';
- div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- div.textContent = text;
- return div;
- }
-
- tooltip.appendChild(header('Bonus Income'));
- var income = document.createElement('div');
- income.style.marginBottom = '4px';
- income.style.color = 'white';
- income.id = 'CMTooltipIncome';
- tooltip.appendChild(income);
- tooltip.appendChild(header('Payback Period'));
- var pp = document.createElement('div');
- pp.style.marginBottom = '4px';
- pp.id = 'CMTooltipPP';
- tooltip.appendChild(pp);
- tooltip.appendChild(header('Time Left'));
- var time = document.createElement('div');
- time.id = 'CMTooltipTime';
- tooltip.appendChild(time);
- if (type == 'b') {
- tooltip.appendChild(header('Production left till next achievement'));
- tooltip.lastChild.id = 'CMTooltipProductionHeader';
- var production = document.createElement('div');
- production.id = 'CMTooltipProduction';
- tooltip.appendChild(production);
- }
-
- area.appendChild(tooltip);
- }
-
- CM.Disp.tooltipType = type;
- CM.Disp.tooltipName = name;
-
- CM.Disp.UpdateTooltip();
-
- return l('tooltip').innerHTML;
}
-CM.Disp.UpdateTooltip = function() {
- CM.Sim.CopyData();
- if (l('tooltipAnchor').style.display != 'none') {
+/**
+ * This function adds extra info to the Sugar Lump tooltip
+ * It is called when the Sugar Lump tooltip is created or refreshed by CM.Disp.UpdateTooltip()
+ * It adds to the additional information to l('CMTooltipArea')
+ */
+CM.Disp.UpdateTooltipSugarLump = function() {
+ if (CM.Config.TooltipLump === 1) {
+ tooltipBox = l('CMTooltipBorder');
- if (l('CMTooltipArea') != null) {
- if (CM.Disp.tooltipType == 'b' || CM.Disp.tooltipType == 'u') {
- // Error checking
- if (CM.Disp.tooltipType == 'u' && (typeof Game.UpgradesInStore[CM.Disp.tooltipName] === 'undefined' || typeof CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name] === 'undefined')) {
- return;
- }
- var price;
- var bonus;
- if (CM.Disp.tooltipType == 'b') {
- var target = '';
- if (Game.buyMode == 1 && Game.buyBulk == 10) {
- target = 'Objects10';
- price = CM.Cache[target][CM.Disp.tooltipName].price;
- }
- else if (Game.buyMode == 1 && Game.buyBulk == 100) {
- target = 'Objects100';
- price = CM.Cache[target][CM.Disp.tooltipName].price;
- }
- else {
- target = 'Objects';
- price = Game.Objects[CM.Disp.tooltipName].getPrice();
- }
- bonus = CM.Cache[target][CM.Disp.tooltipName].bonus;
- if (CM.Config.TooltipBuildUp == 1 && Game.buyMode == 1) {
- l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
- l('CMTooltipPP').textContent = Beautify(CM.Cache[target][CM.Disp.tooltipName].pp, 2);
- l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache[target][CM.Disp.tooltipName].color;
- }
- if (CM.Config.TooltipBuildUp) {
- for (var i in Game.Objects[CM.Disp.tooltipName].productionAchievs) {
- if (!CM.Sim.HasAchiev(Game.Objects[CM.Disp.tooltipName].productionAchievs[i].achiev.name)) {
- var nextProductionAchiev = Game.Objects[CM.Disp.tooltipName].productionAchievs[i]
- break
- }
- }
- if (typeof nextProductionAchiev != "undefined") {
- l('CMTooltipTime').style.marginBottom = '4px';
- l('CMTooltipProductionHeader').style.display = "";
- l('CMTooltipProduction').className = "ProdAchievement" + CM.Disp.tooltipName;
- l('CMTooltipProduction').textContent = Beautify(nextProductionAchiev.pow - CM.Sim.Objects[CM.Disp.tooltipName].totalCookies, 15);
- l('CMTooltipProduction').style.color = "white";
- } else {
- l('CMTooltipProductionHeader').style.display = "none";
- l('CMTooltipTime').style.marginBottom = '0px';
- }
- }
- }
- else { // Upgrades
- bonus = CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].bonus;
- price = Game.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].getPrice();
- if (CM.Config.TooltipBuildUp == 1) {
- l('CMTooltipBorder').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
- l('CMTooltipPP').textContent = Beautify(CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].pp, 2);
- l('CMTooltipPP').className = CM.Disp.colorTextPre + CM.Cache.Upgrades[Game.UpgradesInStore[CM.Disp.tooltipName].name].color;
- }
- }
- if (CM.Config.TooltipBuildUp == 1 && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- l('CMTooltipIncome').textContent = Beautify(bonus, 2);
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Current Sugar Lump'));
- var increase = Math.round(bonus / Game.cookiesPs * 10000);
- if (isFinite(increase) && increase != 0) {
- l('CMTooltipIncome').textContent += ' (' + (increase / 100) + '% of income)';
- }
+ var lumpType = document.createElement('div');
+ lumpType.id = 'CMTooltipTime';
+ tooltipBox.appendChild(lumpType);
+ var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType);
+ lumpType.textContent = lumpColor.text;
+ lumpType.className = CM.Disp.colorTextPre + lumpColor.color;
+ }
+}
- var timeColor = CM.Disp.GetTimeColor(price, (Game.cookies + CM.Disp.GetWrinkConfigBank()), CM.Disp.GetCPS());
- l('CMTooltipTime').textContent = timeColor.text;
- l('CMTooltipTime').className = CM.Disp.colorTextPre + timeColor.color;
- }
+/**
+ * This function adds extra info to the Grimoire tooltips
+ * It is called when Grimoire tooltips are created or refreshed by CM.Disp.UpdateTooltip()
+ * It adds to the additional information to l('CMTooltipArea')
+ */
+CM.Disp.UpdateTooltipGrimoire = function() {
+ var minigame = Game.Objects['Wizard tower'].minigame;
+ var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]);
- if (CM.Config.ToolWarnPos == 0) {
- CM.Disp.TooltipWarn.style.right = '0px';
- }
- else {
- CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px';
- }
- CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px';
+ if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) {
+ tooltipBox = l('CMTooltipBorder');
- if (CM.Config.ToolWarnLucky == 1) {
- CM.Disp.TooltipWarn.style.display = 'block';
- var limitLucky = CM.Cache.Lucky;
- if (CM.Config.ToolWarnBon == 1) {
- var bonusNoFren = bonus;
- bonusNoFren /= CM.Sim.getCPSBuffMult();
- limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
- }
- var limitLuckyFrenzy = limitLucky * 7;
- var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
- if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- if (amount < limitLucky) {
- l('CMDispTooltipWarnLucky').style.display = '';
- l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
- l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
- }
- else if (amount < limitLuckyFrenzy) {
- l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
- l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
- l('CMDispTooltipWarnLucky').style.display = 'none';
- }
- } else {
- l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- }
+ // Time left till enough magic for spell
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Time Left'));
+ var time = document.createElement('div');
+ time.id = 'CMTooltipTime';
+ tooltipBox.appendChild(time);
+ var timeColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost));
+ time.textContent = timeColor.text;
+ time.className = CM.Disp.colorTextPre + timeColor.color;
+
+ // Time left untill magic spent is recovered
+ if (spellCost <= minigame.magic) {
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Recover Time'));
+ var recover = document.createElement('div');
+ recover.id = 'CMTooltipRecover';
+ tooltipBox.appendChild(recover);
+ var recoverColor = CM.Disp.GetTimeColor(CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic));
+ recover.textContent = recoverColor.text;
+ recover.className = CM.Disp.colorTextPre + recoverColor.color;
+ }
+
+ // Extra information on cookies gained when spell is Conjure Baked Goods (Name == 0)
+ if (CM.Disp.tooltipName == 0) {
+ tooltipBox.appendChild(CM.Disp.TooltipCreateHeader('Cookies to be gained/lost'));
+ var conjure = document.createElement('div');
+ conjure.id = 'CMTooltipConjure';
+ tooltipBox.appendChild(conjure);
+ var reward = document.createElement('span');
+ reward.style.color = "#33FF00"
+ reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2)
+ conjure.appendChild(reward)
+ var seperator = document.createElement('span');
+ seperator.textContent = ' / '
+ conjure.appendChild(seperator)
+ var loss = document.createElement('span');
+ loss.style.color = "red"
+ loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2);
+ conjure.appendChild(loss)
+ }
+
+ l('CMTooltipArea').appendChild(tooltipBox);
+ }
+}
+
+/**
+ * This function updates the warnings section of the building and upgrade tooltips
+ * It is called by CM.Disp.UpdateTooltip()
+ */
+CM.Disp.UpdateTooltipWarnings = function() {
+ if (CM.Disp.tooltipType == "b" || CM.Disp.tooltipType == "u") {
+ if (document.getElementById("tooltipWarn") == null) {
+ warningTooltip = CM.Disp.TooltipCreateWarningSection();
+ l('tooltipAnchor').appendChild(warningTooltip);
+ }
+
+ if (CM.Config.ToolWarnPos == 0) CM.Disp.TooltipWarn.style.right = '0px';
+ else CM.Disp.TooltipWarn.style.top = (l('tooltip').offsetHeight) + 'px';
+
+ CM.Disp.TooltipWarn.style.width = (l('tooltip').offsetWidth - 6) + 'px';
+
+ if (CM.Config.ToolWarnLucky == 1) {
+ var limitLucky = CM.Cache.Lucky;
+ if (CM.Config.ToolWarnBon == 1) {
+ var bonusNoFren = CM.Disp.TooltipBonusIncome;
+ bonusNoFren /= CM.Sim.getCPSBuffMult();
+ limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
+ }
+ var limitLuckyFrenzy = limitLucky * 7;
+ var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
+ if ((amount < limitLucky || amount < limitLuckyFrenzy) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
+ if (amount < limitLucky) {
+ l('CMDispTooltipWarnLucky').style.display = '';
+ l('CMDispTooltipWarnLuckyText').textContent = Beautify(limitLucky - amount) + ' (' + CM.Disp.FormatTime((limitLucky - amount) / CM.Disp.GetCPS()) + ')';
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
+ l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
}
- else {
+ else if (amount < limitLuckyFrenzy) {
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = '';
+ l('CMDispTooltipWarnLuckyFrenzyText').textContent = Beautify(limitLuckyFrenzy - amount) + ' (' + CM.Disp.FormatTime((limitLuckyFrenzy - amount) / CM.Disp.GetCPS()) + ')';
l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
}
-
- if (CM.Config.ToolWarnConjure == 1) {
- CM.Disp.TooltipWarn.style.display = 'block';
- var limitLucky = CM.Cache.Lucky;
- if (CM.Config.ToolWarnBon == 1) {
- var bonusNoFren = bonus;
- bonusNoFren /= CM.Sim.getCPSBuffMult();
- limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
- }
- var limitConjure = limitLucky * 2;
- var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
- if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
- l('CMDispTooltipWarnConjure').style.display = '';
- l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')';
- } else {
- l('CMDispTooltipWarnConjure').style.display = 'none';
- }
- }
- else {
- l('CMDispTooltipWarnConjure').style.display = 'none';
- }
- }
- else if (CM.Disp.tooltipType === 's') {
- // Adding information about Sugar Lumps.
-
- CM.Disp.TooltipWarn.style.display = 'none';
- l('CMDispTooltipWarnLucky').style.display = 'none';
- l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- l('CMDispTooltipWarnConjure').style.display = 'none';
-
- if (CM.Config.TooltipLump === 1) {
- l('CMTooltipArea').innerHTML = '';
-
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var lumpTooltip = document.createElement('div');
- lumpTooltip.style.border = '1px solid';
- lumpTooltip.style.padding = '4px';
- lumpTooltip.style.margin = '0px -4px';
- lumpTooltip.id = 'CMTooltipBorder';
- lumpTooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
-
- var lumpHeader = document.createElement('div');
- lumpHeader.style.fontWeight = 'bold';
- lumpHeader.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- lumpHeader.textContent = 'Current Sugar Lump';
-
- lumpTooltip.appendChild(lumpHeader);
- var lumpType = document.createElement('div');
- lumpType.id = 'CMTooltipTime';
- lumpTooltip.appendChild(lumpType);
- var lumpColor = CM.Disp.GetLumpColor(Game.lumpCurrentType);
- lumpType.textContent = lumpColor.text;
- lumpType.className = CM.Disp.colorTextPre + lumpColor.color;
-
- l('CMTooltipArea').appendChild(lumpTooltip);
- }
- }
- else if (CM.Disp.tooltipType === 'g') {
- // Grimoire
- CM.Disp.TooltipWarn.style.display = 'none';
+ } else {
l('CMDispTooltipWarnLucky').style.display = 'none';
l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
- l('CMDispTooltipWarnConjure').style.display = 'none';
-
- var minigame = Game.Objects['Wizard tower'].minigame;
- var spellCost = minigame.getSpellCost(minigame.spellsById[CM.Disp.tooltipName]);
-
- if (CM.Config.TooltipGrim == 1 && spellCost <= minigame.magicM) {
- l('CMTooltipArea').innerHTML = '';
-
- l('tooltip').firstChild.style.paddingBottom = '4px';
- var tooltip = document.createElement('div');
- tooltip.style.border = '1px solid';
- tooltip.style.padding = '4px';
- tooltip.style.margin = '0px -4px';
- tooltip.id = 'CMTooltipBorder';
- tooltip.className = CM.Disp.colorTextPre + CM.Disp.colorGray;
-
- var header = function(text) {
- var div = document.createElement('div');
- div.style.fontWeight = 'bold';
- div.className = CM.Disp.colorTextPre + CM.Disp.colorBlue;
- div.textContent = text;
- return div;
- }
-
- tooltip.appendChild(header('Time Left'));
- var time = document.createElement('div');
- time.id = 'CMTooltipTime';
- tooltip.appendChild(time);
- var timeColor = CM.Disp.GetTimeColor(spellCost, minigame.magic, undefined, CM.Disp.CalculateGrimoireRefillTime(minigame.magic, minigame.magicM, spellCost));
- time.textContent = timeColor.text;
- time.className = CM.Disp.colorTextPre + timeColor.color;
-
- if (spellCost <= minigame.magic) {
- tooltip.appendChild(header('Recover Time'));
- var recover = document.createElement('div');
- recover.id = 'CMTooltipRecover';
- tooltip.appendChild(recover);
- var recoverColor = CM.Disp.GetTimeColor(minigame.magic, Math.max(0, minigame.magic - spellCost), undefined, CM.Disp.CalculateGrimoireRefillTime(Math.max(0, minigame.magic - spellCost), minigame.magicM, minigame.magic));
- recover.textContent = recoverColor.text;
- recover.className = CM.Disp.colorTextPre + recoverColor.color;
- }
-
- // Extra information when spell is Conjure Baked Goods (Name == 0)
- if (CM.Disp.tooltipName == 0) {
- tooltip.appendChild(header('Cookies to be gained/lost'));
- var conjure = document.createElement('div');
- conjure.id = 'CMTooltipConjure';
- tooltip.appendChild(conjure);
- var reward = document.createElement('span');
- reward.style.color = "#33FF00"
- reward.textContent = Beautify(Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30), 2)
- conjure.appendChild(reward)
- var seperator = document.createElement('span');
- seperator.textContent = ' / '
- conjure.appendChild(seperator)
- var loss = document.createElement('span');
- loss.style.color = "red"
- loss.textContent = Beautify((CM.Cache.NoGoldSwitchCookiesPS * 60 * 15), 2);
- conjure.appendChild(loss)
- }
-
- l('CMTooltipArea').appendChild(tooltip);
- }
}
}
else {
- CM.Disp.TooltipWarn.style.display = 'none';
+ l('CMDispTooltipWarnLucky').style.display = 'none';
+ l('CMDispTooltipWarnLuckyFrenzy').style.display = 'none';
+ }
+
+ if (CM.Config.ToolWarnConjure == 1) {
+ var limitLucky = CM.Cache.Lucky;
+ if (CM.Config.ToolWarnBon == 1) {
+ var bonusNoFren = CM.Disp.TooltipBonusIncome;
+ bonusNoFren /= CM.Sim.getCPSBuffMult();
+ limitLucky += ((bonusNoFren * 60 * 15) / 0.15);
+ }
+ var limitConjure = limitLucky * 2;
+ var amount = (Game.cookies + CM.Disp.GetWrinkConfigBank()) - price;
+ if ((amount < limitConjure) && (CM.Disp.tooltipType != 'b' || Game.buyMode == 1)) {
+ l('CMDispTooltipWarnConjure').style.display = '';
+ l('CMDispTooltipWarnConjureText').textContent = Beautify(limitConjure - amount) + ' (' + CM.Disp.FormatTime((limitConjure - amount) / CM.Disp.GetCPS()) + ')';
+ } else {
+ l('CMDispTooltipWarnConjure').style.display = 'none';
+ }
+ }
+ else {
+ l('CMDispTooltipWarnConjure').style.display = 'none';
+ }
+ }
+ else {
+ if (l('CMDispTooltipWarningParent') != null) {
+ l('CMDispTooltipWarningParent').remove();
}
}
}
-CM.Disp.DrawTooltipWarn = function() {
- if (CM.Config.ToolWarnLucky == 1) {
- l('CMDispTooltipWarnLucky').style.opacity = '0';
- l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '0';
+/**
+ * This function updates the location of the tooltip
+ * It is called by Game.tooltip.update() because of CM.ReplaceNative()
+ */
+CM.Disp.UpdateTooltipLocation = function() {
+ if (Game.tooltip.origin == 'store') {
+ var warnOffset = 0;
+ if (CM.Config.ToolWarnLucky == 1 && CM.Config.ToolWarnPos == 1 && typeof CM.Disp.TooltipWarn != "undefined") {
+ warnOffset = CM.Disp.TooltipWarn.clientHeight - 4;
+ }
+ Game.tooltip.tta.style.top = Math.min(parseInt(Game.tooltip.tta.style.top), (l('game').clientHeight + l('topBar').clientHeight) - Game.tooltip.tt.clientHeight - warnOffset - 46) + 'px';
}
- if (CM.Config.ToolWarnConjure == 1) {
- l('CMDispTooltipWarnConjure').style.opacity = '0';
- }
-}
-
-CM.Disp.UpdateTooltipWarn = function() {
- if (CM.Config.ToolWarnLucky == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) {
- l('CMDispTooltipWarnLucky').style.opacity = '1';
- l('CMDispTooltipWarnLuckyFrenzy').style.opacity = '1';
- }
- if (CM.Config.ToolWarnConjure == 1 && l('tooltipAnchor').style.display != 'none' && l('CMTooltipArea') != null) {
- l('CMDispTooltipWarnConjure').style.opacity = '1';
+ // Kept for future possible use if the code changes again
+ /*else if (!Game.onCrate && !Game.OnAscend && CM.Config.TimerBar == 1 && CM.Config.TimerBarPos == 0) {
+ Game.tooltip.tta.style.top = (parseInt(Game.tooltip.tta.style.top) + parseInt(CM.Disp.TimerBar.style.height)) + 'px';
+ }*/
+}
+
+/**
+ * This function toggles the position of the warnings created by CM.Disp.TooltipCreateWarningSection()
+ * It is called by a change in CM.Config.ToolWarnPos
+ */
+CM.Disp.ToggleToolWarnPos = function() {
+ if (typeof CM.Disp.TooltipWarn != "undefined") {
+ if (CM.Config.ToolWarnPos == 0) {
+ CM.Disp.TooltipWarn.style.top = 'auto';
+ CM.Disp.TooltipWarn.style.margin = '4px -4px';
+ CM.Disp.TooltipWarn.style.padding = '3px 4px';
+ }
+ else {
+ CM.Disp.TooltipWarn.style.right = 'auto';
+ CM.Disp.TooltipWarn.style.margin = '4px';
+ CM.Disp.TooltipWarn.style.padding = '4px 3px';
+ }
}
}
+/**
+ * This function checks and create a tooltip for the wrinklers
+ * It is called by CM.Loop()
+ * TODO: Change this code to be the same as other tooltips. (i.d., create tooltip with type "w")
+ */
CM.Disp.CheckWrinklerTooltip = function() {
- if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) {
+ if (CM.Config.ToolWrink == 1 && CM.Disp.TooltipWrinklerArea == 1) { // Latter is set by CM.Main.AddWrinklerAreaDetect
var showingTooltip = false;
for (var i in Game.wrinklers) {
var me = Game.wrinklers[i];
@@ -1855,6 +1749,11 @@ 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()
+ * TODO: Change this code to be the same as other tooltips. Fit this into CM.Disp.UpdateTooltip()
+ */
CM.Disp.UpdateWrinklerTooltip = function() {
if (CM.Config.ToolWrink == 1 && l('CMTooltipWrinkler') != null) {
var sucked = Game.wrinklers[CM.Disp.TooltipWrinkler].sucked;
@@ -1877,6 +1776,10 @@ CM.Disp.UpdateWrinklerTooltip = function() {
* Section: General functions related to the Options/Stats pages
* TODO: Annotate functions */
+/**
+ * This function adds the calll the functions to add extra info to the stats and options pages
+ * It is called by Game.UpdateMenu()
+ */
CM.Disp.AddMenu = function() {
var title = function() {
var div = document.createElement('div');
@@ -1892,52 +1795,96 @@ CM.Disp.AddMenu = function() {
if (CM.Config.Stats) {
CM.Disp.AddMenuStats(title);
}
-
- if (CM.Config.MissingUpgrades) {
- CM.Disp.AddMissingUpgrades();
- }
}
}
+/**
+ * This function refreshes the stats page, CM.Config.UpStats determines the rate at which that happens
+ * It is called by CM.Loop()
+ */
CM.Disp.RefreshMenu = function() {
if (CM.Config.UpStats && Game.onMenu == 'stats' && (Game.drawT - 1) % (Game.fps * 5) != 0 && (Game.drawT - 1) % Game.fps == 0) Game.UpdateMenu();
}
/********
- * Section: Functions related to the Options page
- * TODO: Annotate functions */
-
-CM.Disp.AddMenuPref = function(title) {
- var header = function(text, config) {
- var div = document.createElement('div');
- div.className = 'listing';
- div.style.padding = '5px 16px';
- div.style.opacity = '0.7';
- div.style.fontSize = '17px';
- div.style.fontFamily = '\"Kavoon\", Georgia, serif';
- div.appendChild(document.createTextNode(text + ' '));
- var span = document.createElement('span');
- span.style.cursor = 'pointer';
- span.style.display = 'inline-block';
- span.style.height = '14px';
- span.style.width = '14px';
- span.style.borderRadius = '7px';
- span.style.textAlign = 'center';
- span.style.backgroundColor = '#C0C0C0';
- span.style.color = 'black';
- span.style.fontSize = '13px';
- span.style.verticalAlign = 'middle';
- span.textContent = CM.Config.MenuPref[config] ? '-' : '+';
- span.onclick = function() {CM.ToggleMenuConfig(config); Game.UpdateMenu();};
- div.appendChild(span);
- return div;
- }
+ * Section: Functions related to the Options/Preferences page
+/**
+ * This function adds the options/settings of CookieMonster to the options page
+ * It is called by CM.Disp.AddMenu
+ * @param {function} title A function that returns the title of CookieMonster pre-styled
+ */
+CM.Disp.AddMenuPref = function(title) {
var frag = document.createDocumentFragment();
-
frag.appendChild(title());
- var listing = function(config) {
+ for (var group in CM.ConfigGroups) {
+ groupObject = CM.Disp.CreatePrefHeader(group, CM.ConfigGroups[group]) // (group, display-name of group)
+ frag.appendChild(groupObject)
+ if (CM.Config.OptionsPref[group]) { // 0 is show, 1 is collapsed
+ for (var option in CM.ConfigData) {
+ if (CM.ConfigData[option].group == group) frag.appendChild(CM.Disp.CreatePrefOption(option))
+ }
+ }
+ }
+
+ var resDef = document.createElement('div');
+ resDef.className = 'listing';
+ var resDefBut = document.createElement('a');
+ resDefBut.className = 'option';
+ resDefBut.onclick = function() {CM.RestoreDefault();};
+ resDefBut.textContent = 'Restore Default';
+ resDef.appendChild(resDefBut);
+ frag.appendChild(resDef);
+
+ l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]);
+
+ // TODO: What does this do? @DanielNoord
+ CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick;
+ eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();'));
+ //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();};
+}
+
+/**
+ * This function creates a header-object for the options page
+ * It is called by CM.Disp.AddMenuPref()
+ * @param {string} config The name of the Config-group
+ * @param {string} text The to-be displayed name of the header
+ * @returns {object} div The header object
+ */
+CM.Disp.CreatePrefHeader = function(config, text) {
+ var div = document.createElement('div');
+ div.className = 'listing';
+ div.style.padding = '5px 16px';
+ div.style.opacity = '0.7';
+ div.style.fontSize = '17px';
+ div.style.fontFamily = '\"Kavoon\", Georgia, serif';
+ div.appendChild(document.createTextNode(text + ' '));
+ var span = document.createElement('span'); // Creates the +/- button
+ span.style.cursor = 'pointer';
+ span.style.display = 'inline-block';
+ span.style.height = '14px';
+ span.style.width = '14px';
+ span.style.borderRadius = '7px';
+ span.style.textAlign = 'center';
+ span.style.backgroundColor = '#C0C0C0';
+ span.style.color = 'black';
+ span.style.fontSize = '13px';
+ span.style.verticalAlign = 'middle';
+ span.textContent = CM.Config.OptionsPref[config] ? '-' : '+';
+ span.onclick = function() {CM.ToggleOptionsConfig(config); Game.UpdateMenu();};
+ div.appendChild(span);
+ return div;
+}
+
+/**
+ * This function creates an option-object for the options page
+ * It is called by CM.Disp.AddMenuPref()
+ * @param {string} config The name of the option
+ * @returns {object} div The option object
+ */
+CM.Disp.CreatePrefOption = function(config) {
+ if (CM.ConfigData[config].type == "bool") {
var div = document.createElement('div');
div.className = 'listing';
var a = document.createElement('a');
@@ -1956,8 +1903,7 @@ CM.Disp.AddMenuPref = function(title) {
div.appendChild(label);
return div;
}
-
- var vol = function(config) {
+ else if (CM.ConfigData[config].type == "vol") {
var volConfig = config;
var volume = document.createElement('div');
volume.className = 'listing';
@@ -1980,8 +1926,7 @@ CM.Disp.AddMenuPref = function(title) {
volume.appendChild(volLabel);
return volume;
}
-
- var url = function(config) {
+ else if (CM.ConfigData[config].type == "url") {
var div = document.createElement('div');
div.className = 'listing';
var span = document.createElement('span');
@@ -2012,18 +1957,7 @@ CM.Disp.AddMenuPref = function(title) {
div.appendChild(label);
return div;
}
-
- frag.appendChild(header('Bars/Colors', 'BarsColors'));
- if (CM.Config.MenuPref.BarsColors) {
- frag.appendChild(listing('BotBar'));
- frag.appendChild(listing('TimerBar'));
- frag.appendChild(listing('TimerBarPos'));
- frag.appendChild(listing('SortBuildings'));
- frag.appendChild(listing('SortUpgrades'));
- frag.appendChild(listing('BuildColor'));
- frag.appendChild(listing('BulkBuildColor'));
- frag.appendChild(listing('ColorPPBulkMode'));
- frag.appendChild(listing('UpBarColor'));
+ else if (CM.ConfigData[config].type == "color") {
for (var i = 0; i < CM.Disp.colors.length; i++) {
var div = document.createElement('div');
div.className = 'listing';
@@ -2038,101 +1972,9 @@ CM.Disp.AddMenuPref = function(title) {
var label = document.createElement('label');
label.textContent = CM.ConfigData.Colors.desc[CM.Disp.colors[i]];
div.appendChild(label);
- frag.appendChild(div);
+ return div;
}
- frag.appendChild(listing('UpgradeBarFixedPos'));
}
-
- frag.appendChild(header('Calculation', 'Calculation'));
- if (CM.Config.MenuPref.Calculation) {
- frag.appendChild(listing('CalcWrink'));
- frag.appendChild(listing('CPSMode'));
- frag.appendChild(listing('AvgCPSHist'));
- frag.appendChild(listing('AvgClicksHist'));
- frag.appendChild(listing('ToolWarnBon'));
- }
-
- frag.appendChild(header('Notification', 'Notification'));
- if (CM.Config.MenuPref.Notification) {
- frag.appendChild(listing('GCNotification'));
- frag.appendChild(listing('GCFlash'));
- frag.appendChild(listing('GCSound'));
- frag.appendChild(vol('GCVolume'));
- frag.appendChild(url('GCSoundURL'));
- frag.appendChild(listing('GCTimer'));
- frag.appendChild(listing('Favicon'));
- frag.appendChild(listing('FortuneNotification'));
- frag.appendChild(listing('FortuneFlash'));
- frag.appendChild(listing('FortuneSound'));
- frag.appendChild(vol('FortuneVolume'));
- frag.appendChild(url('FortuneSoundURL'));
- frag.appendChild(listing('SeaNotification'));
- frag.appendChild(listing('SeaFlash'));
- frag.appendChild(listing('SeaSound'));
- frag.appendChild(vol('SeaVolume'));
- frag.appendChild(url('SeaSoundURL'));
- frag.appendChild(listing('GardFlash'));
- frag.appendChild(listing('GardSound'));
- frag.appendChild(vol('GardVolume'));
- frag.appendChild(url('GardSoundURL'));
- frag.appendChild(listing('MagicNotification'));
- frag.appendChild(listing('MagicFlash'));
- frag.appendChild(listing('MagicSound'));
- frag.appendChild(vol('MagicVolume'));
- frag.appendChild(url('MagicSoundURL'));
- frag.appendChild(listing('WrinklerNotification'));
- frag.appendChild(listing('WrinklerFlash'));
- frag.appendChild(listing('WrinklerSound'));
- frag.appendChild(vol('WrinklerVolume'));
- frag.appendChild(url('WrinklerSoundURL'));
- frag.appendChild(listing('WrinklerMaxNotification'));
- frag.appendChild(listing('WrinklerMaxFlash'));
- frag.appendChild(listing('WrinklerMaxSound'));
- frag.appendChild(vol('WrinklerMaxVolume'));
- frag.appendChild(url('WrinklerMaxSoundURL'));
- frag.appendChild(listing('Title'));
- }
-
- frag.appendChild(header('Tooltip', 'Tooltip'));
- if (CM.Config.MenuPref.Tooltip) {
- frag.appendChild(listing('TooltipBuildUp'));
- frag.appendChild(listing('TooltipAmor'));
- frag.appendChild(listing('ToolWarnLucky'));
- frag.appendChild(listing('ToolWarnConjure'));
- frag.appendChild(listing('ToolWarnPos'));
- frag.appendChild(listing('TooltipGrim'));
- frag.appendChild(listing('ToolWrink'));
- frag.appendChild(listing('TooltipLump'));
- }
-
- frag.appendChild(header('Statistics', 'Statistics'));
- if (CM.Config.MenuPref.Statistics) {
- frag.appendChild(listing('Stats'));
- frag.appendChild(listing('MissingUpgrades'));
- frag.appendChild(listing('UpStats'));
- frag.appendChild(listing('TimeFormat'));
- frag.appendChild(listing('SayTime'));
- frag.appendChild(listing('GrimoireBar'));
- }
-
- frag.appendChild(header('Other', 'Other'));
- if (CM.Config.MenuPref.Other) {
- frag.appendChild(listing('Scale'));
- var resDef = document.createElement('div');
- resDef.className = 'listing';
- var resDefBut = document.createElement('a');
- resDefBut.className = 'option';
- resDefBut.onclick = function() {CM.RestoreDefault();};
- resDefBut.textContent = 'Restore Default';
- resDef.appendChild(resDefBut);
- frag.appendChild(resDef);
- }
-
- l('menu').childNodes[2].insertBefore(frag, l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1]);
-
- CM.Disp.FormatButtonOnClickBak = l('formatButton').onclick;
- eval('l(\'formatButton\').onclick = ' + l('formatButton').onclick.toString().split('mp3\');').join('mp3\'); CM.Disp.RefreshScale();'));
- //l('formatButton').onclick = function() {Game.Toggle('format', 'formatButton', 'Short numbers OFF', 'Short numbers ON', '1'); PlaySound('snd/tick.mp3'); CM.Disp.RefreshScale();};
}
/********
@@ -2140,34 +1982,8 @@ CM.Disp.AddMenuPref = function(title) {
* TODO: Annotate functions */
CM.Disp.AddMenuStats = function(title) {
- var header = function(text, config) {
- var div = document.createElement('div');
- div.className = 'listing';
- div.style.padding = '5px 16px';
- div.style.opacity = '0.7';
- div.style.fontSize = '17px';
- div.style.fontFamily = '\"Kavoon\", Georgia, serif';
- div.appendChild(document.createTextNode(text + ' '));
- var span = document.createElement('span');
- span.style.cursor = 'pointer';
- span.style.display = 'inline-block';
- span.style.height = '14px';
- span.style.width = '14px';
- span.style.borderRadius = '7px';
- span.style.textAlign = 'center';
- span.style.backgroundColor = '#C0C0C0';
- span.style.color = 'black';
- span.style.fontSize = '13px';
- span.style.verticalAlign = 'middle';
- span.textContent = CM.Config.StatsPref[config] ? '-' : '+';
- span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();};
- div.appendChild(span);
- return div;
- }
-
var stats = document.createElement('div');
stats.className = 'subsection';
-
stats.appendChild(title());
var listing = function(name, text) {
@@ -2243,7 +2059,7 @@ CM.Disp.AddMenuStats = function(title) {
var goldCookTooltip = CM.Sim.auraMult('Dragon\'s Fortune') ? 'GoldCookDragonsFortuneTooltipPlaceholder' : 'GoldCookTooltipPlaceholder';
- stats.appendChild(header('Lucky Cookies', 'Lucky'));
+ stats.appendChild(CreateStatsHeader('Lucky Cookies', 'Lucky'));
if (CM.Config.StatsPref.Lucky) {
var luckyColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var luckyTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Lucky) ? CM.Disp.FormatTime((CM.Cache.Lucky - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : '';
@@ -2287,7 +2103,7 @@ CM.Disp.AddMenuStats = function(title) {
stats.appendChild(listing(listingQuest('\"Lucky!\" Reward (CUR)' + (luckySplit ? ' (Golden / Wrath)' : ''), goldCookTooltip), document.createTextNode(Beautify(luckyCur) + (luckySplit ? (' / ' + Beautify(luckyCurWrath)) : ''))));
}
- stats.appendChild(header('Chain Cookies', 'Chain'));
+ stats.appendChild(CreateStatsHeader('Chain Cookies', 'Chain'));
if (CM.Config.StatsPref.Chain) {
var chainColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var chainTime = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Chain) ? CM.Disp.FormatTime((CM.Cache.Chain - (Game.cookies + CM.Disp.GetWrinkConfigBank())) / CM.Disp.GetCPS()) : '';
@@ -2360,7 +2176,7 @@ CM.Disp.AddMenuStats = function(title) {
stats.appendChild(listing(listingQuest('\"Chain\" Reward (CUR) (Golden / Wrath)', goldCookTooltip), document.createTextNode(Beautify(chainCur) + ' / ' + Beautify(chainCurWrath))));
}
- stats.appendChild(header('Conjure Baked Goods', 'Conjure'));
+ stats.appendChild(CreateStatsHeader('Conjure Baked Goods', 'Conjure'));
if (CM.Config.StatsPref.Conjure) {
var conjureColor = ((Game.cookies + CM.Disp.GetWrinkConfigBank()) < CM.Cache.Conjure) ? CM.Disp.colorRed : CM.Disp.colorGreen;
var conjureCur = Math.min((Game.cookies + CM.Disp.GetWrinkConfigBank()) * 0.15, CM.Cache.NoGoldSwitchCookiesPS * 60 * 30);
@@ -2385,7 +2201,7 @@ CM.Disp.AddMenuStats = function(title) {
var choEgg = (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')); // Needs to be done for the checking below
- stats.appendChild(header('Prestige', 'Prestige'));
+ stats.appendChild(CreateStatsHeader('Prestige', 'Prestige'));
if (CM.Config.StatsPref.Prestige) {
var possiblePresMax = Math.floor(Game.HowMuchPrestige(CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0)));
var neededCook = Game.HowManyCookiesReset(possiblePresMax + 1) - (CM.Cache.RealCookiesEarned + Game.cookiesReset + CM.Cache.WrinkGodBank + (choEgg ? CM.Cache.lastChoEgg : 0));
@@ -2463,7 +2279,7 @@ CM.Disp.AddMenuStats = function(title) {
}
if (Game.cpsSucked > 0) {
- stats.appendChild(header('Wrinklers', 'Wrink'));
+ stats.appendChild(CreateStatsHeader('Wrinklers', 'Wrink'));
if (CM.Config.StatsPref.Wrink) {
var popAllFrag = document.createDocumentFragment();
popAllFrag.appendChild(document.createTextNode(Beautify(CM.Cache.WrinkBank) + ' '));
@@ -2516,7 +2332,7 @@ CM.Disp.AddMenuStats = function(title) {
var centEgg = Game.Has('Century egg');
if (Game.season == 'christmas' || specDisp || choEgg || centEgg) {
- stats.appendChild(header('Season Specials', 'Sea'));
+ stats.appendChild(CreateStatsHeader('Season Specials', 'Sea'));
if (CM.Config.StatsPref.Sea) {
if (specDisp) {
if (halloCook.length != 0) stats.appendChild(listing('Halloween Cookies Left to Buy', createMissDisp(halloCook)));
@@ -2536,7 +2352,7 @@ CM.Disp.AddMenuStats = function(title) {
}
}
- stats.appendChild(header('Miscellaneous', 'Misc'));
+ stats.appendChild(CreateStatsHeader('Miscellaneous', 'Misc'));
if (CM.Config.StatsPref.Misc) {
stats.appendChild(listing(
'Average Cookies Per Second (Past ' + (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] < 60 ? (CM.Disp.cookieTimes[CM.Config.AvgCPSHist] + ' seconds') : ((CM.Disp.cookieTimes[CM.Config.AvgCPSHist] / 60) + (CM.Config.AvgCPSHist == 3 ? ' minute' : ' minutes'))) + ')',
@@ -2560,6 +2376,42 @@ CM.Disp.AddMenuStats = function(title) {
}
l('menu').insertBefore(stats, l('menu').childNodes[2]);
+
+ if (CM.Config.MissingUpgrades) {
+ CM.Disp.AddMissingUpgrades();
+ }
+}
+
+/**
+ * This function creates a header-object for the stats page
+ * It is called by CM.Disp.AddMenuStats()
+ * @param {string} config The name of the Config-group
+ * @param {string} text The to-be displayed name of the header
+ * @returns {object} div The header object
+ */
+CM.Disp.CreateStatsHeader = function(text, config) {
+ var div = document.createElement('div');
+ div.className = 'listing';
+ div.style.padding = '5px 16px';
+ div.style.opacity = '0.7';
+ div.style.fontSize = '17px';
+ div.style.fontFamily = '\"Kavoon\", Georgia, serif';
+ div.appendChild(document.createTextNode(text + ' '));
+ var span = document.createElement('span');
+ span.style.cursor = 'pointer';
+ span.style.display = 'inline-block';
+ span.style.height = '14px';
+ span.style.width = '14px';
+ span.style.borderRadius = '7px';
+ span.style.textAlign = 'center';
+ span.style.backgroundColor = '#C0C0C0';
+ span.style.color = 'black';
+ span.style.fontSize = '13px';
+ span.style.verticalAlign = 'middle';
+ span.textContent = CM.Config.StatsPref[config] ? '-' : '+';
+ span.onclick = function() {CM.ToggleStatsConfig(config); Game.UpdateMenu();};
+ div.appendChild(span);
+ return div;
}
CM.Disp.AddMissingUpgrades = function() {
@@ -2641,11 +2493,35 @@ CM.Disp.AddMissingUpgrades = function() {
/********
* Section: Variables used in Disp functions
- * TODO: Move certain variables to src/Data.js (e.g., CM.Disp.metric & CM.Disp.shortScale) */
+ */
+/**
+ * This list is used to make some very basic tooltips.
+ * It is used by CM.DelayInit() in the call of CM.Disp.CreateSimpleTooltip()
+ * @item {string} placeholder
+ * @item {string} text
+ * @item {string} minWidth
+ */
+CM.Disp.TooltipText = [
+ ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'],
+ ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'],
+ ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'],
+ ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'],
+ ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'],
+ ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'],
+ ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px']
+];
+
+/**
+ * These are variables used to create DOM object names and id (e.g., 'CMTextTooltip)
+ */
CM.Disp.colorTextPre = 'CMText';
CM.Disp.colorBackPre = 'CMBack';
CM.Disp.colorBorderPre = 'CMBorder';
+
+/**
+ * These are variables which can be set in the options by the user to standardize colours throughout CookieMonster
+ */
CM.Disp.colorBlue = 'Blue';
CM.Disp.colorGreen = 'Green';
CM.Disp.colorYellow = 'Yellow';
@@ -2656,40 +2532,25 @@ CM.Disp.colorGray = 'Gray';
CM.Disp.colorPink = 'Pink';
CM.Disp.colorBrown = 'Brown';
CM.Disp.colors = [CM.Disp.colorBlue, CM.Disp.colorGreen, CM.Disp.colorYellow, CM.Disp.colorOrange, CM.Disp.colorRed, CM.Disp.colorPurple, CM.Disp.colorGray, CM.Disp.colorPink, CM.Disp.colorBrown];
+
+
+/**
+ * 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};
-CM.Disp.lastGoldenCookieState = 0;
-CM.Disp.lastSpawnedGoldenCookieState = 0;
-CM.Disp.currSpawnedGoldenCookieState
-CM.Disp.lastTickerFortuneState = 0;
-CM.Disp.lastSeasonPopupState = 0;
-CM.Disp.lastGardenNextStep = 0;
-CM.Disp.lastMagicBarFull = 0;
-CM.Disp.lastWrinklerCount = 0;
-CM.Disp.goldenShimmersByID = {};
-CM.Disp.spawnedGoldenShimmer = 0;
CM.Disp.GCTimers = {};
-CM.Disp.seasonPopShimmer;
CM.Disp.lastAscendState = -1;
+/**
+ * These lists are used in the stats page to show
+ * average cookies per {CM.Disp.cookieTimes/CM.Disp.clickTimes} seconds
+ */
CM.Disp.cookieTimes = [10, 15, 30, 60, 300, 600, 900, 1800];
CM.Disp.clickTimes = [1, 5, 10, 15, 30];
-CM.Disp.metric = ['M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
-CM.Disp.shortScale = ['M', 'B', 'Tr', 'Quadr', 'Quint', 'Sext', 'Sept', 'Oct', 'Non', 'Dec', 'Undec', 'Duodec', 'Tredec', 'Quattuordec', 'Quindec', 'Sexdec', 'Septendec', 'Octodec', 'Novemdec', 'Vigint', 'Unvigint', 'Duovigint', 'Trevigint', 'Quattuorvigint'];
-
+/**
+ * These are variables with base-values that get initalized when initliazing CookieMonster
+ * TODO: See if these can be removed or moved
+ */
CM.Disp.TooltipWrinklerArea = 0;
CM.Disp.TooltipWrinkler = -1;
-CM.Disp.TooltipWrinklerCache = [];
-for (var i in Game.wrinklers) {
- CM.Disp.TooltipWrinklerCache[i] = 0;
-}
-
-CM.Disp.TooltipText = [
- ['GoldCookTooltipPlaceholder', 'Calculated with Golden Switch off', '200px'],
- ['GoldCookDragonsFortuneTooltipPlaceholder', 'Calculated with Golden Switch off and at least one golden cookie on-screen', '240px'],
- ['PrestMaxTooltipPlaceholder', 'The MAX prestige is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '320px'],
- ['NextPrestTooltipPlaceholder', 'Calculated with cookies gained from wrinklers and Chocolate egg', '200px'],
- ['HeavenChipMaxTooltipPlaceholder', 'The MAX heavenly chips is calculated with the cookies gained from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and buying Chocolate egg', '330px'],
- ['ResetTooltipPlaceholder', 'The bonus income you would get from new prestige levels unlocked at 100% of its potential and from ascension achievements if you have the same buildings/upgrades after reset', '370px'],
- ['ChoEggTooltipPlaceholder', 'The amount of cookies you would get from popping all wrinklers with Skruuia god in Diamond slot, selling all stock market goods, selling all buildings with Earth Shatterer and Reality Bending auras, and then buying Chocolate egg', '300px']
-];
diff --git a/src/Header.js b/src/Header.js
index 26893fb..3731fa3 100644
--- a/src/Header.js
+++ b/src/Header.js
@@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() {
CM.Disp = {};
+ CM.Main = {};
+
CM.Sim = {};
}
diff --git a/src/Main.js b/src/Main.js
index 657bdd8..5bf1c02 100644
--- a/src/Main.js
+++ b/src/Main.js
@@ -18,14 +18,12 @@ CM.ReplaceNative = function() {
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.Disp.DrawTooltipWarn();
}
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.UpdateTooltipWarn();
CM.Disp.UpdateTooltipLocation();
}
@@ -51,10 +49,12 @@ CM.ReplaceNative = function() {
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();
- CM.Disp.AddTooltipUpgrade();
+ CM.Disp.ReplaceTooltipUpgrade();
Game.CalculateGains();
}
@@ -165,14 +165,15 @@ CM.Loop = function() {
CM.Cache.RemakePP();
// Update colors
- CM.Disp.UpdateBotBarOther();
CM.Disp.UpdateBuildings();
CM.Disp.UpdateUpgrades();
// Redraw timers
- CM.Disp.UpdateBotBarTime();
CM.Disp.UpdateTimerBar();
+ // Update Bottom Bar
+ CM.Disp.UpdateBotBar();
+
// Update Tooltip
CM.Disp.UpdateTooltip();
@@ -184,23 +185,13 @@ CM.Loop = function() {
CM.Disp.RefreshMenu();
}
- // Check Golden Cookies
- CM.Disp.CheckGoldenCookie();
-
- // Check Fortune Cookies
- CM.Disp.CheckTickerFortune();
-
- // Check Season Popup
- CM.Disp.CheckSeasonPopup();
-
- // Check Garden Tick
- CM.Disp.CheckGardenTick();
-
- // Check Grimoire Meter
- CM.Disp.CheckMagicMeter();
-
- // Check Wrinklers
- CM.Disp.CheckWrinklerCount();
+ // 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.UpdateAvgCPS()
@@ -233,13 +224,12 @@ CM.DelayInit = function() {
CM.Disp.CreateWhiteScreen();
CM.Disp.CreateFavicon();
for (var i in CM.Disp.TooltipText) {
- CM.Disp.CreateTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]);
+ CM.Disp.CreateSimpleTooltip(CM.Disp.TooltipText[i][0], CM.Disp.TooltipText[i][1], CM.Disp.TooltipText[i][2]);
}
- CM.Disp.CreateTooltipWarn();
- CM.Disp.AddTooltipBuild();
- CM.Disp.AddTooltipGrimoire();
- CM.Disp.AddTooltipLump();
- CM.Disp.AddWrinklerAreaDetect();
+ CM.Disp.ReplaceTooltipBuild();
+ CM.Disp.ReplaceTooltipGrimoire();
+ CM.Disp.ReplaceTooltipLump();
+ CM.Main.AddWrinklerAreaDetect();
CM.Cache.InitCookiesDiff();
CM.ReplaceNative();
CM.ReplaceNativeGrimoire();
@@ -256,9 +246,197 @@ CM.DelayInit = function() {
Game.Win('Third-party');
}
+/********
+ * Section: Functions related to checking for changes in Minigames/GC's/Ticker
+ * TODO: Annotate functions
+ * TODO: Possibly move this section */
+
+/**
+ * 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 (var i in 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.Loop
+ * TODO: Remove the delete function, as it does not delete correctly and crowds CM.Disp.GCTimers
+ */
+CM.Main.CheckGoldenCookie = function() {
+ CM.Main.FindShimmer();
+ for (var i in CM.Disp.GCTimers) {
+ if (typeof CM.Cache.goldenShimmersByID[i] == "undefined") {
+ CM.Disp.GCTimers[i].parentNode.removeChild(CM.Disp.GCTimers[i]);
+ // TODO remove delete here
+ 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.Config.GCSoundURL, 'GCSound', 'GCVolume');
+ CM.Disp.Notification('GCNotification', "Golden Cookie Spawned", "A Golden Cookie has spawned. Click it now!")
+ }
+ CM.Disp.UpdateFavicon();
+
+ for (var i in Game.shimmers) {
+ if (typeof CM.Disp.GCTimers[Game.shimmers[i].id] == "undefined") {
+ CM.Disp.CreateGCTimer(Game.shimmers[i]);
+ }
+ }
+ }
+ CM.Main.lastSpawnedGoldenCookieState = CM.Main.currSpawnedGoldenCookieState
+ if (CM.Main.currSpawnedGoldenCookieState == 0) CM.Cache.spawnedGoldenShimmer = 0;
+ }
+ else if (CM.Config.GCTimer == 1 && CM.Main.lastGoldenCookieState) {
+ for (var i in 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.Loop
+ */
+CM.Main.CheckSeasonPopup = function() {
+ if (CM.Main.lastSeasonPopupState != Game.shimmerTypes['reindeer'].spawned) {
+ CM.Main.lastSeasonPopupState = Game.shimmerTypes['reindeer'].spawned;
+ for (var i in 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.Config.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.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.Config.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.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.Config.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.Loop
+ */
+CM.Main.CheckMagicMeter = function() {
+ if (Game.Objects['Wizard tower'].minigameLoaded && CM.Config.GrimoireBar == 1) {
+ var 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.Config.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.Loop
+ */
+CM.Main.CheckWrinklerCount = function() {
+ if (Game.elderWrath > 0) {
+ var CurrentWrinklers = 0;
+ for (var 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.Config.WrinklerMaxFlash) {
+ CM.Disp.Flash(3, 'WrinklerMaxFlash');
+ } else {
+ CM.Disp.Flash(3, 'WrinklerFlash');
+ }
+ if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.WrinklerMaxSound) {
+ CM.Disp.PlaySound(CM.Config.WrinklerMaxSoundURL, 'WrinklerMaxSound', 'WrinklerMaxVolume');
+ } else {
+ CM.Disp.PlaySound(CM.Config.WrinklerSoundURL, 'WrinklerSound', 'WrinklerVolume');
+ }
+ if (CurrentWrinklers == Game.getWrinklersMax() && CM.Config.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.DelayInit
+ * TODO: The system for displaying wrinklers should ideally use a similar system as other tooltips
+ * Thus, writing a CM.Disp.ReplaceTooltipWrinkler function etc.
+ */
+CM.Main.AddWrinklerAreaDetect = function() {
+ l('backgroundLeftCanvas').onmouseover = function() {CM.Disp.TooltipWrinklerArea = 1;};
+ l('backgroundLeftCanvas').onmouseout = function() {
+ CM.Disp.TooltipWrinklerArea = 0;
+ Game.tooltip.hide();
+ for (var i in Game.wrinklers) {
+ CM.Disp.TooltipWrinklerCache[i] = 0;
+ }
+ };
+}
+
CM.HasReplaceNativeGrimoireLaunch = false;
CM.HasReplaceNativeGrimoireDraw = false;
+CM.Main.lastGoldenCookieState = 0;
+CM.Main.lastSpawnedGoldenCookieState = 0;
+CM.Main.currSpawnedGoldenCookieState
+CM.Main.lastTickerFortuneState = 0;
+CM.Main.lastSeasonPopupState = 0;
+CM.Main.lastGardenNextStep = 0;
+CM.Main.lastMagicBarFull = 0;
+CM.Main.lastWrinklerCount = 0;
+
CM.ConfigDefault = {
BotBar: 1,
TimerBar: 1,
@@ -325,7 +503,7 @@ CM.ConfigDefault = {
SayTime: 1,
GrimoireBar: 1,
Scale: 2,
- MenuPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1},
+ OptionsPref: {BarsColors: 1, Calculation: 1, Notification: 1, Tooltip: 1, Statistics: 1, Other: 1},
StatsPref: {Lucky: 1, Conjure: 1, Chain: 1, Prestige: 1, Wrink: 1, Sea: 1, Misc: 1},
Colors : {Blue: '#4bb8f0', Green: '#00ff00', Yellow: '#ffff00', Orange: '#ff7f00', Red: '#ff0000', Purple: '#ff00ff', Gray: '#b3b3b3', Pink: '#ff1493', Brown: '#8b4513'},
SortBuildings: 0,
diff --git a/src/Sim.js b/src/Sim.js
index 902cc7b..17988c2 100644
--- a/src/Sim.js
+++ b/src/Sim.js
@@ -118,7 +118,7 @@ CM.Sim.eff = function(name) {
return CM.Sim.effs[name]
}
else {
- return Game.effs[name];
+ return CM.Sim.effs[name];
}
}
@@ -252,7 +252,7 @@ CM.Sim.CalculateGains = function() {
var mult = 1;
// Include minigame effects
var effs={};
- for (var i in CM.Cache.Objects) {
+ for (var i in Game.Objects) {
// TODO Store minigames and effects in Cache
// Include possibility of new/modded building and new/modded minigames
if (CM.Sim.Objects[i].minigameLoaded && CM.Sim.Objects[i].minigame.effs) {