Merge pull request #685 from DanielNoord/soundtest

Test button for sounds and new Audio() code #630
This commit is contained in:
Daniël van Noord
2021-03-16 13:29:10 +01:00
committed by GitHub
12 changed files with 32 additions and 12 deletions

View File

@@ -8,7 +8,6 @@ module.exports = {
l: 'readonly', l: 'readonly',
b64_to_utf8: 'readonly', b64_to_utf8: 'readonly',
utf8_to_b64: 'readonly', utf8_to_b64: 'readonly',
realAudio: 'readonly',
BeautifyAll: 'readonly', BeautifyAll: 'readonly',
}, },
extends: ['airbnb-base', 'plugin:prettier/recommended'], extends: ['airbnb-base', 'plugin:prettier/recommended'],

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -20,6 +20,7 @@ import Config from '../../Data/SettingsData';
import ConfigDefault from '../../Data/SettingsDefault'; import ConfigDefault from '../../Data/SettingsDefault';
import RefreshScale from '../HelperFunctions/RefreshScale'; import RefreshScale from '../HelperFunctions/RefreshScale';
import UpdateColors from '../HelperFunctions/UpdateColors'; import UpdateColors from '../HelperFunctions/UpdateColors';
import PlaySound from '../Notifications/Sound';
import { Colors } from '../VariablesAndData'; import { Colors } from '../VariablesAndData';
/** /**
@@ -110,6 +111,18 @@ function CreatePrefOption(config) {
}; };
volume.appendChild(slider); volume.appendChild(slider);
div.appendChild(volume); div.appendChild(volume);
const a = document.createElement('a');
a.className = 'option';
a.onclick = function () {
PlaySound(
CMOptions[config.replace('Volume', 'SoundURL')],
config.replace('Volume', 'Sound'),
config,
true,
);
};
a.textContent = 'Test sound';
div.appendChild(a);
return div; return div;
} }
if (Config[config].type === 'url') { if (Config[config].type === 'url') {

View File

@@ -7,12 +7,13 @@ import { isInitializing } from '../../InitSaveLoad/Variables';
* @param {variable} url A variable that gives the url for the sound (e.g., CM.Options.GCSoundURL) * @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} 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 {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) { export default function PlaySound(url, sndConfig, volConfig, forced) {
// The arguments check makes the sound not play upon initialization of the mod // The arguments check makes the sound not play upon initialization of the mod
if (CMOptions[sndConfig] === 1 && isInitializing === false) { if ((CMOptions[sndConfig] === 1 || forced) && isInitializing === false) {
// eslint-disable-next-line new-cap // eslint-disable-next-line new-cap
const sound = new realAudio(url); const sound = new Audio(url);
if (CMOptions.GeneralSound) if (CMOptions.GeneralSound)
sound.volume = (CMOptions[volConfig] / 100) * (Game.volume / 100); sound.volume = (CMOptions[volConfig] / 100) * (Game.volume / 100);
else sound.volume = CMOptions[volConfig] / 100; else sound.volume = CMOptions[volConfig] / 100;

View File

@@ -13,7 +13,7 @@ export default function CheckGardenTick() {
) { ) {
if (LastGardenNextStep !== 0 && LastGardenNextStep < Date.now()) { if (LastGardenNextStep !== 0 && LastGardenNextStep < Date.now()) {
Flash(3, 'GardFlash'); Flash(3, 'GardFlash');
PlaySound(CMOptions.GardSoundURL, 'GardSound', 'GardVolume'); PlaySound(CMOptions.GardSoundURL, 'GardSound', 'GardVolume', false);
} }
LastGardenNextStep = Game.Objects.Farm.minigame.nextStep; LastGardenNextStep = Game.Objects.Farm.minigame.nextStep;
} }

View File

@@ -50,7 +50,7 @@ export default function CheckGoldenCookie() {
if (LastGoldenCookieState) { if (LastGoldenCookieState) {
if (LastSpawnedGoldenCookieState < CurrSpawnedGoldenCookieState) { if (LastSpawnedGoldenCookieState < CurrSpawnedGoldenCookieState) {
Flash(3, 'GCFlash'); Flash(3, 'GCFlash');
PlaySound(CMOptions.GCSoundURL, 'GCSound', 'GCVolume'); PlaySound(CMOptions.GCSoundURL, 'GCSound', 'GCVolume', false);
CreateNotification( CreateNotification(
'GCNotification', 'GCNotification',
'Golden Cookie Spawned', 'Golden Cookie Spawned',

View File

@@ -18,7 +18,7 @@ export default function CheckMagicMeter() {
else if (!LastMagicBarFull) { else if (!LastMagicBarFull) {
LastMagicBarFull = true; LastMagicBarFull = true;
Flash(3, 'MagicFlash'); Flash(3, 'MagicFlash');
PlaySound(CMOptions.MagicSoundURL, 'MagicSound', 'MagicVolume'); PlaySound(CMOptions.MagicSoundURL, 'MagicSound', 'MagicVolume', false);
CreateNotification( CreateNotification(
'MagicNotification', 'MagicNotification',
'Magic Meter full', 'Magic Meter full',

View File

@@ -19,7 +19,7 @@ export default function CheckSeasonPopup() {
} }
}); });
Flash(3, 'SeaFlash'); Flash(3, 'SeaFlash');
PlaySound(CMOptions.SeaSoundURL, 'SeaSound', 'SeaVolume'); PlaySound(CMOptions.SeaSoundURL, 'SeaSound', 'SeaVolume', false);
CreateNotification( CreateNotification(
'SeaNotification', 'SeaNotification',
'Reindeer sighted!', 'Reindeer sighted!',

View File

@@ -17,7 +17,12 @@ export default function CheckTickerFortune() {
Game.TickerEffect && Game.TickerEffect.type === 'fortune'; Game.TickerEffect && Game.TickerEffect.type === 'fortune';
if (LastTickerFortuneState) { if (LastTickerFortuneState) {
Flash(3, 'FortuneFlash'); Flash(3, 'FortuneFlash');
PlaySound(CMOptions.FortuneSoundURL, 'FortuneSound', 'FortuneVolume'); PlaySound(
CMOptions.FortuneSoundURL,
'FortuneSound',
'FortuneVolume',
false,
);
CreateNotification( CreateNotification(
'FortuneNotification', 'FortuneNotification',
'Fortune Cookie found', 'Fortune Cookie found',

View File

@@ -32,12 +32,14 @@ export default function CheckWrinklerCount() {
CMOptions.WrinklerMaxSoundURL, CMOptions.WrinklerMaxSoundURL,
'WrinklerMaxSound', 'WrinklerMaxSound',
'WrinklerMaxVolume', 'WrinklerMaxVolume',
false,
); );
} else { } else {
PlaySound( PlaySound(
CMOptions.WrinklerSoundURL, CMOptions.WrinklerSoundURL,
'WrinklerSound', 'WrinklerSound',
'WrinklerVolume', 'WrinklerVolume',
false,
); );
} }
if ( if (