Remove functions and tests that moved to framework
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
import { FavouriteSettings } from '../../Disp/VariablesAndData';
|
||||
|
||||
/**
|
||||
* This function toggles whether a setting is part of the favourites section in setting or not
|
||||
* @param {string} config The name of the toggleable config option
|
||||
*/
|
||||
export default function ToggleFavouriteSetting(config) {
|
||||
if (FavouriteSettings.includes(config))
|
||||
FavouriteSettings = FavouriteSettings.filter((ele) => ele !== config);
|
||||
else FavouriteSettings.push(config);
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
const ConfigPrefix = 'CMConfig';
|
||||
export default ConfigPrefix;
|
||||
@@ -1,22 +0,0 @@
|
||||
/** Creates a Prompt similar to the base game without some of the stuff breaking them */
|
||||
export default function CookieMonsterPrompt(content, options) {
|
||||
Game.promptWrapL.className = 'framed';
|
||||
const str = content;
|
||||
Game.promptL.innerHTML = `${str}<div class="optionBox"></div>`;
|
||||
Object.keys(options).forEach((i) => {
|
||||
const option = document.createElement('a');
|
||||
option.id = `promptOption${i}`;
|
||||
option.className = 'option';
|
||||
option.onclick = function () {
|
||||
PlaySound('snd/tick.mp3');
|
||||
options[i][1]();
|
||||
};
|
||||
option.textContent = options[i][0];
|
||||
Game.promptL.children[1].appendChild(option);
|
||||
});
|
||||
Game.promptAnchorL.style.display = 'block';
|
||||
Game.darkenL.style.display = 'block';
|
||||
Game.promptL.focus();
|
||||
Game.promptOn = 1;
|
||||
Game.UpdatePrompt();
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import { ToggleHeader } from '../../../Config/ToggleSetting';
|
||||
|
||||
/**
|
||||
* This function creates a header-object for the options page
|
||||
* @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
|
||||
*/
|
||||
export default function CreatePrefHeader(config, text) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'title';
|
||||
|
||||
div.style.opacity = '0.7';
|
||||
div.style.fontSize = '17px';
|
||||
div.appendChild(document.createTextNode(`${text} `));
|
||||
const 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 = Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[config]
|
||||
? '-'
|
||||
: '+';
|
||||
span.onclick = function () {
|
||||
ToggleHeader(config);
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
div.appendChild(span);
|
||||
return div;
|
||||
}
|
||||
@@ -1,247 +0,0 @@
|
||||
import saveFramework from '@cookiemonsterteam/cookiemonsterframework/src/saveDataFunctions/saveFramework';
|
||||
import jscolor, * as JsColor from '@eastdesire/jscolor';
|
||||
import ToggleFavouriteSetting from '../../../Config/Toggles/ToggleFavourites';
|
||||
import { ConfigPrefix, ToggleConfig, ToggleConfigVolume } from '../../../Config/ToggleSetting';
|
||||
import {} from '../../../Data/Sectionheaders.ts';
|
||||
import settings from '../../../Data/settings';
|
||||
import RefreshScale from '../../HelperFunctions/RefreshScale';
|
||||
import UpdateColours from '../../HelperFunctions/UpdateColours';
|
||||
import Flash from '../../Notifications/Flash';
|
||||
import PlaySound from '../../Notifications/Sound';
|
||||
import { FavouriteSettings, SimpleTooltipElements } from '../../VariablesAndData';
|
||||
import CookieMonsterPrompt from '../Prompt';
|
||||
|
||||
/**
|
||||
* This function creates the favourite setting star object
|
||||
* @param {string} config The name of the option
|
||||
* @returns {object} div The option object
|
||||
*/
|
||||
function CreateFavouriteStar(config) {
|
||||
const FavStar = document.createElement('a');
|
||||
if (FavouriteSettings.includes(config)) {
|
||||
FavStar.innerText = '★';
|
||||
FavStar.style.color = 'yellow';
|
||||
} else FavStar.innerText = '☆';
|
||||
FavStar.className = 'option';
|
||||
FavStar.onclick = function () {
|
||||
ToggleFavouriteSetting(config);
|
||||
saveFramework();
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
FavStar.onmouseover = function () {
|
||||
Game.tooltip.draw(this, escape(SimpleTooltipElements.FavouriteSettingPlaceholder.innerHTML));
|
||||
};
|
||||
FavStar.onmouseout = function () {
|
||||
Game.tooltip.hide();
|
||||
};
|
||||
FavStar.appendChild(document.createTextNode(' '));
|
||||
return FavStar;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function creates an option-object for the options page
|
||||
* @param {string} config The name of the option
|
||||
* @returns {object} div The option object
|
||||
*/
|
||||
export default function CreatePrefOption(config) {
|
||||
const div = document.createElement('div');
|
||||
div.className = 'listing';
|
||||
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FavouriteSettings === 1) {
|
||||
div.appendChild(CreateFavouriteStar(config));
|
||||
}
|
||||
if (settings[config].type === 'bool') {
|
||||
const a = document.createElement('a');
|
||||
if (
|
||||
settings[config].toggle &&
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] === 0
|
||||
) {
|
||||
a.className = 'option off';
|
||||
} else {
|
||||
a.className = 'option';
|
||||
}
|
||||
a.id = ConfigPrefix + config;
|
||||
a.onclick = function () {
|
||||
ToggleConfig(config);
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
a.textContent =
|
||||
settings[config].label[
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config]
|
||||
];
|
||||
div.appendChild(a);
|
||||
const label = document.createElement('label');
|
||||
label.textContent = settings[config].desc;
|
||||
label.style.lineHeight = '1.6';
|
||||
div.appendChild(label);
|
||||
return div;
|
||||
}
|
||||
if (settings[config].type === 'vol') {
|
||||
const volume = document.createElement('div');
|
||||
volume.className = 'sliderBox';
|
||||
const title = document.createElement('div');
|
||||
title.style.float = 'left';
|
||||
title.innerHTML = settings[config].desc;
|
||||
volume.appendChild(title);
|
||||
const percent = document.createElement('div');
|
||||
percent.id = `slider${config}right`;
|
||||
percent.style.float = 'right';
|
||||
percent.innerHTML = `${Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config]}%`;
|
||||
volume.appendChild(percent);
|
||||
const slider = document.createElement('input');
|
||||
slider.className = 'slider';
|
||||
slider.id = `slider${config}`;
|
||||
slider.style.clear = 'both';
|
||||
slider.type = 'range';
|
||||
slider.min = '0';
|
||||
slider.max = '100';
|
||||
slider.step = '1';
|
||||
slider.value = Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config];
|
||||
slider.oninput = function () {
|
||||
ToggleConfigVolume(config);
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
slider.onchange = function () {
|
||||
ToggleConfigVolume(config);
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
volume.appendChild(slider);
|
||||
div.appendChild(volume);
|
||||
const a = document.createElement('a');
|
||||
a.className = 'option';
|
||||
a.onclick = function () {
|
||||
PlaySound(
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[
|
||||
config.replace('Volume', 'SoundURL')
|
||||
],
|
||||
config.replace('Volume', 'Sound'),
|
||||
config,
|
||||
true,
|
||||
);
|
||||
};
|
||||
a.textContent = 'Test sound';
|
||||
div.appendChild(a);
|
||||
return div;
|
||||
}
|
||||
if (settings[config].type === 'url') {
|
||||
const span = document.createElement('span');
|
||||
span.className = 'option';
|
||||
span.textContent = `${settings[config].label} `;
|
||||
span.style.lineHeight = '1.6';
|
||||
div.appendChild(span);
|
||||
const input = document.createElement('input');
|
||||
input.id = ConfigPrefix + config;
|
||||
input.className = 'option';
|
||||
input.type = 'text';
|
||||
input.readOnly = true;
|
||||
input.setAttribute(
|
||||
'value',
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config],
|
||||
);
|
||||
input.style.width = '300px';
|
||||
div.appendChild(input);
|
||||
div.appendChild(document.createTextNode(' '));
|
||||
const inputPrompt = document.createElement('input');
|
||||
inputPrompt.id = `${ConfigPrefix + config}Prompt`;
|
||||
inputPrompt.className = 'option';
|
||||
inputPrompt.type = 'text';
|
||||
inputPrompt.setAttribute(
|
||||
'value',
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config],
|
||||
);
|
||||
const a = document.createElement('a');
|
||||
a.className = 'option';
|
||||
a.onclick = function () {
|
||||
CookieMonsterPrompt(inputPrompt.outerHTML, [
|
||||
[
|
||||
'Save',
|
||||
function () {
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] = l(
|
||||
`${ConfigPrefix}${config}Prompt`,
|
||||
).value;
|
||||
saveFramework();
|
||||
Game.ClosePrompt();
|
||||
Game.UpdateMenu();
|
||||
},
|
||||
],
|
||||
[
|
||||
'Cancel',
|
||||
function () {
|
||||
Game.ClosePrompt();
|
||||
},
|
||||
],
|
||||
]);
|
||||
};
|
||||
a.textContent = 'Edit';
|
||||
div.appendChild(a);
|
||||
const label = document.createElement('label');
|
||||
label.textContent = settings[config].desc;
|
||||
label.style.lineHeight = '1.6';
|
||||
div.appendChild(label);
|
||||
return div;
|
||||
}
|
||||
if (settings[config].type === 'colour') {
|
||||
const innerSpan = document.createElement('span');
|
||||
innerSpan.className = 'option';
|
||||
const input = document.createElement('input');
|
||||
input.id = config;
|
||||
input.style.width = '65px';
|
||||
input.setAttribute(
|
||||
'value',
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config],
|
||||
);
|
||||
innerSpan.appendChild(input);
|
||||
const change = function () {
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[this.targetElement.id] =
|
||||
this.toHEXString();
|
||||
UpdateColours();
|
||||
saveFramework();
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
// eslint-disable-next-line no-new
|
||||
new JsColor(input, { hash: true, position: 'right', onInput: change });
|
||||
const label = document.createElement('label');
|
||||
label.textContent = settings[config].desc;
|
||||
label.style.lineHeight = '1.6';
|
||||
innerSpan.appendChild(label);
|
||||
if (config.includes('Flash')) {
|
||||
const a = document.createElement('a');
|
||||
a.className = 'option';
|
||||
a.onclick = function () {
|
||||
Flash(3, config.replace('Colour', ''), true);
|
||||
};
|
||||
a.textContent = 'Test flash';
|
||||
innerSpan.appendChild(a);
|
||||
}
|
||||
div.appendChild(innerSpan);
|
||||
jscolor.init();
|
||||
return div;
|
||||
}
|
||||
if (settings[config].type === 'numscale') {
|
||||
const span = document.createElement('span');
|
||||
span.className = 'option';
|
||||
span.textContent = `${settings[config].label} `;
|
||||
span.style.lineHeight = '1.6';
|
||||
div.appendChild(span);
|
||||
const input = document.createElement('input');
|
||||
input.id = ConfigPrefix + config;
|
||||
input.className = 'option';
|
||||
input.type = 'number';
|
||||
input.value = Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config];
|
||||
input.min = settings[config].min;
|
||||
input.max = settings[config].max;
|
||||
input.oninput = function () {
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] = this.value;
|
||||
saveFramework();
|
||||
RefreshScale();
|
||||
Game.UpdateMenu();
|
||||
};
|
||||
div.appendChild(input);
|
||||
div.appendChild(document.createTextNode(' '));
|
||||
const label = document.createElement('label');
|
||||
label.textContent = settings[config].desc;
|
||||
label.style.lineHeight = '1.6';
|
||||
div.appendChild(label);
|
||||
return div;
|
||||
}
|
||||
return div;
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
import { ConfigGroups, ConfigGroupsNotification } from '../../../Data/Sectionheaders.ts';
|
||||
import settings from '../../../Data/settings';
|
||||
import { FavouriteSettings } from '../../VariablesAndData';
|
||||
import CreatePrefHeader from './CreateHeader';
|
||||
import CreatePrefOption from './CreateOption';
|
||||
|
||||
/**
|
||||
* This function adds the options/settings of CookieMonster to the options page
|
||||
* It is called by CM.Disp.AddMenu
|
||||
* @param {object} title On object that includes the title of the menu
|
||||
*/
|
||||
export default function AddMenuPref(title) {
|
||||
const frag = document.createDocumentFragment();
|
||||
frag.appendChild(title);
|
||||
|
||||
Object.keys(ConfigGroups).forEach((group) => {
|
||||
if (group === 'Favourite') {
|
||||
if (
|
||||
FavouriteSettings.length !== 0 &&
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.FavouriteSettings > 0
|
||||
) {
|
||||
frag.appendChild(CreatePrefHeader(group, ConfigGroups[group])); // (group, display-name of group)
|
||||
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[group])
|
||||
for (let index = 0; index < FavouriteSettings.length; index++) {
|
||||
frag.appendChild(CreatePrefOption(FavouriteSettings[index]));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
frag.appendChild(CreatePrefHeader(group, ConfigGroups[group])); // (group, display-name of group)
|
||||
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[group]) {
|
||||
// 0 is show, 1 is collapsed
|
||||
// Make sub-sections of Notification section
|
||||
if (group === 'Notification') {
|
||||
Object.keys(ConfigGroupsNotification).forEach((subGroup) => {
|
||||
const subGroupObject = CreatePrefHeader(subGroup, ConfigGroupsNotification[subGroup]); // (group, display-name of group)
|
||||
subGroupObject.style.fontSize = '15px';
|
||||
subGroupObject.style.opacity = '0.5';
|
||||
frag.appendChild(subGroupObject);
|
||||
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.headers[subGroup]) {
|
||||
Object.keys(settings).forEach((option) => {
|
||||
if (settings[option].group === subGroup) frag.appendChild(CreatePrefOption(option));
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Object.keys(settings).forEach((option) => {
|
||||
if (settings[option].group === group) frag.appendChild(CreatePrefOption(option));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
l('menu').childNodes[2].insertBefore(
|
||||
frag,
|
||||
l('menu').childNodes[2].childNodes[l('menu').childNodes[2].childNodes.length - 1],
|
||||
);
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
import { isInitializing } from '../../InitSaveLoad/Variables';
|
||||
|
||||
/**
|
||||
* 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.Options that is checked before creating the flash
|
||||
* @param {bool} forced Whether the sound should play regardless of settings, used to test the sound
|
||||
*/
|
||||
export default function Flash(mode, config, forced) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if (
|
||||
((Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[config] === 1 ||
|
||||
forced) &&
|
||||
mode === 3 &&
|
||||
isInitializing === false) ||
|
||||
mode === 1
|
||||
) {
|
||||
l('CMFlashScreen').style.backgroundColor =
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[`Colour${config}`];
|
||||
l('CMFlashScreen').style.opacity = '0.5';
|
||||
if (mode === 3) {
|
||||
l('CMFlashScreen').style.display = 'inline';
|
||||
setTimeout(() => {
|
||||
Flash(2, config, true);
|
||||
}, 1000 / Game.fps);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
Flash(0, config, true);
|
||||
}, 1000 / Game.fps);
|
||||
}
|
||||
} else if (mode === 2) {
|
||||
l('CMFlashScreen').style.opacity = '1';
|
||||
setTimeout(() => {
|
||||
Flash(1, config, true);
|
||||
}, 1000 / Game.fps);
|
||||
} else if (mode === 0) l('CMFlashScreen').style.display = 'none';
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
import { isInitializing } from '../../InitSaveLoad/Variables';
|
||||
|
||||
/**
|
||||
* 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.Options 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
|
||||
*/
|
||||
export default function CreateNotification(notifyConfig, title, message) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if (
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[notifyConfig] === 1 &&
|
||||
document.visibilityState === 'hidden' &&
|
||||
isInitializing === false
|
||||
) {
|
||||
const CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
|
||||
// eslint-disable-next-line no-new
|
||||
new Notification(title, { body: message, badge: CookieIcon });
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { isInitializing } from '../../InitSaveLoad/Variables';
|
||||
|
||||
/**
|
||||
* 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.Options.GCSoundURL)
|
||||
* @param {string} sndConfig The setting in CM.Options that is checked before creating the sound
|
||||
* @param {string} volConfig The setting in CM.Options that is checked to determine volume
|
||||
* @param {bool} forced Whether the sound should play regardless of settings, used to test the sound
|
||||
*/
|
||||
export default function PlaySound(url, sndConfig, volConfig, forced) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if (
|
||||
(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[sndConfig] === 1 ||
|
||||
forced) &&
|
||||
isInitializing === false
|
||||
) {
|
||||
// eslint-disable-next-line new-cap
|
||||
const sound = new Audio(url);
|
||||
if (Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.GeneralSound)
|
||||
sound.volume =
|
||||
(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[volConfig] / 100) *
|
||||
(Game.volume / 100);
|
||||
else
|
||||
sound.volume =
|
||||
Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings[volConfig] / 100;
|
||||
sound.play();
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
/** Variable that shows if Cookie Moonster is initzializing */
|
||||
export let isInitializing = false; // eslint-disable-line prefer-const
|
||||
export let test;
|
||||
@@ -1,17 +0,0 @@
|
||||
import { beforeEach, describe, it } from 'mocha';
|
||||
import { assert } from 'chai';
|
||||
|
||||
import ToggleFavouriteSetting from '../../../src/Config/Toggles/ToggleFavourites';
|
||||
import { FavouriteSettings } from '../../../src/Disp/VariablesAndData';
|
||||
|
||||
describe('ToggleFavouriteSetting', () => {
|
||||
beforeEach(() => {
|
||||
global.domids = {};
|
||||
});
|
||||
// TODO: Can't write test for checking existing config due to Babel/Typescript problem
|
||||
it('New config', () => {
|
||||
FavouriteSettings.push('TestConfig');
|
||||
ToggleFavouriteSetting('TestConfig2');
|
||||
assert.deepEqual(FavouriteSettings, ['TestConfig', 'TestConfig2']);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user