Files
CookieMonster/src/Footer.js
Daniël van Noord db22e07d8e Fixed #617
2021-02-25 22:17:21 +01:00

83 lines
2.7 KiB
JavaScript

/**
* 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 () {
CM.Footer.isInitzializing = true;
let proceed = true;
if (Game.version !== Number(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.Main.DelayInit();
Game.registerHook('draw', CM.Disp.Draw);
Game.registerHook('logic', CM.Main.Loop);
CM.Footer.isInitzializing = false;
}
};
/**
* 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) {
const save = JSON.parse(str);
CM.Sim.InitData();
CM.Config.LoadConfig(save.settings);
if (save.version !== `${CM.VersionMajor}.${CM.VersionMinor}`) {
if (Game.prefs.popups) Game.Popup('A new version of Cookie Monster has been loaded, check out the release notes in the info tab!');
else Game.Notify('A new version of Cookie Monster has been loaded, check out the release notes in the info tab!', '', '', 0, 1);
}
};
/**
* Section: Functions related to the initialization of CookieMonster */
/**
* 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 (typeof CM.Footer.isInitzializing === 'undefined') {
CM.Footer.AddJscolor();
const delay = setInterval(function () {
if (typeof jscolor !== 'undefined') {
jscolor.init();
Game.registerMod('CookieMonster', CM);
clearInterval(delay);
}
}, 500);
}