Use framework for Options menu

This commit is contained in:
Daniël van Noord
2021-07-20 18:08:32 +02:00
parent e9dc2ffa51
commit 82c872ef18
4 changed files with 101 additions and 48 deletions

View File

@@ -1,49 +1,10 @@
import saveFramework from '@cookiemonsterteam/cookiemonsterframework/src/saveDataFunctions/saveFramework';
import settings from '../Data/settings';
import { saveAndLoadingFunctions } from '@cookiemonsterteam/cookiemonsterframework/src/index';
/** Functions related to toggling or changing an individual setting */
/** Used to name certain DOM or outside facing elements and refer to them */
export const ConfigPrefix = 'CMConfig';
/**
* This function toggles options by incrementing them with 1 and handling changes
* It is called by the onclick event of options of the "bool" type
* @param {string} config The name of the option
*/
export function ToggleConfig(config) {
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] += 1;
if (
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] ===
settings[config].label.length
) {
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] = 0;
if (settings[config].toggle) l(ConfigPrefix + config).className = 'option off';
} else l(ConfigPrefix + config).className = 'option';
if (typeof settings[config].func !== 'undefined') {
settings[config].func();
}
saveFramework();
}
/**
* This function sets the value of the specified volume-option and updates the display in the options menu
* It is called by the oninput and onchange event of "vol" type options
* @param {string} config The name of the option
*/
export function ToggleConfigVolume(config) {
if (l(`slider${config}`) !== null) {
l(`slider${config}right`).innerHTML = `${l(`slider${config}`).value}%`;
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] = Math.round(
l(`slider${config}`).value,
);
}
saveFramework();
}
/**
* This function toggles header options by incrementing them with 1 and handling changes
* It is called by the onclick event of the +/- next to headers
@@ -53,5 +14,5 @@ export function ToggleHeader(config) {
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[config] += 1;
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[config] > 1)
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[config] = 0;
saveFramework();
saveAndLoadingFunctions.saveFramework();
}