Incorporated Modding API
This commit is contained in:
@@ -190,7 +190,7 @@ CM.Cache.CacheMissingUpgrades = function() {
|
|||||||
CM.Cache.AddQueue = function() {
|
CM.Cache.AddQueue = function() {
|
||||||
CM.Cache.Queue = document.createElement('script');
|
CM.Cache.Queue = document.createElement('script');
|
||||||
CM.Cache.Queue.type = 'text/javascript';
|
CM.Cache.Queue.type = 'text/javascript';
|
||||||
CM.Cache.Queue.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/queue/queue.js');
|
CM.Cache.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js';
|
||||||
document.head.appendChild(CM.Cache.Queue);
|
document.head.appendChild(CM.Cache.Queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -682,16 +682,16 @@ CM.Cache.spawnedGoldenShimmer = 0;
|
|||||||
* @param {object} config The Config to be saved (normally CM.Options)
|
* @param {object} config The Config to be saved (normally CM.Options)
|
||||||
*/
|
*/
|
||||||
CM.Config.SaveConfig = function(config) {
|
CM.Config.SaveConfig = function(config) {
|
||||||
localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config));
|
CM.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
||||||
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
||||||
*/
|
*/
|
||||||
CM.Config.LoadConfig = function() {
|
CM.Config.LoadConfig = function(settings) {
|
||||||
if (localStorage.getItem(CM.ConfigPrefix) != null) {
|
if (settings != null) {
|
||||||
CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix));
|
CM.Options = settings;
|
||||||
|
|
||||||
// Check values
|
// Check values
|
||||||
var mod = false;
|
var mod = false;
|
||||||
@@ -749,9 +749,8 @@ CM.Config.LoadConfig = function() {
|
|||||||
* It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found
|
* It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found
|
||||||
*/
|
*/
|
||||||
CM.Config.RestoreDefault = function() {
|
CM.Config.RestoreDefault = function() {
|
||||||
CM.Options = {};
|
CM.Config.LoadConfig(CM.Data.ConfigDefault);
|
||||||
CM.Config.SaveConfig(CM.Data.ConfigDefault);
|
CM.Config.SaveConfig();
|
||||||
CM.Config.LoadConfig();
|
|
||||||
Game.UpdateMenu();
|
Game.UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1386,7 +1385,7 @@ CM.Disp.CreateCssArea = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: What does this do? @Aktanusa
|
* TODO: What does this do? @Aktanusa
|
||||||
* It is called by CM.Init()
|
* It is called by CM.init, which is called by Game.registerMod
|
||||||
*/
|
*/
|
||||||
CM.Disp.AddJscolor = function() {
|
CM.Disp.AddJscolor = function() {
|
||||||
CM.Disp.Jscolor = document.createElement('script');
|
CM.Disp.Jscolor = document.createElement('script');
|
||||||
@@ -4090,24 +4089,6 @@ CM.Loop = function() {
|
|||||||
CM.Cache.UpdateAvgCPS()
|
CM.Cache.UpdateAvgCPS()
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Init = function() {
|
|
||||||
var proceed = true;
|
|
||||||
if (Game.version != CM.VersionMajor) {
|
|
||||||
proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?');
|
|
||||||
}
|
|
||||||
if (proceed) {
|
|
||||||
CM.Cache.AddQueue();
|
|
||||||
CM.Disp.AddJscolor();
|
|
||||||
|
|
||||||
var delay = setInterval(function() {
|
|
||||||
if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') {
|
|
||||||
CM.DelayInit();
|
|
||||||
clearInterval(delay);
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CM.DelayInit = function() {
|
CM.DelayInit = function() {
|
||||||
CM.Sim.InitData();
|
CM.Sim.InitData();
|
||||||
CM.Cache.InitCache();
|
CM.Cache.InitCache();
|
||||||
@@ -4144,18 +4125,9 @@ CM.DelayInit = function() {
|
|||||||
l("upgrades").style.display = "flex";
|
l("upgrades").style.display = "flex";
|
||||||
l("upgrades").style["flex-wrap"] = "wrap";
|
l("upgrades").style["flex-wrap"] = "wrap";
|
||||||
|
|
||||||
CM.Main.RegisterHooks();
|
|
||||||
|
|
||||||
Game.Win('Third-party');
|
Game.Win('Third-party');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook custom methods into the game
|
|
||||||
*/
|
|
||||||
CM.Main.RegisterHooks = function() {
|
|
||||||
Game.registerHook('draw', CM.Disp.Draw);
|
|
||||||
}
|
|
||||||
|
|
||||||
/********
|
/********
|
||||||
* Section: Functions related to checking for changes in Minigames/GC's/Ticker
|
* Section: Functions related to checking for changes in Minigames/GC's/Ticker
|
||||||
* TODO: Possibly move this section */
|
* TODO: Possibly move this section */
|
||||||
@@ -4580,6 +4552,7 @@ CM.Sim.InitData = function() {
|
|||||||
for (var i in Game.Achievements) {
|
for (var i in Game.Achievements) {
|
||||||
CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i);
|
CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i);
|
||||||
}
|
}
|
||||||
|
CM.Sim.CopyData
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Sim.CopyData = function() {
|
CM.Sim.CopyData = function() {
|
||||||
@@ -5275,8 +5248,53 @@ CM.Sim.mouseCps = function() {
|
|||||||
* Footer *
|
* Footer *
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
|
/********
|
||||||
|
* Section: Functions related to base game modding API */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: This should at one point be used to register hooks
|
||||||
|
*/
|
||||||
|
CM.init = function() {
|
||||||
|
var proceed = true;
|
||||||
|
if (Game.version != CM.VersionMajor) {
|
||||||
|
proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?');
|
||||||
|
}
|
||||||
|
if (proceed) {
|
||||||
|
CM.DelayInit();
|
||||||
|
Game.registerHook('draw', CM.Disp.Draw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This registers a save function. Per Game code/comments:
|
||||||
|
* "use this to store persistent data associated with your mod
|
||||||
|
* return 'a string to be saved';"
|
||||||
|
*/
|
||||||
|
CM.save = function() {
|
||||||
|
return JSON.stringify({
|
||||||
|
settings: CM.Options,
|
||||||
|
version: CM.VersionMajor + '.' + CM.VersionMinor,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This registers a load function. Per Game code/comments:
|
||||||
|
* "do stuff with the string data you saved previously"
|
||||||
|
*/
|
||||||
|
CM.load = function(str) {
|
||||||
|
let save = JSON.parse(str);
|
||||||
|
CM.Config.LoadConfig(save.settings);
|
||||||
|
}
|
||||||
|
|
||||||
if (!CM.isRunning) {
|
if (!CM.isRunning) {
|
||||||
CM.Init();
|
CM.Cache.AddQueue();
|
||||||
|
CM.Disp.AddJscolor();
|
||||||
|
var delay = setInterval(function() {
|
||||||
|
if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') {
|
||||||
|
Game.registerMod('CookieMonster', CM);
|
||||||
|
clearInterval(delay);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
CM.isRunning = 1
|
CM.isRunning = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -158,13 +158,6 @@ CM.Cache.CacheMissingUpgrades = function() {
|
|||||||
/********
|
/********
|
||||||
* Section: UNSORTED */
|
* Section: UNSORTED */
|
||||||
|
|
||||||
CM.Cache.AddQueue = function() {
|
|
||||||
CM.Cache.Queue = document.createElement('script');
|
|
||||||
CM.Cache.Queue.type = 'text/javascript';
|
|
||||||
CM.Cache.Queue.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/queue/queue.js');
|
|
||||||
document.head.appendChild(CM.Cache.Queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
CM.Cache.NextNumber = function(base) {
|
CM.Cache.NextNumber = function(base) {
|
||||||
var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1;
|
var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1;
|
||||||
while (base == base + count) {
|
while (base == base + count) {
|
||||||
|
|||||||
@@ -6,22 +6,24 @@
|
|||||||
* Section: Functions related to saving, loading and restoring configs */
|
* Section: Functions related to saving, loading and restoring configs */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function saves the config of CookieMonster to localStorage
|
* @deprecated
|
||||||
|
* This function (used to) save the config of CookieMonster
|
||||||
* It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(),
|
* It is called by CM.Config.LoadConfig(), CM.Config.RestoreDefault(), CM.Config.ToggleConfig(),
|
||||||
* CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale"
|
* CM.ToggleConfigVolume() and changes in options with type "url", "color" or "numscale"
|
||||||
* @param {object} config The Config to be saved (normally CM.Options)
|
* TODO: See if there is a way to force Cookie CLICKER to save only the mod-data and not also Save-data.
|
||||||
|
* Otherwise this can be removed
|
||||||
*/
|
*/
|
||||||
CM.Config.SaveConfig = function(config) {
|
CM.Config.SaveConfig = function(config) {
|
||||||
localStorage.setItem(CM.ConfigPrefix, JSON.stringify(config));
|
CM.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
* This function loads the config of CookieMonster saved in localStorage and loads it into CM.Options
|
||||||
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
||||||
*/
|
*/
|
||||||
CM.Config.LoadConfig = function() {
|
CM.Config.LoadConfig = function(settings) {
|
||||||
if (localStorage.getItem(CM.ConfigPrefix) != null) {
|
if (settings != null) {
|
||||||
CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix));
|
CM.Options = settings;
|
||||||
|
|
||||||
// Check values
|
// Check values
|
||||||
var mod = false;
|
var mod = false;
|
||||||
@@ -79,9 +81,8 @@ CM.Config.LoadConfig = function() {
|
|||||||
* It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found
|
* It is called by resDefBut.onclick loaded in the options page or by CM.Config.LoadConfig if no localStorage is found
|
||||||
*/
|
*/
|
||||||
CM.Config.RestoreDefault = function() {
|
CM.Config.RestoreDefault = function() {
|
||||||
CM.Options = {};
|
CM.Config.LoadConfig(CM.Data.ConfigDefault);
|
||||||
CM.Config.SaveConfig(CM.Data.ConfigDefault);
|
CM.Config.SaveConfig(CM.Options);
|
||||||
CM.Config.LoadConfig();
|
|
||||||
Game.UpdateMenu();
|
Game.UpdateMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
11
src/Disp.js
11
src/Disp.js
@@ -264,17 +264,6 @@ CM.Disp.CreateCssArea = function() {
|
|||||||
document.head.appendChild(CM.Disp.Css);
|
document.head.appendChild(CM.Disp.Css);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: What does this do? @Aktanusa
|
|
||||||
* It is called by CM.Init()
|
|
||||||
*/
|
|
||||||
CM.Disp.AddJscolor = function() {
|
|
||||||
CM.Disp.Jscolor = document.createElement('script');
|
|
||||||
CM.Disp.Jscolor.type = 'text/javascript';
|
|
||||||
CM.Disp.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js');
|
|
||||||
document.head.appendChild(CM.Disp.Jscolor);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function sets the size of the background of the full game and the left column
|
* This function sets the size of the background of the full game and the left column
|
||||||
* depending on whether certain abrs are activated
|
* depending on whether certain abrs are activated
|
||||||
|
|||||||
@@ -2,8 +2,86 @@
|
|||||||
* Footer *
|
* Footer *
|
||||||
**********/
|
**********/
|
||||||
|
|
||||||
|
/********
|
||||||
|
* Section: Functions related to base game modding API */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This register a init function to the CM object. Per Game code/comments:
|
||||||
|
* "this function is called as soon as the mod is registered
|
||||||
|
* declare hooks here"
|
||||||
|
* It starts the further initialization of CookieMonster and registers hooks
|
||||||
|
*/
|
||||||
|
CM.init = function() {
|
||||||
|
var proceed = true;
|
||||||
|
if (Game.version != CM.VersionMajor) {
|
||||||
|
proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?');
|
||||||
|
}
|
||||||
|
if (proceed) {
|
||||||
|
CM.DelayInit();
|
||||||
|
Game.registerHook('draw', CM.Disp.Draw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This registers a save function to the CM object. Per Game code/comments:
|
||||||
|
* "use this to store persistent data associated with your mod
|
||||||
|
* return 'a string to be saved';"
|
||||||
|
*/
|
||||||
|
CM.save = function() {
|
||||||
|
return JSON.stringify({
|
||||||
|
settings: CM.Options,
|
||||||
|
version: CM.VersionMajor + '.' + CM.VersionMinor,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This registers a load function to the CM object. Per Game code/comments:
|
||||||
|
* "do stuff with the string data you saved previously"
|
||||||
|
*/
|
||||||
|
CM.load = function(str) {
|
||||||
|
let save = JSON.parse(str);
|
||||||
|
CM.Config.LoadConfig(save.settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/********
|
||||||
|
* Section: Functions related to the initialization of CookieMonster */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This functions loads an external script (on the same repository) that creates a Queue() function
|
||||||
|
* It is called by the last function in the footer
|
||||||
|
*/
|
||||||
|
CM.Footer.AddQueue = function() {
|
||||||
|
CM.Footer.Queue = document.createElement('script');
|
||||||
|
CM.Footer.Queue.type = 'text/javascript';
|
||||||
|
CM.Footer.Queue.src = 'https://aktanusa.github.io/CookieMonster/queue/queue.js';
|
||||||
|
document.head.appendChild(CM.Footer.Queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This functions loads an external script (on the same repository) that creates the
|
||||||
|
* functionality needed to dynamiccaly change colours
|
||||||
|
* It is called by the last function in the footer
|
||||||
|
*/
|
||||||
|
CM.Footer.AddJscolor = function() {
|
||||||
|
CM.Footer.Jscolor = document.createElement('script');
|
||||||
|
CM.Footer.Jscolor.type = 'text/javascript';
|
||||||
|
CM.Footer.Jscolor.setAttribute('src', 'https://aktanusa.github.io/CookieMonster/jscolor/jscolor.js');
|
||||||
|
document.head.appendChild(CM.Footer.Jscolor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This functions starts the initizialization and register CookieMonster
|
||||||
|
* It is called as the last function in this script's execution
|
||||||
|
*/
|
||||||
if (!CM.isRunning) {
|
if (!CM.isRunning) {
|
||||||
CM.Init();
|
CM.Footer.AddQueue();
|
||||||
|
CM.Footer.AddJscolor();
|
||||||
|
var delay = setInterval(function() {
|
||||||
|
if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') {
|
||||||
|
Game.registerMod('CookieMonster', CM);
|
||||||
|
clearInterval(delay);
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
CM.isRunning = 1
|
CM.isRunning = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() {
|
|||||||
|
|
||||||
CM.Disp = {};
|
CM.Disp = {};
|
||||||
|
|
||||||
|
CM.Footer = {};
|
||||||
|
|
||||||
CM.Main = {};
|
CM.Main = {};
|
||||||
|
|
||||||
CM.Options = {};
|
CM.Options = {};
|
||||||
|
|||||||
27
src/Main.js
27
src/Main.js
@@ -211,24 +211,6 @@ CM.Loop = function() {
|
|||||||
CM.Cache.UpdateAvgCPS()
|
CM.Cache.UpdateAvgCPS()
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Init = function() {
|
|
||||||
var proceed = true;
|
|
||||||
if (Game.version != CM.VersionMajor) {
|
|
||||||
proceed = confirm('Cookie Monster version ' + CM.VersionMajor + '.' + CM.VersionMinor + ' is meant for Game version ' + CM.VersionMajor + '. Loading a different version may cause errors. Do you still want to load Cookie Monster?');
|
|
||||||
}
|
|
||||||
if (proceed) {
|
|
||||||
CM.Cache.AddQueue();
|
|
||||||
CM.Disp.AddJscolor();
|
|
||||||
|
|
||||||
var delay = setInterval(function() {
|
|
||||||
if (typeof Queue !== 'undefined' && typeof jscolor !== 'undefined') {
|
|
||||||
CM.DelayInit();
|
|
||||||
clearInterval(delay);
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CM.DelayInit = function() {
|
CM.DelayInit = function() {
|
||||||
CM.Sim.InitData();
|
CM.Sim.InitData();
|
||||||
CM.Cache.InitCache();
|
CM.Cache.InitCache();
|
||||||
@@ -265,18 +247,9 @@ CM.DelayInit = function() {
|
|||||||
l("upgrades").style.display = "flex";
|
l("upgrades").style.display = "flex";
|
||||||
l("upgrades").style["flex-wrap"] = "wrap";
|
l("upgrades").style["flex-wrap"] = "wrap";
|
||||||
|
|
||||||
CM.Main.RegisterHooks();
|
|
||||||
|
|
||||||
Game.Win('Third-party');
|
Game.Win('Third-party');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hook custom methods into the game
|
|
||||||
*/
|
|
||||||
CM.Main.RegisterHooks = function() {
|
|
||||||
Game.registerHook('draw', CM.Disp.Draw);
|
|
||||||
}
|
|
||||||
|
|
||||||
/********
|
/********
|
||||||
* Section: Functions related to checking for changes in Minigames/GC's/Ticker
|
* Section: Functions related to checking for changes in Minigames/GC's/Ticker
|
||||||
* TODO: Possibly move this section */
|
* TODO: Possibly move this section */
|
||||||
|
|||||||
@@ -207,6 +207,7 @@ CM.Sim.InitData = function() {
|
|||||||
for (var i in Game.Achievements) {
|
for (var i in Game.Achievements) {
|
||||||
CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i);
|
CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i);
|
||||||
}
|
}
|
||||||
|
CM.Sim.CopyData
|
||||||
}
|
}
|
||||||
|
|
||||||
CM.Sim.CopyData = function() {
|
CM.Sim.CopyData = function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user