Complete overhaul of code structure and relevant files (#639)
This commit is contained in:
25
src/Disp/Notifications/Flash.js
Normal file
25
src/Disp/Notifications/Flash.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
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
|
||||
*/
|
||||
export default function Flash(mode, config) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if ((CMOptions[config] === 1 && mode === 3 && isInitializing === false) || mode === 1) {
|
||||
l('CMWhiteScreen').style.opacity = '0.5';
|
||||
if (mode === 3) {
|
||||
l('CMWhiteScreen').style.display = 'inline';
|
||||
setTimeout(function () { Flash(2, config); }, 1000 / Game.fps);
|
||||
} else {
|
||||
setTimeout(function () { Flash(0, config); }, 1000 / Game.fps);
|
||||
}
|
||||
} else if (mode === 2) {
|
||||
l('CMWhiteScreen').style.opacity = '1';
|
||||
setTimeout(function () { Flash(1, config); }, 1000 / Game.fps);
|
||||
} else if (mode === 0) l('CMWhiteScreen').style.display = 'none';
|
||||
}
|
||||
19
src/Disp/Notifications/Notification.js
Normal file
19
src/Disp/Notifications/Notification.js
Normal file
@@ -0,0 +1,19 @@
|
||||
/** Functions related to the flashes/sound/notifications */
|
||||
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
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 Notification(notifyConfig, title, message) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if (CMOptions[notifyConfig] === 1 && document.visibilityState === 'hidden' && isInitializing === false) {
|
||||
const CookieIcon = 'https://orteil.dashnet.org/cookieclicker/favicon.ico';
|
||||
new Notification(title, { body: message, badge: CookieIcon });
|
||||
}
|
||||
}
|
||||
20
src/Disp/Notifications/Sound.js
Normal file
20
src/Disp/Notifications/Sound.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import { CMOptions } from '../../Config/VariablesAndData';
|
||||
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
|
||||
*/
|
||||
export default function PlaySound(url, sndConfig, volConfig) {
|
||||
// The arguments check makes the sound not play upon initialization of the mod
|
||||
if (CMOptions[sndConfig] === 1 && isInitializing === false) {
|
||||
// eslint-disable-next-line new-cap
|
||||
const sound = new realAudio(url);
|
||||
if (CMOptions.GeneralSound) sound.volume = (CMOptions[volConfig] / 100) * (Game.volume / 100);
|
||||
else sound.volume = (CMOptions[volConfig] / 100);
|
||||
sound.play();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user