Skip to content

Commit 4d445c6

Browse files
committed
Added the option to change sounds played when a Golden Cookie/Season Special spawns (Fixed issue #17)
1 parent f9ac7aa commit 4d445c6

4 files changed

Lines changed: 90 additions & 14 deletions

File tree

CookieMonster.js

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,17 @@ CM.LoadConfig = function() {
202202
var mod = false;
203203
for (var i in CM.ConfigDefault) {
204204
if (i != 'StatsPref') {
205-
if (CM.Config[i] == undefined || !(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) {
206-
mod = true;
207-
CM.Config[i] = CM.ConfigDefault[i];
205+
if (i.indexOf('SoundURL') == -1) {
206+
if (CM.Config[i] == undefined || !(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) {
207+
mod = true;
208+
CM.Config[i] = CM.ConfigDefault[i];
209+
}
210+
}
211+
else { // Sound URLs
212+
if (CM.Config[i] == undefined || typeof CM.Config[i] != 'string') {
213+
mod = true;
214+
CM.Config[i] = CM.ConfigDefault[i];
215+
}
208216
}
209217
}
210218
else { // Statistics Preferences
@@ -286,7 +294,9 @@ CM.ConfigData.Volume = {label: [], desc: 'Volume of the sound'};
286294
for (var i = 0; i < 101; i++) {
287295
CM.ConfigData.Volume.label[i] = i + '%';
288296
}
289-
CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when has been spawned', func: function() {CM.Disp.ToggleGCTimer();}};
297+
CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
298+
CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns', func: function() {CM.Disp.ToggleGCTimer();}};
299+
CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', func: function() {CM.Disp.ToggleGCTimer();}};
290300
CM.ConfigData.Title = {label: ['Title OFF', 'Title ON'], desc: 'Update title with Golden Cookie/Season Popup timers'};
291301
CM.ConfigData.Tooltip = {label: ['Tooltip Information OFF', 'Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades'};
292302
CM.ConfigData.ToolWarnCaut = {label: ['Tooltip Warning/Caution OFF', 'Tooltip Warning/Caution ON'], desc: 'A warning/caution when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', func: function() {CM.Disp.ToggleToolWarnCaut();}};
@@ -902,7 +912,7 @@ CM.Disp.CheckGoldenCookie = function() {
902912
}
903913

904914
CM.Disp.Flash(3);
905-
CM.Disp.PlaySound('http://freesound.org/data/previews/66/66717_931655-lq.mp3');
915+
CM.Disp.PlaySound(CM.Config.GCSoundURL);
906916
}
907917
else if (CM.Config.GCTimer == 1) CM.Disp.GCTimer.style.display = 'none';
908918
}
@@ -916,7 +926,7 @@ CM.Disp.CheckGoldenCookie = function() {
916926
CM.Disp.EmphSeasonPopup = function() {
917927
if (Game.season=='christmas') {
918928
CM.Disp.Flash(3);
919-
CM.Disp.PlaySound('http://www.freesound.org/data/previews/121/121099_2193266-lq.mp3');
929+
CM.Disp.PlaySound(CM.Config.SeaSoundURL);
920930
}
921931
}
922932

@@ -994,6 +1004,32 @@ CM.Disp.AddMenuPref = function(title) {
9941004
div.appendChild(label);
9951005
return div;
9961006
}
1007+
1008+
var url = function(config) {
1009+
var div = document.createElement('div');
1010+
div.className = 'listing';
1011+
var span = document.createElement('span');
1012+
span.className = 'option';
1013+
span.textContent = CM.ConfigData[config].label + ' ';
1014+
div.appendChild(span);
1015+
var input = document.createElement('input');
1016+
input.id = CM.ConfigPrefix + config;
1017+
input.className = 'option';
1018+
input.type = 'text';
1019+
input.value = CM.Config[config];
1020+
input.style.width = '300px';
1021+
div.appendChild(input);
1022+
div.appendChild(document.createTextNode(' '));
1023+
var a = document.createElement('a');
1024+
a.className = 'option';
1025+
a.onclick = function() {CM.Config[config] = l(CM.ConfigPrefix + config).value;CM.SaveConfig(CM.Config);};
1026+
a.textContent = 'Save';
1027+
div.appendChild(a);
1028+
var label = document.createElement('label');
1029+
label.textContent = CM.ConfigData[config].desc;
1030+
div.appendChild(label);
1031+
return div;
1032+
}
9971033

9981034
frag.appendChild(header('Bars/Colors'));
9991035
frag.appendChild(listing('BotBar'));
@@ -1025,6 +1061,8 @@ CM.Disp.AddMenuPref = function(title) {
10251061
volLabel.textContent = CM.ConfigData[volConfig].desc;
10261062
volume.appendChild(volLabel);
10271063
frag.appendChild(volume);
1064+
frag.appendChild(url('GCSoundURL'));
1065+
frag.appendChild(url('SeaSoundURL'));
10281066
frag.appendChild(listing('GCTimer'));
10291067
frag.appendChild(listing('Title'));
10301068

@@ -1845,7 +1883,7 @@ CM.Init = function() {
18451883
}
18461884
}
18471885

1848-
CM.ConfigDefault = {BotBar: 1, TimerBar: 1, BuildColor: 1, UpBarColor: 1, Flash: 1, Sound: 1, Volume: 100, GCTimer: 1, Title: 1, Tooltip: 1, ToolWarnCaut: 1, ToolWarnCautPos: 1, ToolWrink: 1, Stats: 1, UpStats: 1, SayTime: 1, Scale: 2, StatsPref: {Lucky: 1, Chain: 1, HC: 1, Wrink: 1, Sea: 1}};
1886+
CM.ConfigDefault = {BotBar: 1, TimerBar: 1, BuildColor: 1, UpBarColor: 1, Flash: 1, Sound: 1, Volume: 100, GCSoundURL: 'http://freesound.org/data/previews/66/66717_931655-lq.mp3', SeaSoundURL: 'http://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', GCTimer: 1, Title: 1, Tooltip: 1, ToolWarnCaut: 1, ToolWarnCautPos: 1, ToolWrink: 1, Stats: 1, UpStats: 1, SayTime: 1, Scale: 2, StatsPref: {Lucky: 1, Chain: 1, HC: 1, Wrink: 1, Sea: 1}};
18491887
CM.ConfigPrefix = 'CMConfig';
18501888

18511889
CM.VersionMajor = '1.0465';

src/Config.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,17 @@ CM.LoadConfig = function() {
1414
var mod = false;
1515
for (var i in CM.ConfigDefault) {
1616
if (i != 'StatsPref') {
17-
if (CM.Config[i] == undefined || !(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) {
18-
mod = true;
19-
CM.Config[i] = CM.ConfigDefault[i];
17+
if (i.indexOf('SoundURL') == -1) {
18+
if (CM.Config[i] == undefined || !(CM.Config[i] > -1 && CM.Config[i] < CM.ConfigData[i].label.length)) {
19+
mod = true;
20+
CM.Config[i] = CM.ConfigDefault[i];
21+
}
22+
}
23+
else { // Sound URLs
24+
if (CM.Config[i] == undefined || typeof CM.Config[i] != 'string') {
25+
mod = true;
26+
CM.Config[i] = CM.ConfigDefault[i];
27+
}
2028
}
2129
}
2230
else { // Statistics Preferences
@@ -98,7 +106,9 @@ CM.ConfigData.Volume = {label: [], desc: 'Volume of the sound'};
98106
for (var i = 0; i < 101; i++) {
99107
CM.ConfigData.Volume.label[i] = i + '%';
100108
}
101-
CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when has been spawned', func: function() {CM.Disp.ToggleGCTimer();}};
109+
CM.ConfigData.GCSoundURL = {label: 'Golden Cookie Sound URL:', desc: 'URL of the sound to be played when a Golden Cookie spawns'};
110+
CM.ConfigData.SeaSoundURL = {label: 'Season Special Sound URL:', desc: 'URL of the sound to be played when a Season Special spawns', func: function() {CM.Disp.ToggleGCTimer();}};
111+
CM.ConfigData.GCTimer = {label: ['Golden Cookie Timer OFF', 'Golden Cookie Timer ON'], desc: 'A timer on the Golden Cookie when it has been spawned', func: function() {CM.Disp.ToggleGCTimer();}};
102112
CM.ConfigData.Title = {label: ['Title OFF', 'Title ON'], desc: 'Update title with Golden Cookie/Season Popup timers'};
103113
CM.ConfigData.Tooltip = {label: ['Tooltip Information OFF', 'Tooltip Information ON'], desc: 'Extra information in tooltip for buildings/upgrades'};
104114
CM.ConfigData.ToolWarnCaut = {label: ['Tooltip Warning/Caution OFF', 'Tooltip Warning/Caution ON'], desc: 'A warning/caution when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', func: function() {CM.Disp.ToggleToolWarnCaut();}};

src/Disp.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ CM.Disp.CheckGoldenCookie = function() {
595595
}
596596

597597
CM.Disp.Flash(3);
598-
CM.Disp.PlaySound('http://freesound.org/data/previews/66/66717_931655-lq.mp3');
598+
CM.Disp.PlaySound(CM.Config.GCSoundURL);
599599
}
600600
else if (CM.Config.GCTimer == 1) CM.Disp.GCTimer.style.display = 'none';
601601
}
@@ -609,7 +609,7 @@ CM.Disp.CheckGoldenCookie = function() {
609609
CM.Disp.EmphSeasonPopup = function() {
610610
if (Game.season=='christmas') {
611611
CM.Disp.Flash(3);
612-
CM.Disp.PlaySound('http://www.freesound.org/data/previews/121/121099_2193266-lq.mp3');
612+
CM.Disp.PlaySound(CM.Config.SeaSoundURL);
613613
}
614614
}
615615

@@ -687,6 +687,32 @@ CM.Disp.AddMenuPref = function(title) {
687687
div.appendChild(label);
688688
return div;
689689
}
690+
691+
var url = function(config) {
692+
var div = document.createElement('div');
693+
div.className = 'listing';
694+
var span = document.createElement('span');
695+
span.className = 'option';
696+
span.textContent = CM.ConfigData[config].label + ' ';
697+
div.appendChild(span);
698+
var input = document.createElement('input');
699+
input.id = CM.ConfigPrefix + config;
700+
input.className = 'option';
701+
input.type = 'text';
702+
input.value = CM.Config[config];
703+
input.style.width = '300px';
704+
div.appendChild(input);
705+
div.appendChild(document.createTextNode(' '));
706+
var a = document.createElement('a');
707+
a.className = 'option';
708+
a.onclick = function() {CM.Config[config] = l(CM.ConfigPrefix + config).value;CM.SaveConfig(CM.Config);};
709+
a.textContent = 'Save';
710+
div.appendChild(a);
711+
var label = document.createElement('label');
712+
label.textContent = CM.ConfigData[config].desc;
713+
div.appendChild(label);
714+
return div;
715+
}
690716

691717
frag.appendChild(header('Bars/Colors'));
692718
frag.appendChild(listing('BotBar'));
@@ -718,6 +744,8 @@ CM.Disp.AddMenuPref = function(title) {
718744
volLabel.textContent = CM.ConfigData[volConfig].desc;
719745
volume.appendChild(volLabel);
720746
frag.appendChild(volume);
747+
frag.appendChild(url('GCSoundURL'));
748+
frag.appendChild(url('SeaSoundURL'));
721749
frag.appendChild(listing('GCTimer'));
722750
frag.appendChild(listing('Title'));
723751

src/Main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ CM.Init = function() {
125125
}
126126
}
127127

128-
CM.ConfigDefault = {BotBar: 1, TimerBar: 1, BuildColor: 1, UpBarColor: 1, Flash: 1, Sound: 1, Volume: 100, GCTimer: 1, Title: 1, Tooltip: 1, ToolWarnCaut: 1, ToolWarnCautPos: 1, ToolWrink: 1, Stats: 1, UpStats: 1, SayTime: 1, Scale: 2, StatsPref: {Lucky: 1, Chain: 1, HC: 1, Wrink: 1, Sea: 1}};
128+
CM.ConfigDefault = {BotBar: 1, TimerBar: 1, BuildColor: 1, UpBarColor: 1, Flash: 1, Sound: 1, Volume: 100, GCSoundURL: 'http://freesound.org/data/previews/66/66717_931655-lq.mp3', SeaSoundURL: 'http://www.freesound.org/data/previews/121/121099_2193266-lq.mp3', GCTimer: 1, Title: 1, Tooltip: 1, ToolWarnCaut: 1, ToolWarnCautPos: 1, ToolWrink: 1, Stats: 1, UpStats: 1, SayTime: 1, Scale: 2, StatsPref: {Lucky: 1, Chain: 1, HC: 1, Wrink: 1, Sea: 1}};
129129
CM.ConfigPrefix = 'CMConfig';
130130

131131
CM.VersionMajor = '1.0465';

0 commit comments

Comments
 (0)