New colour settings, changeable flash colour #728

This commit is contained in:
Daniël van Noord
2021-03-28 10:55:10 +02:00
parent fe8749e7b2
commit 972d4723ed
21 changed files with 183 additions and 126 deletions

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

@@ -3,6 +3,7 @@ import ConfigData from '../../Data/SettingsData';
import { CMOptions } from '../VariablesAndData';
import save from '../../InitSaveLoad/save';
import CMLoop from '../../Main/Loop';
import UpdateColours from '../../Disp/HelperFunctions/UpdateColours';
/** Functions related to saving, loading and restoring all settings */
@@ -41,25 +42,19 @@ export function LoadConfig(settings) {
if (settings !== undefined) {
CMOptions = settings;
if (typeof CMOptions.Colors !== 'undefined') {
delete CMOptions.Colors;
}
if (typeof CMOptions.Colours !== 'undefined') {
delete CMOptions.Colours;
}
// Check values
let mod = false;
Object.keys(ConfigDefault).forEach((i) => {
if (typeof CMOptions[i] === 'undefined') {
mod = true;
CMOptions[i] = ConfigDefault[i];
} else if (i !== 'Header' && i !== 'Colors') {
if (i.indexOf('SoundURL') === -1) {
if (
!(CMOptions[i] > -1 && CMOptions[i] < ConfigData[i].label.length)
) {
mod = true;
CMOptions[i] = ConfigDefault[i];
}
} else if (typeof CMOptions[i] !== 'string') {
// Sound URLs
mod = true;
CMOptions[i] = ConfigDefault[i];
}
} else if (i === 'Header') {
Object.keys(ConfigDefault.Header).forEach((j) => {
if (
@@ -70,17 +65,6 @@ export function LoadConfig(settings) {
CMOptions[i][j] = ConfigDefault[i][j];
}
});
} else {
// Colors
Object.keys(ConfigDefault.Colors).forEach((j) => {
if (
typeof CMOptions[i][j] === 'undefined' ||
typeof CMOptions[i][j] !== 'string'
) {
mod = true;
CMOptions[i][j] = ConfigDefault[i][j];
}
});
}
});
if (mod) SaveConfig();
@@ -94,4 +78,6 @@ export function LoadConfig(settings) {
// Default values
LoadConfig(ConfigDefault);
}
Game.UpdateMenu();
UpdateColours();
}

View File

@@ -23,10 +23,9 @@ export class SettingStandard extends Setting {
}
/** The colour picker setting class */
export class SettingColours extends Setting {
constructor(type, group, desc, func) {
constructor(type, group, desc) {
super(type, group);
this.desc = desc;
this.func = func;
}
}

View File

@@ -13,7 +13,6 @@ import { CMOptions } from '../Config/VariablesAndData';
import UpdateBuildings from '../Disp/BuildingsUpgrades/Buildings';
import UpdateUpgrades from '../Disp/BuildingsUpgrades/Upgrades';
import RefreshScale from '../Disp/HelperFunctions/RefreshScale';
import UpdateColours from '../Disp/HelperFunctions/UpdateColours';
import { UpdateFavicon } from '../Disp/TabTitle/FavIcon';
import { SimDoSims } from '../Sim/VariablesAndData';
import {
@@ -193,30 +192,50 @@ const Config = {
0,
Infinity,
),
Colours: new SettingColours(
ColourBlue: new SettingColours(
'colour',
'Colours',
{
Blue:
'Standard colour is blue. Used to show upgrades better than best PP building, for Click Frenzy bar, and for various labels',
Green:
),
ColourGreen: new SettingColours(
'colour',
'Colours',
'Standard colour is green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
Yellow:
),
ColourYellow: new SettingColours(
'colour',
'Colours',
'Standard colour is yellow. Used to show buildings within the top 10 of PP, for Frenzy bar, and for various labels',
Orange:
),
ColourOrange: new SettingColours(
'colour',
'Colours',
'Standard colour is orange. Used to show buildings within the top 20 of PP, for Next Reindeer bar, and for various labels',
Red:
),
ColourRed: new SettingColours(
'colour',
'Colours',
'Standard colour is Red. Used to show buildings within the top 30 of PP, for Clot bar, and for various labels',
Purple:
),
ColourPurple: new SettingColours(
'colour',
'Colours',
'Standard colour is purple. Used to show buildings outside of the top 30 of PP, for Next Cookie bar, and for various labels',
Gray:
),
ColourGray: new SettingColours(
'colour',
'Colours',
'Standard colour is gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
Pink: 'Standard colour is pink. Used for Dragonflight bar',
Brown: 'Standard colour is brown. Used for Dragon Harvest bar',
},
function () {
UpdateColours();
},
),
ColourPink: new SettingColours(
'colour',
'Colours',
'Standard colour is pink. Used for Dragonflight bar',
),
ColourBrown: new SettingColours(
'colour',
'Colours',
'Standard colour is brown. Used for Dragon Harvest bar',
),
// BarsDisplay
@@ -561,6 +580,11 @@ const Config = {
'Flash screen on golden cookie',
true,
),
ColourGCFlash: new SettingColours(
'colour',
'NotificationGC',
'The colour of the GC flash, standard colour is white',
),
GCSound: new SettingStandard(
'bool',
'NotificationGC',
@@ -592,6 +616,11 @@ const Config = {
'Flash screen on fortune cookie spawn',
true,
),
ColourFortuneFlash: new SettingColours(
'colour',
'NotificationFC',
'The colour of the fortune flash, standard colour is white',
),
FortuneSound: new SettingStandard(
'bool',
'NotificationFC',
@@ -623,6 +652,11 @@ const Config = {
'Flash screen on season popup',
true,
),
ColourSeaFlash: new SettingColours(
'colour',
'NotificationSea',
'The colour of the season popup flash, standard colour is white',
),
SeaSound: new SettingStandard(
'bool',
'NotificationSea',
@@ -644,6 +678,11 @@ const Config = {
'Flash screen on garden tick',
true,
),
ColourGardFlash: new SettingColours(
'colour',
'NotificationGard',
'The colour of the garden flash, standard colour is white',
),
GardSound: new SettingStandard(
'bool',
'NotificationGard',
@@ -675,6 +714,11 @@ const Config = {
'Flash screen when magic reaches maximum',
true,
),
ColourMagicFlash: new SettingColours(
'colour',
'NotificationMagi',
'The colour of the magic flash, standard colour is white',
),
MagicSound: new SettingStandard(
'bool',
'NotificationMagi',
@@ -706,6 +750,11 @@ const Config = {
'Flash screen when a wrinkler appears',
true,
),
ColourWrinklerFlash: new SettingColours(
'colour',
'NotificationWrink',
'The colour of the wrinkler flash, standard colour is white',
),
WrinklerSound: new SettingStandard(
'bool',
'NotificationWrink',
@@ -737,6 +786,11 @@ const Config = {
'Flash screen when the maximum amount of Wrinklers has appeared',
true,
),
ColourWrinklerMaxFlash: new SettingColours(
'colour',
'NotificationWrinkMax',
'The colour of the maximum wrinkler flash, standard colour is white',
),
WrinklerMaxSound: new SettingStandard(
'bool',
'NotificationWrinkMax',

View File

@@ -16,17 +16,15 @@ const ConfigDefault = {
PPExcludeTop: 0,
PPRigidelMode: 0,
PPSecondsLowerLimit: 0,
Colours: {
Blue: '#4bb8f0',
Green: '#00ff00',
Yellow: '#ffff00',
Orange: '#ff7f00',
Red: '#ff0000',
Purple: '#ff00ff',
Gray: '#b3b3b3',
Pink: '#ff1493',
Brown: '#8b4513',
},
ColourBlue: '#4bb8f0',
ColourGreen: '#00ff00',
ColourYellow: '#ffff00',
ColourOrange: '#ff7f00',
ColourRed: '#ff0000',
ColourPurple: '#ff00ff',
ColourGray: '#b3b3b3',
ColourPink: '#ff1493',
ColourBrown: '#8b4513',
BotBar: 1,
TimerBar: 1,
TimerBarPos: 0,
@@ -66,39 +64,46 @@ const ConfigDefault = {
GeneralSound: 1,
GCNotification: 0,
GCFlash: 1,
ColourGCFlash: '#ffffff',
GCSound: 1,
GCVolume: 100,
GCSoundURL: 'https://freesound.org/data/previews/66/66717_931655-lq.mp3',
FortuneNotification: 0,
FortuneFlash: 1,
ColourFortuneFlash: '#ffffff',
FortuneSound: 1,
FortuneVolume: 100,
FortuneSoundURL:
'https://freesound.org/data/previews/174/174027_3242494-lq.mp3',
SeaNotification: 0,
SeaFlash: 1,
ColourSeaFlash: '#ffffff',
SeaSound: 1,
SeaVolume: 100,
SeaSoundURL:
'https://www.freesound.org/data/previews/121/121099_2193266-lq.mp3',
GardFlash: 1,
ColourGardFlash: '#ffffff',
GardSound: 1,
GardVolume: 100,
GardSoundURL: 'https://freesound.org/data/previews/103/103046_861714-lq.mp3',
MagicNotification: 0,
MagicFlash: 1,
ColourMagicFlash: '#ffffff',
MagicSound: 1,
MagicVolume: 100,
MagicSoundURL:
'https://freesound.org/data/previews/221/221683_1015240-lq.mp3',
WrinklerNotification: 0,
WrinklerFlash: 1,
ColourWrinklerFlash: '#ffffff',
WrinklerSound: 1,
WrinklerVolume: 100,
WrinklerSoundURL:
'https://freesound.org/data/previews/124/124186_8043-lq.mp3',
WrinklerMaxNotification: 0,
WrinklerMaxFlash: 1,
ColourWrinklerMaxFlash: '#ffffff',
WrinklerMaxSound: 1,
WrinklerMaxVolume: 100,
WrinklerMaxSoundURL:

View File

@@ -7,7 +7,7 @@ import {
import { CMOptions } from '../../Config/VariablesAndData';
import BuildingSell from '../../Sim/SimulationEvents/SellBuilding';
import { Beautify } from '../BeautifyAndFormatting/BeautifyFormatting';
import { Colours, LastTargetBuildings } from '../VariablesAndData';
import { ColoursOrdering, LastTargetBuildings } from '../VariablesAndData';
/**
* Section: Functions related to right column of the screen (buildings/upgrades)
@@ -33,7 +33,7 @@ export default function UpdateBuildings() {
if (CMOptions.BuildColour === 1) {
Object.keys(target).forEach((i) => {
l(`productPrice${Game.Objects[i].id}`).style.color =
CMOptions.Colours[target[i].color];
CMOptions[`Colour${target[i].color}`];
});
} else {
Object.keys(Game.Objects).forEach((i) => {
@@ -72,9 +72,10 @@ export default function UpdateBuildings() {
});
arr.sort(function (a, b) {
return Colours.indexOf(a.color) > Colours.indexOf(b.color)
return ColoursOrdering.indexOf(a.color) >
ColoursOrdering.indexOf(b.color)
? 1
: Colours.indexOf(a.color) < Colours.indexOf(b.color)
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color)
? -1
: a.pp < b.pp
? -1
@@ -89,9 +90,10 @@ export default function UpdateBuildings() {
});
arr.sort(function (a, b) {
return Colours.indexOf(a.color) > Colours.indexOf(b.color)
return ColoursOrdering.indexOf(a.color) >
ColoursOrdering.indexOf(b.color)
? 1
: Colours.indexOf(a.color) < Colours.indexOf(b.color)
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color)
? -1
: a.pp < b.pp
? -1

View File

@@ -9,7 +9,7 @@ import {
ColourOrange,
ColourPurple,
ColourRed,
Colours,
ColoursOrdering,
ColourYellow,
} from '../VariablesAndData';
@@ -81,9 +81,9 @@ export default function UpdateUpgrades() {
if (CMOptions.SortUpgrades) {
arr.sort(function (a, b) {
return Colours.indexOf(a.color) > Colours.indexOf(b.color)
return ColoursOrdering.indexOf(a.color) > ColoursOrdering.indexOf(b.color)
? 1
: Colours.indexOf(a.color) < Colours.indexOf(b.color)
: ColoursOrdering.indexOf(a.color) < ColoursOrdering.indexOf(b.color)
? -1
: a.pp < b.pp
? -1

View File

@@ -3,7 +3,7 @@ import UpdateBuildings from '../BuildingsUpgrades/Buildings';
import {
ColourBackPre,
ColourBorderPre,
Colours,
ColoursOrdering,
ColourTextPre,
} from '../VariablesAndData';
@@ -13,19 +13,19 @@ import {
*/
export default function UpdateColours() {
let str = '';
for (let i = 0; i < Colours.length; i++) {
str += `.${ColourTextPre}${Colours[i]} { color: ${
CMOptions.Colours[Colours[i]]
for (let i = 0; i < ColoursOrdering.length; i++) {
str += `.${ColourTextPre}${ColoursOrdering[i]} { color: ${
CMOptions[`Colour${ColoursOrdering[i]}`]
}; }\n`;
}
for (let i = 0; i < Colours.length; i++) {
str += `.${ColourBackPre}${Colours[i]} { background-color: ${
CMOptions.Colours[Colours[i]]
for (let i = 0; i < ColoursOrdering.length; i++) {
str += `.${ColourBackPre}${ColoursOrdering[i]} { background-color: ${
CMOptions[`Colour${ColoursOrdering[i]}`]
}; }\n`;
}
for (let i = 0; i < Colours.length; i++) {
str += `.${ColourBorderPre}${Colours[i]} { border: 1px solid ${
CMOptions.Colours[Colours[i]]
for (let i = 0; i < ColoursOrdering.length; i++) {
str += `.${ColourBorderPre}${ColoursOrdering[i]} { border: 1px solid ${
CMOptions[`Colour${ColoursOrdering[i]}`]
}; }\n`;
}
l('CMCSS').textContent = str;

View File

@@ -1,9 +1,9 @@
/**
* This function creates a white square over the full screen and appends it to l('wrapper')
*/
export default function CreateWhiteScreen() {
export default function CreateFlashScreen() {
const WhiteScreen = document.createElement('div');
WhiteScreen.id = 'CMWhiteScreen';
WhiteScreen.id = 'CMFlashScreen';
WhiteScreen.style.width = '100%';
WhiteScreen.style.height = '100%';
WhiteScreen.style.backgroundColor = 'white';

View File

@@ -20,8 +20,8 @@ import Config from '../../Data/SettingsData';
import ConfigDefault from '../../Data/SettingsDefault';
import RefreshScale from '../HelperFunctions/RefreshScale';
import UpdateColours from '../HelperFunctions/UpdateColours';
import Flash from '../Notifications/Flash';
import PlaySound from '../Notifications/Sound';
import { Colours } from '../VariablesAndData';
/**
* This function creates a header-object for the options page
@@ -167,18 +167,17 @@ function CreatePrefOption(config) {
div.appendChild(label);
return div;
}
if (Config[config].type === 'color') {
if (Config[config].type === 'colour') {
div.className = '';
for (let i = 0; i < Colours.length; i++) {
const innerDiv = document.createElement('div');
innerDiv.className = 'listing';
const input = document.createElement('input');
input.id = Colours[i];
input.id = config;
input.style.width = '65px';
input.setAttribute('value', CMOptions.Colours[Colours[i]]);
input.setAttribute('value', CMOptions[config]);
innerDiv.appendChild(input);
const change = function () {
CMOptions.Colours[this.targetElement.id] = this.toHEXString();
CMOptions[this.targetElement.id] = this.toHEXString();
UpdateColours();
SaveConfig();
Game.UpdateMenu();
@@ -186,10 +185,18 @@ function CreatePrefOption(config) {
// eslint-disable-next-line no-new
new JsColor(input, { hash: true, position: 'right', onInput: change });
const label = document.createElement('label');
label.textContent = Config.Colours.desc[Colours[i]];
label.textContent = Config[config].desc;
innerDiv.appendChild(label);
div.appendChild(innerDiv);
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';
innerDiv.appendChild(a);
}
div.appendChild(innerDiv);
jscolor.init();
return div;
}

View File

@@ -7,28 +7,32 @@ import { isInitializing } from '../../InitSaveLoad/Variables';
* @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) {
export default function Flash(mode, config, forced) {
// The arguments check makes the sound not play upon initialization of the mod
if (
(CMOptions[config] === 1 && mode === 3 && isInitializing === false) ||
((CMOptions[config] === 1 || forced) &&
mode === 3 &&
isInitializing === false) ||
mode === 1
) {
l('CMWhiteScreen').style.opacity = '0.5';
l('CMFlashScreen').style.backgroundColor = CMOptions[`Colour${config}`];
l('CMFlashScreen').style.opacity = '0.5';
if (mode === 3) {
l('CMWhiteScreen').style.display = 'inline';
l('CMFlashScreen').style.display = 'inline';
setTimeout(function () {
Flash(2, config);
Flash(2, config, true);
}, 1000 / Game.fps);
} else {
setTimeout(function () {
Flash(0, config);
Flash(0, config, true);
}, 1000 / Game.fps);
}
} else if (mode === 2) {
l('CMWhiteScreen').style.opacity = '1';
l('CMFlashScreen').style.opacity = '1';
setTimeout(function () {
Flash(1, config);
Flash(1, config, true);
}, 1000 / Game.fps);
} else if (mode === 0) l('CMWhiteScreen').style.display = 'none';
} else if (mode === 0) l('CMFlashScreen').style.display = 'none';
}

View File

@@ -23,7 +23,7 @@ export const ColourPurple = 'Purple';
export const ColourGray = 'Gray';
export const ColourPink = 'Pink';
export const ColourBrown = 'Brown';
export const Colours = [
export const ColoursOrdering = [
ColourGray,
ColourBlue,
ColourGreen,

View File

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

View File

@@ -49,7 +49,7 @@ export default function CheckGoldenCookie() {
LastGoldenCookieState = Game.shimmerTypes.golden.n;
if (LastGoldenCookieState) {
if (LastSpawnedGoldenCookieState < CurrSpawnedGoldenCookieState) {
Flash(3, 'GCFlash');
Flash(3, 'GCFlash', false);
PlaySound(CMOptions.GCSoundURL, 'GCSound', 'GCVolume', false);
CreateNotification(
'GCNotification',

View File

@@ -17,7 +17,7 @@ export default function CheckMagicMeter() {
if (minigame.magic < minigame.magicM) LastMagicBarFull = false;
else if (!LastMagicBarFull) {
LastMagicBarFull = true;
Flash(3, 'MagicFlash');
Flash(3, 'MagicFlash', false);
PlaySound(CMOptions.MagicSoundURL, 'MagicSound', 'MagicVolume', false);
CreateNotification(
'MagicNotification',

View File

@@ -18,7 +18,7 @@ export default function CheckSeasonPopup() {
CacheSeasonPopShimmer = Game.shimmers[i];
}
});
Flash(3, 'SeaFlash');
Flash(3, 'SeaFlash', false);
PlaySound(CMOptions.SeaSoundURL, 'SeaSound', 'SeaVolume', false);
CreateNotification(
'SeaNotification',

View File

@@ -16,7 +16,7 @@ export default function CheckTickerFortune() {
LastTickerFortuneState =
Game.TickerEffect && Game.TickerEffect.type === 'fortune';
if (LastTickerFortuneState) {
Flash(3, 'FortuneFlash');
Flash(3, 'FortuneFlash', false);
PlaySound(
CMOptions.FortuneSoundURL,
'FortuneSound',

View File

@@ -20,9 +20,9 @@ export default function CheckWrinklerCount() {
CurrentWrinklers === Game.getWrinklersMax() &&
CMOptions.WrinklerMaxFlash
) {
Flash(3, 'WrinklerMaxFlash');
Flash(3, 'WrinklerMaxFlash', false);
} else {
Flash(3, 'WrinklerFlash');
Flash(3, 'WrinklerFlash', false);
}
if (
CurrentWrinklers === Game.getWrinklersMax() &&

View File

@@ -4,13 +4,14 @@ import { CacheStatsCookies } from '../Cache/Stats/Stats';
import { LoadConfig } from '../Config/SaveLoadReload/SaveLoadReloadSettings';
import { VersionMajor, VersionMinor } from '../Data/Moddata';
import CreateUpgradeBar from '../Disp/BuildingsUpgrades/UpgradeBar';
import UpdateColours from '../Disp/HelperFunctions/UpdateColours';
import { CreateBotBar } from '../Disp/InfoBars/BottomBar';
import { CreateTimerBar } from '../Disp/InfoBars/TimerBar';
import CreateSectionHideButtons from '../Disp/Initialization/CreateSectionHideButtons';
import CreateWrinklerButtons from '../Disp/Initialization/CreateWrinklerButton';
import CreateCssArea from '../Disp/Initialization/CssArea';
import UpdateBuildingUpgradeStyle from '../Disp/Initialization/UpdateBuildingUpgradeStyle';
import CreateWhiteScreen from '../Disp/Initialization/WhiteScreen';
import CreateFlashScreen from '../Disp/Initialization/FlashScreen';
import { CreateFavicon } from '../Disp/TabTitle/FavIcon';
import { CreateSimpleTooltip } from '../Disp/Tooltips/Tooltip';
import { CMLastAscendState, TooltipText } from '../Disp/VariablesAndData';
@@ -37,7 +38,7 @@ export default function InitializeCookieMonster() {
CreateBotBar();
CreateTimerBar();
CreateUpgradeBar();
CreateWhiteScreen();
CreateFlashScreen();
CreateSectionHideButtons();
CreateFavicon();
Object.keys(TooltipText).forEach((i) => {
@@ -58,8 +59,7 @@ export default function InitializeCookieMonster() {
ReplaceNativeGrimoire();
Game.CalculateGains();
LoadConfig(); // Must be after all things are created!
Game.UpdateMenu();
LoadConfig();
CMLastAscendState = Game.OnAscend;
if (Game.prefs.popups)