Skip to content

Commit

Permalink
Merge pull request #730 from DanielNoord/functions
Browse files Browse the repository at this point in the history
Functions
  • Loading branch information
DanielNoord authored Mar 28, 2021
2 parents 212a358 + 972d472 commit adb020d
Show file tree
Hide file tree
Showing 24 changed files with 212 additions and 145 deletions.
2 changes: 1 addition & 1 deletion CookieMonster.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonster.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/CookieMonster.js.map

Large diffs are not rendered by default.

34 changes: 10 additions & 24 deletions src/Config/SaveLoadReload/SaveLoadReloadSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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 (
Expand All @@ -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();
Expand All @@ -94,4 +78,6 @@ export function LoadConfig(settings) {
// Default values
LoadConfig(ConfigDefault);
}
Game.UpdateMenu();
UpdateColours();
}
2 changes: 1 addition & 1 deletion src/Config/Toggles/ToggleWrinklerButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CMOptions } from '../VariablesAndData';
* It is called by changes in CM.Options.WrinklerButtons
*/
export default function ToggleWrinklerButtons() {
if (CMOptions.WrinklerButtons) {
if (CMOptions.WrinklerButtons && Game.elderWrath) {
l('PopAllNormalWrinklerButton').style.display = '';
l('PopFattestWrinklerButton').style.display = '';
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/Data/SettingClasses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
100 changes: 77 additions & 23 deletions src/Data/SettingsData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
'Standard colour is green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
Yellow:
'Standard colour is yellow. Used to show buildings within the top 10 of PP, for Frenzy bar, and for various labels',
Orange:
'Standard colour is orange. Used to show buildings within the top 20 of PP, for Next Reindeer bar, and for various labels',
Red:
'Standard colour is Red. Used to show buildings within the top 30 of PP, for Clot bar, and for various labels',
Purple:
'Standard colour is purple. Used to show buildings outside of the top 30 of PP, for Next Cookie bar, and for various labels',
Gray:
'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();
},
'Standard colour is blue. Used to show upgrades better than best PP building, for Click Frenzy bar, and for various labels',
),
ColourGreen: new SettingColours(
'colour',
'Colours',
'Standard colour is green. Used to show best PP building, for Blood Frenzy bar, and for various labels',
),
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',
),
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',
),
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',
),
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',
),
ColourGray: new SettingColours(
'colour',
'Colours',
'Standard colour is gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar',
),
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
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
27 changes: 16 additions & 11 deletions src/Data/SettingsDefault.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
14 changes: 8 additions & 6 deletions src/Disp/BuildingsUpgrades/Buildings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) => {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/Disp/BuildingsUpgrades/Upgrades.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ColourOrange,
ColourPurple,
ColourRed,
Colours,
ColoursOrdering,
ColourYellow,
} from '../VariablesAndData';

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit adb020d

Please sign in to comment.