Incorporated Modding API
This commit is contained in:
@@ -158,13 +158,6 @@ CM.Cache.CacheMissingUpgrades = function() {
|
||||
/********
|
||||
* 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) {
|
||||
var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1;
|
||||
while (base == base + count) {
|
||||
|
||||
@@ -6,22 +6,24 @@
|
||||
* 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(),
|
||||
* 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) {
|
||||
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
|
||||
* It is called by CM.DelayInit() and CM.Config.RestoreDefault()
|
||||
*/
|
||||
CM.Config.LoadConfig = function() {
|
||||
if (localStorage.getItem(CM.ConfigPrefix) != null) {
|
||||
CM.Options = JSON.parse(localStorage.getItem(CM.ConfigPrefix));
|
||||
CM.Config.LoadConfig = function(settings) {
|
||||
if (settings != null) {
|
||||
CM.Options = settings;
|
||||
|
||||
// Check values
|
||||
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
|
||||
*/
|
||||
CM.Config.RestoreDefault = function() {
|
||||
CM.Options = {};
|
||||
CM.Config.SaveConfig(CM.Data.ConfigDefault);
|
||||
CM.Config.LoadConfig();
|
||||
CM.Config.LoadConfig(CM.Data.ConfigDefault);
|
||||
CM.Config.SaveConfig(CM.Options);
|
||||
Game.UpdateMenu();
|
||||
}
|
||||
|
||||
|
||||
11
src/Disp.js
11
src/Disp.js
@@ -264,17 +264,6 @@ CM.Disp.CreateCssArea = function() {
|
||||
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
|
||||
* depending on whether certain abrs are activated
|
||||
|
||||
@@ -2,8 +2,86 @@
|
||||
* 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) {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ RunCookieMonsterHeader = function() {
|
||||
|
||||
CM.Disp = {};
|
||||
|
||||
CM.Footer = {};
|
||||
|
||||
CM.Main = {};
|
||||
|
||||
CM.Options = {};
|
||||
|
||||
27
src/Main.js
27
src/Main.js
@@ -211,24 +211,6 @@ CM.Loop = function() {
|
||||
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.Sim.InitData();
|
||||
CM.Cache.InitCache();
|
||||
@@ -265,18 +247,9 @@ CM.DelayInit = function() {
|
||||
l("upgrades").style.display = "flex";
|
||||
l("upgrades").style["flex-wrap"] = "wrap";
|
||||
|
||||
CM.Main.RegisterHooks();
|
||||
|
||||
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
|
||||
* TODO: Possibly move this section */
|
||||
|
||||
@@ -207,6 +207,7 @@ CM.Sim.InitData = function() {
|
||||
for (var i in Game.Achievements) {
|
||||
CM.Sim.Achievements[i] = CM.Sim.InitAchievement(i);
|
||||
}
|
||||
CM.Sim.CopyData
|
||||
}
|
||||
|
||||
CM.Sim.CopyData = function() {
|
||||
|
||||
Reference in New Issue
Block a user