-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheditor_start.js
9695 lines (8654 loc) · 459 KB
/
editor_start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function (window, $) {
"use strict";
/* global saveAs */
var Game = window.Game;
var byId = window.byId;
var document = window.document;
var EN = window.EN;
var loc = window.loc;
var FindLocStringByPart = window.FindLocStringByPart;
var locStrings = window.locStrings;
Game.init = function () {
"use strict";
if (!Game.firstRun) { return; }
document.forms[0].reset();
//#region start stuff
function toggleAltMode(ev) {
var testkey = Game.checkEventAltMode(ev);
if (typeof testkey !== "undefined" && testkey !== Game.altMode) {
Game.altMode = Boolean(testkey);
// Game.clearTooltip();
}
$(document.forms[0]).toggleClass("altMode", Boolean(Game.altMode));
}
$(window).on("keydown keyup", function (ev) {
Game.focusing = false;
toggleAltMode(ev);
}).on("focus", function () {
Game.focusing = true;
}).on("click", function (ev) {
if (Game.focusing) {
Game.focusing = false;
toggleAltMode(ev);
}
}).on("visibilitychange", function (ev) {
if (!document.hidden) {
toggleAltMode(ev);
}
});
//old key format
localStorage.removeItem("CCalcAbbreviateNums");
//read from saves now
localStorage.removeItem("CCalc.Heralds");
var localAbbr = Boolean(localStorage.getItem("CCalc.AbbreviateNums"));
byId("abbrCheck").checked = localAbbr;
Game.abbrOn = localAbbr;
var localSteam = Boolean(localStorage.getItem("CCalc.Steam"));
byId("steamCheck").checked = localSteam;
Game.steam = localSteam;
//automatic season detection (might not be 100% accurate)
Game.defaultSeason = "";
var year = new Date().getFullYear();
var leap = Number(((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
var day = Math.floor((new Date() - new Date(new Date().getFullYear(), 0, 0)) / (1000 * 60 * 60 * 24));
if (day >= 41 && day <= 46) {
Game.defaultSeason = "valentines";
} else if (day >= 90 + leap && day <= 92 + leap) {
Game.defaultSeason = "fools";
} else if (day >= 304 - 7 + leap && day <= 304 + leap) {
Game.defaultSeason = "halloween";
} else if (day >= 349 + leap && day <= 365 + leap) {
Game.defaultSeason = "christmas";
} else {
//easter is a pain goddamn
var easterDay = (function (Y) {
var C = Math.floor(Y / 100),
N = Y - 19 * Math.floor(Y / 19),
K = Math.floor((C - 17) / 25),
I = C - Math.floor(C / 4) - Math.floor((C - K) / 3) + 19 * N + 15;
I = I - 30 * Math.floor((I / 30));
I = I - Math.floor(I / 28) * (1 - Math.floor(I / 28) *
Math.floor(29 / (I + 1)) * Math.floor((21 - N) / 11));
var J = Y + Math.floor(Y / 4) + I + 2 - C + Math.floor(C / 4);
J = J - 7 * Math.floor(J / 7);
var L = I - J,
M = 3 + Math.floor((L + 40) / 44),
D = L + 28 - 31 * Math.floor(M / 4);
return new Date(Y, M - 1, D);
})(year);
easterDay = Math.floor((easterDay - new Date(easterDay.getFullYear(), 0, 0)) /
(1000 * 60 * 60 * 24));
if (day >= easterDay - 7 && day <= easterDay) { Game.defaultSeason = "easter"; }
}
Game.season = Game.defaultSeason;
var foolsNameCheck = byId("foolsNameCheck");
foolsNameCheck.checked = Game.defaultSeason === "fools";
for (var i in Game.prefs) {
Game.defaultPrefs[i] = Game.prefs[i];
}
Game.prefNodes = {
bgMusic: {text: "Music in background", label: loc("music will keep playing even when the game window isn't focused"), app: true},
fullscreen: {text: "Fullscreen", app: true},
fancy: {text: "Fancy graphics", label: loc("visual improvements; disabling may improve performance")},
filters: {text: "CSS filters", label: (EN ? "cutting-edge visual improvements; disabling may improve performance" : loc("visual improvements; disabling may improve performance"))},
particles: {text: "Particles", label: loc("cookies falling down, etc; disabling may improve performance")},
numbers: {text: "Numbers", label: loc("numbers that pop up when clicking the cookie")},
milk: {text: "Milk", label: (EN ? "only appears with enough achievements" : "")},
cursors: {text: "Cursors", label: loc("visual display of your cursors")},
wobbly: {text: "Wobbly cookie", label: (EN ? "your cookie will react when you click it" : "")},
cookiesound: {text: "Alt cookie sound", label: (EN ? "how your cookie sounds when you click on it" : "")},
crates: {text: "Icon crates", label: loc("display boxes around upgrades and achievements in Stats")},
monospace: {text: "Alt font", label: loc("your cookies are displayed using a monospace font")},
format: {text: "Short numbers", label: (EN ? "shorten big numbers" : ""), invert: true},
notifs: {text: "Fast notes", label: loc("notifications disappear much faster")},
autoupdate: {text: "Offline mode", label: "disables update notifications", hidden: true, invert: true},
warn: {text: "Closing warning", label: loc("the game will ask you to confirm when you close the window")},
focus: {text: "Defocus", label: loc("the game will be less resource-intensive when out of focus"), hidden: true, invert: true},
autosave: {text: "Autosave", label: "the game will save automatically", hidden: true},
extraButtons: {text: "Extra buttons", label: loc("add options on buildings like Mute")},
askLumps: {text: "Lump confirmation", label: loc("the game will ask you to confirm before spending sugar lumps")},
customGrandmas: {text: "Custom grandmas", label: loc("some grandmas will be named after Patreon supporters")},
notScary: {text: "Scary stuff"},
timeout: {text: "Sleep mode timeout", label: loc("on slower computers, the game will put itself in sleep mode when it's inactive and starts to lag out; offline CpS production kicks in during sleep mode")},
screenreader: {text: "Screen reader mode", label: loc("allows optimizations for screen readers; game will reload")},
discordPresence: {text: "Discord status", label: loc("if Discord is on, show your game info as activity status"), app: true}
};
var $gameOptions = $("#gameOptions");
var $gameAppOptions = $("#gameAppOptions");
$("<style>a.option::after { content: ' " + loc("ON") + "' } a.option.off::after { content: ' " + loc("OFF") + "' }</style>").appendTo("head");
for (i in Game.prefNodes) {
var pref = Game.prefNodes[i];
pref.$node = $('<div><a class="option smallFancyButton' + (Game.prefs[i] ^ pref.invert ? "" : " off") +
'" data-pref="' + i + '">' + loc(pref.text) + '</a> <span class="optionLabel">' + (pref.label ? "(" + pref.label + ")" : "") + "</span></div>")
.toggleClass("hidden", Boolean(pref.hidden))
.appendTo(pref.app ? $gameAppOptions : $gameOptions)
.find(".option");
}
Game.togglePref = function (prefName, toggle) {
if (!(prefName in Game.prefs)) {
return false;
}
if (typeof toggle === "undefined") {
toggle = !Game.prefs[prefName];
}
var prefNode = Game.prefNodes[prefName];
if (prefNode) {
prefNode.$node.toggleClass("off", !(toggle ^ prefNode.invert));
}
Game.prefs[prefName] = Boolean(toggle);
return toggle;
};
$gameOptions.on("click", "a.option", function () {
Game.togglePref(this.dataset.pref);
Game.scheduleUpdate();
return false;
});
var $tooltipContainer = $("#tooltip");
var tooltipEle = byId("tooltipBlock");
var $tooltipEle = $(tooltipEle);
Game.updateTooltip = null;
Game.tooltipOn = false;
Game.setTooltip = function (obj, update) {
Game.clearTooltip(update);
if (!obj || !obj.refEle) {
return;
}
if (obj.html) {
tooltipEle.innerHTML = obj.html;
}
$tooltipContainer.removeClass("hidden");
var ele = obj.refEle;
var pos = ele.getBoundingClientRect();
var eleWidth = pos.width;
var top, left;
//position it centered above obj.refEle
var windowWidth = document.body.offsetWidth;
var tooltipWidth = tooltipEle.offsetWidth;
var tooltipHeight = tooltipEle.offsetHeight;
top = pos.top - tooltipHeight - 10 - (obj.isCrate ? 9 : 0);
//put tooltip below ele if it would go off top of screen, or if specified to
if (top < 0 || obj.position === "below") {
top = pos.top + pos.height + 10;
}
left = pos.left + eleWidth / 2 - tooltipWidth / 2;
if (left + tooltipWidth + 15 > windowWidth) { //stop tooltip from going off right edge of screen
left = windowWidth - 15 - tooltipWidth;
}
//position tooltip, stopping it from going off left edge of screen (higher priority than off right)
$tooltipContainer.css({top: top, left: Math.max(left, 5)});
Game.tooltipOn = true;
};
Game.clearTooltip = function (update) {
$tooltipContainer.addClass("hidden").removeAttr("style");
Game.tooltipOn = false;
if (!update) {
Game.updateTooltip = null;
Game.tooltipUpgrade = null;
Game.tooltipAnchor = null;
}
};
//sets two inputs to update each other when changed
function twinInputs(ele1, ele2) {
ele1 = $(ele1)[0];
ele2 = $(ele2)[0];
ele1.twin = ele2;
ele2.twin = ele1;
}
function makeTag(str, color, cName) {
return ('<span class="tag' + (cName || "") + '"' + (color ? ' style="background-color:' + color + ';"' : "") + ">" + str + "</span> ");
}
var BeautifyInTextFilter = /(([\d]+[,]*)+)/g;
var clearCommasRgx = /,/g;
function BeautifyInTextFunction(str) {
return Game.Beautify(parseInt(str.replace(clearCommasRgx, ""), 10));
}
function AbbrInTextFunction(str) {
return Game.abbreviateNumber(parseInt(str.replace(clearCommasRgx, ""), 10), 0, true);
}
function BeautifyInText(str) { //reformat every number inside a string
return str.replace(BeautifyInTextFilter, BeautifyInTextFunction);
}
function AbbrInText(str) { //reformat every number inside a string
return str.replace(BeautifyInTextFilter, AbbrInTextFunction);
}
Game.getIconCss = function (icon) {
var css = {
backgroundPosition: (-icon[0] * 48) + "px " + (-icon[1] * 48) + "px",
backgroundImage: ""
};
if (icon[2]) {
css.backgroundImage = "url(" + icon[2] + ")";
}
return css;
};
Game.getIconCssStr = function (iconCss) {
if (Array.isArray(iconCss)) {
iconCss = Game.getIconCss(iconCss);
}
var str = "background-position:" + iconCss.backgroundPosition + ";";
if (iconCss.backgroundImage) {
str = "background-image:" + iconCss.backgroundImage + ";" + str;
}
return str;
};
Game.getTinyIconStr = function (iconCss) {
return ('<div class="icon tinyIcon" style="' + Game.getIconCssStr(iconCss) + '"></div>');
};
//#endregion start stuff
var j, desc, upgrade, achieve;
//#region Objects/Buildings
var ObjCalcFn = function (building) {
var mult = 1;
mult *= Game.GetTieredCpsMult(building);
return (building.baseCps * mult);
};
var ObjTableBody = $("#buildTable tbody");
Game.WinBuildingProductionAchs = function (building) {
for (var i = 0; i < building.productionAchievs.length; i++) {
var data = building.productionAchievs[i];
if (building.totalCookies >= data.pow) {
Game.Win(data.achiev);
}
}
};
var vanilla = true;
Game.Object = function (name, commonName, desc, foolsName, iconColumn, calcCps, props) {
var id = Game.ObjectsById.length;
this.type = "building";
this.id = id;
this.vanilla = vanilla;
this.name = name;
this.dname = name;
commonName = commonName.split("|");
this.single = commonName[0];
this.plural = commonName[1];
this.bsingle = this.single;
this.bplural = this.plural;
this.pluralCapital = this.plural.charAt(0).toUpperCase() + this.plural.slice(1);
this.actionName = commonName[2];
this.groupName = commonName[3];
desc = desc.split("|");
this.desc = desc[0];
this.displayDesc = desc[0];
this.extraName = commonName[1];
this.extraPlural = commonName[2];
foolsName = foolsName.split("|");
this.foolsName = foolsName[0];
this.foolsDesc = foolsName[1];
this.dname = loc(this.name);
this.single = loc(this.single);
this.plural = loc(this.plural);
this.desc = loc(FindLocStringByPart(this.name + " quote"));
this.foolsName = loc(FindLocStringByPart(this.name + " business name")) || this.foolsName;
this.foolsDesc = loc(FindLocStringByPart(this.name + " business quote")) || this.foolsDesc;
this.displayName = foolsNameCheck.checked ? this.foolsName : this.dname;
this.totalCookiesThresholdMult = Math.max(Math.pow(10, id - 2), 1);
this.iconColumn = iconColumn;
this.icon = [iconColumn, 0];
this.iconCssStr = Game.getIconCssStr(this.icon);
this.amount = 0;
this.bought = 0;
this.highest = 0;
this.free = 0;
this.level = 0;
this.totalCookies = 0;
this.muted = false;
this.fortune = 0;
this.storedTotalCps = 0;
this.synergies = [];
this.priceCache = {};
this.tieredUpgrades = {};
this.tieredAchievs = {};
this.productionAchievs = [];
this.calcCps = typeof calcCps === "function" ? calcCps : ObjCalcFn;
if (id > 0) {
//new automated price and CpS curves
this.baseCps = Math.ceil((Math.pow(id * 1, id * 0.5 + 2)) * 10) / 10;
//clamp 14,467,199 to 14,000,000 (there's probably a more elegant way to do that)
var digits = Math.pow(10, (Math.ceil(Math.log(Math.ceil(this.baseCps)) / Math.LN10))) / 100;
this.baseCps = Math.round(this.baseCps / digits) * digits;
this.basePrice = (id * 1 + 9 + (id < 5 ? 0 : Math.pow(id - 5, 1.75) * 5)) * Math.pow(10, id) * (Math.max(1, id - 14));
digits = Math.pow(10, (Math.ceil(Math.log(Math.ceil(this.basePrice)) / Math.LN10))) / 100;
this.basePrice = Math.round(this.basePrice / digits) * digits;
if (id >= 16) { this.basePrice *= 10; }
if (id >= 17) { this.basePrice *= 10; }
if (id >= 18) { this.basePrice *= 10; }
if (id >= 19) { this.basePrice *= 20; }
}
this.$tableRow = $('<tr class="buildingRow" data-building="' + name + '"><td class="name">' + this.name + "</td>" +
'<td><input type="text" class="amountIn skinnyInput plusminusIn"></td>' +
'<td><input type="text" class="boughtIn skinnyInput plusminusIn"> ' +
'<span class="boughtExpectedSpan">(0)</span></td>' +
'<td><input type="text" class="highestIn skinnyInput plusminusIn"> ' +
'<span class="highestExpectedSpan">(0)</span></td>' +
'<td><input type="text" class="levelIn skinnyInput plusminusIn limited"></td>' +
'<td><input type="text" class="totalCookiesIn exp deci"></td><td class="special"><td class="price">0</td>' +
'<td class="productButtonSpan' + (id > 0 ? "" : " hideChildren") + '">' +
'<span class="productButton productMute">Mute</span> ' +
"</td>" +
"</tr>").attr({"data-building": this.name, "data-id": id})
.appendTo(ObjTableBody);
this.amountIn = this.$tableRow.find(".amountIn")[0];
this.boughtIn = this.$tableRow.find(".boughtIn")[0];
this.highestIn = this.$tableRow.find(".highestIn")[0];
this.levelIn = this.$tableRow.find(".levelIn")[0];
this.totalCookiesIn = this.$tableRow.find(".totalCookiesIn")[0];
this.muteButton = this.$tableRow.find(".productMute")[0];
this.muteButton.objTie = this;
// this.muteButton.dataset.title = '<div class="alignCenter"><b>Mute</b><br>(Minimize this building)</div>';
this.$nameSpan = this.$tableRow.find(".name");
this.$nameSpan[0].objTie = this;
this.$priceSpan = this.$tableRow.find(".price");
this.$boughtExpectedSpan = this.$tableRow.find(".boughtExpectedSpan");
this.$boughtExpectedSpan[0].objTie = this;
this.$highestExpectedSpan = this.$tableRow.find(".highestExpectedSpan");
this.$highestExpectedSpan[0].objTie = this;
Game.registerInputs(this, [
[this.amountIn, "amount"],
[this.boughtIn, "bought"],
[this.highestIn, "highest"],
[this.levelIn, "level"],
[this.totalCookiesIn, "totalCookies"]
]);
if (props) {
$.extend(this, props);
}
Game.Objects[name] = this;
Game.ObjectsById.push(this);
Game.ObjectsByGroup[this.groupName] = this;
Game.last = this;
};
Game.Object.prototype.toString = function () {
return this.name;
};
Game.Object.prototype.getType = function () {
return this.type;
};
Game.Object.prototype.setDisplay = function () {
if (foolsNameCheck.checked) {
this.displayName = this.foolsName;
this.displayDesc = this.foolsDesc;
} else {
this.displayName = this.dname;
this.displayDesc = this.desc;
}
this.$nameSpan.text(this.displayName);
this.$tooltipBlock = null;
};
Game.Object.prototype.checkUnlocks = function () {
if (Game.ascensionMode === 1 || this.bought > this.free || this.amount !== this.free) {
Game.UnlockTiered(this);
// if (this.SpecialGrandmaUpgrade && this.amount >= Game.SpecialGrandmaUnlock && Game.Objects["Grandma"].amount > 0) {
// Game.Unlock(this.SpecialGrandmaUpgrade);
// }
}
Game.WinBuildingProductionAchs(this);
};
Game.Object.prototype.sacrifice = function (amount) {
if (!isNaN(amount)) {
Game.setInput(this.amountIn, this.amount - amount);
}
};
Game.Object.prototype.getPrice = function (amount) {
if (isNaN(amount)) {
amount = this.amount;
}
amount = Math.max(0, amount - (Game.ascensionMode === 1 ? 0 : this.free));
if (!this.priceCache[amount]) {
var price = this.basePrice * Math.pow(Game.ObjectPriceIncrease, amount);
price = Game.modifyObjectPrice(this, price);
this.priceCache[amount] = Math.ceil(price);
}
return this.priceCache[amount];
};
//sum how many cookies to reach end by buying
Game.Object.prototype.getPriceSum = function (start, end) {
var cumu = 0;
for (var i = start; i < end; i++) {
cumu += this.getPrice(i);
}
return cumu;
};
Game.Object.prototype.mute = function (toggle) {
if (this.id == 0) { return false; }
if (typeof toggle === "undefined") {
toggle = !this.muted;
}
this.muted = Boolean(toggle);
this.muteButton.classList.toggle("on", this.muted);
};
Game.Object.prototype.getTooltip = function (ele, update) {
if (!this.$tooltipBlock) {
this.setTooltipBlock();
}
$tooltipEle.empty().append(this.$tooltipBlock);
Game.setTooltip({refEle: ele, isCrate: true}, update);
};
Game.Object.prototype.setTooltipBlock = function () {
var me = this;
var name = me.displayName;
var desc = me.displayDesc;
var canBuy = false;
var price = me.price;
if (Game.cookies >= price) { canBuy = true; }
var i, upgrade, other, mult, boost;
var synergiesStr = "";
//note : might not be entirely accurate, math may need checking
if (me.amount > 0) {
var synergiesWith = {};
var synergyBoost = 0;
if (me.name === "Grandma") {
for (i = 0; i < Game.UpgradesByGroup.grandmaSynergy.length; i++) {
upgrade = Game.UpgradesByGroup.grandmaSynergy[i];
if (upgrade.bought) {
other = upgrade.grandmaBuilding;
mult = me.amount * 0.01 * (1 / (other.id - 1));
boost = (other.storedTotalCps * Game.globalCpsMult) - (other.storedTotalCps * Game.globalCpsMult) / (1 + mult);
synergyBoost += boost;
if (!synergiesWith[other.plural]) { synergiesWith[other.plural] = 0; }
synergiesWith[other.plural] += mult;
}
}
} else if (me.name === "Portal" && Game.HasUpgrade("Elder Pact")) {
other = Game.Objects["Grandma"];
boost = (me.amount * 0.05 * other.amount) * Game.globalCpsMult;
synergyBoost += boost;
if (!synergiesWith[other.plural]) { synergiesWith[other.plural] = 0; }
synergiesWith[other.plural] += boost / (other.storedTotalCps * Game.globalCpsMult);
}
for (i = 0; i < me.synergies.length; i++) {
upgrade = me.synergies[i];
if (upgrade.bought) {
var weight = 0.05;
other = upgrade.buildingTie1;
if (me == upgrade.buildingTie1) {
weight = 0.001;
other = upgrade.buildingTie2;
}
boost = (other.storedTotalCps * Game.globalCpsMult) - (other.storedTotalCps * Game.globalCpsMult) / (1 + me.amount * weight);
synergyBoost += boost;
if (!synergiesWith[other.plural]) { synergiesWith[other.plural] = 0; }
synergiesWith[other.plural] += me.amount * weight;
}
}
if (synergyBoost > 0) {
for (i in synergiesWith) {
if (synergiesStr != "") { synergiesStr += ", "; }
synergiesStr += '<span class="synergizeWith">' + i + " +" + Game.Beautify(synergiesWith[i] * 100, 1) + "%</span>";
}
synergiesStr = "...also boosting some other buildings : " + synergiesStr + " - all combined, these boosts account for <b>" + Game.BeautifyAbbr(synergyBoost, 1) + "</b> cookies per second (<b>" + Game.Beautify((synergyBoost / Game.cookiesPs) * 100, 1) + "%</b> of total CpS)";
}
}
this.$tooltipBlock = $(
'<div class="buildingTooltipHighlight"></div>' +
'<div class="buildingTooltip">' +
'<div class="icon buildingIcon" style="' + me.iconCssStr + '"></div>' +
'<div class="buildingPrice"><span class="price priceIcon' + (canBuy ? "" : " disabled") + '">' + Game.BeautifyAbbr(Math.round(price)) + "</span>" + Game.costDetails(price) + "</div>" +
'<div class="name">' + name + "</div>" +
'<small><div class="tag">' + loc("owned: %1", me.amount) + "</div>" + (me.free > 0 ? '<div class="tag">' + loc("free: %1!", me.free) + "</div>" : "") + "</small>" +
'<div class="line"></div><div class="description"><q>' + desc + "</q></div>" +
(me.totalCookies > 0 ? (
'<div class="line"></div>' +
(me.amount > 0 ? '<div class="descriptionBlock">' + loc("each %1 produces <b>%2</b> per second", [me.single, loc("%1 cookie", Game.LBeautify((me.storedTotalCps / me.amount) * Game.globalCpsMult, 1))]) + "</div>" : "") +
'<div class="descriptionBlock">' + loc("%1 producing <b>%2</b> per second", [loc("%1 " + me.bsingle, Game.LBeautify(me.amount)), loc("%1 cookie", Game.LBeautify(me.storedTotalCps * Game.globalCpsMult, 1))]) +
" (" + loc("<b>%1%</b> of total CpS", Game.Beautify(Game.cookiesPs > 0 ? ((me.amount > 0 ? ((me.storedTotalCps * Game.globalCpsMult) / Game.cookiesPs) : 0) * 100) : 0, 1)) + ")</div>" +
(synergiesStr ? ('<div class="descriptionBlock">' + synergiesStr + "</div>") : "") +
(EN ? '<div class="descriptionBlock"><b>' + Game.Beautify(me.totalCookies) + "</b> " + (Math.floor(me.totalCookies) == 1 ? "cookie" : "cookies") + " " +
me.actionName + " so far</div>" : '<div class="descriptionBlock">' + loc("<b>%1</b> produced so far", loc("%1 cookie", Game.LBeautify(me.totalCookies))) + "</div>")
) : "") +
"</div>"
);
};
/* Game.Object.prototype.levelTooltip = function () {
var me = this;
var level = Game.Beautify(me.level);
return ('<div style="width:280px;padding:8px;"><b>Level ' + level + " " + me.plural + '</b><div class="line"></div>' +
(me.level === 1 ? me.extraName : me.extraPlural).replace("[X]", level) + " granting <b>+" + level + "% " + me.name +
' CpS</b>.<div class="line"></div>Click to level up for <span class="price lump' + (Game.lumps >= me.level + 1 ? "" : " disabled") + '">' +
Game.Beautify(me.level + 1) + Game.getPlural(me.level + 1, " sugar lump") + "</span>." +
((me.level === 0 && me.minigameUrl) ? '<div class="line"></div><b>Levelling up this building unlocks a minigame.</b>' : "") + "</div>");
}; */
//define Objects/Buildings
new Game.Object("Cursor", "cursor|cursors|clicked|cursor",
"Autoclicks once every 10 seconds.|[X] extra finger|[X] extra fingers",
"Rolling pin|Essential in flattening dough. The first step in cookie-making.",
0, function (me) {
var add = 0;
if (Game.HasUpgrade("Thousand fingers")) { add += 0.1; }
if (Game.HasUpgrade("Million fingers")) { add *= 5; }
if (Game.HasUpgrade("Billion fingers")) { add *= 10; }
if (Game.HasUpgrade("Trillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Quadrillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Quintillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Sextillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Septillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Octillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Nonillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Decillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Undecillion fingers")) { add *= 20; }
if (Game.HasUpgrade("Unshackled cursors")) { add *= 25; }
var mult = 1;
mult *= Game.GetTieredCpsMult(me);
// mult *= Game.magicCps("Cursor"); //effectively disabled ingame after Orteil found how overpowered it was
mult *= Game.eff("cursorCps");
add *= Game.ObjectsOwned - me.amount;
return (Game.ComputeCps(0.1, Game.HasUpgrade("Reinforced index finger") +
Game.HasUpgrade("Carpal tunnel prevention cream") + Game.HasUpgrade("Ambidextrous"), add) * mult);
}, {
basePrice: 15,
baseCps: 0.1,
totalCookiesThresholdMult: 1000000,
checkUnlocks: function () {
var amount = this.amount;
if (Game.ascensionMode === 1 || this.bought > this.free || amount !== this.free) {
if (amount >= 1) { Game.Unlock(["Reinforced index finger", "Carpal tunnel prevention cream"]); }
if (amount >= 10) { Game.Unlock("Ambidextrous"); }
if (amount >= 25) { Game.Unlock("Thousand fingers"); }
if (amount >= 50) { Game.Unlock("Million fingers"); }
if (amount >= 100) { Game.Unlock("Billion fingers"); }
if (amount >= 150) { Game.Unlock("Trillion fingers"); }
if (amount >= 200) { Game.Unlock("Quadrillion fingers"); }
if (amount >= 250) { Game.Unlock("Quintillion fingers"); }
if (amount >= 300) { Game.Unlock("Sextillion fingers"); }
if (amount >= 350) { Game.Unlock("Septillion fingers"); }
if (amount >= 400) { Game.Unlock("Octillion fingers"); }
if (amount >= 450) { Game.Unlock("Nonillion fingers"); }
if (amount >= 500) { Game.Unlock("Decillion fingers"); }
if (amount >= 550) { Game.Unlock("Unecillion fingers"); }
}
if (amount >= 1) { Game.Win("Click"); }
if (amount >= 2) { Game.Win("Double-click"); }
if (amount >= 50) { Game.Win("Mouse wheel"); }
if (amount >= 100) { Game.Win("Of Mice and Men"); }
if (amount >= 200) { Game.Win("The Digital"); }
if (amount >= 300) { Game.Win("Extreme polydactyly"); }
if (amount >= 400) { Game.Win("Dr. T"); }
if (amount >= 500) { Game.Win("Thumbs, phalanges, metacarpals"); }
if (amount >= 600) { Game.Win("With her finger and her thumb"); }
if (amount >= 700) { Game.Win("Gotta hand it to you"); }
if (amount >= 800) { Game.Win("The devil's workshop"); }
if (amount >= 900) { Game.Win("All on deck"); }
if (amount >= 1000) { Game.Win("A round of applause"); }
Game.WinBuildingProductionAchs(this);
}
}
);
new Game.Object("Grandma", "grandma|grandmas|baked|grandma",
"A nice grandma to bake more cookies.|Grandmas are [X] year older|Grandmas are [X] years older",
"Oven|A crucial element of baking cookies.",
1, function (me) {
var mult = 1;
for (var i = 0; i < Game.UpgradesByGroup.grandmaSynergy.length; i++) {
if (Game.UpgradesByGroup.grandmaSynergy[i].getBought()) {
mult *= 2;
}
}
if (Game.HasUpgrade("Bingo center/Research facility")) { mult *= 4; }
if (Game.HasUpgrade("Ritual rolling pins")) { mult *= 2; }
if (Game.HasUpgrade("Naughty list")) { mult *= 2; }
if (Game.HasUpgrade("Elderwort biscuits")) { mult *= 1.02; }
mult *= Game.eff("grandmaCps");
if (Game.HasUpgrade("Cat ladies")) {
for (i = 0; i < Game.UpgradesByPool.kitten.length; i++) {
if (Game.UpgradesByPool.kitten[i].getBought()) { mult *= 1.29; }
}
}
mult *= Game.GetTieredCpsMult(me);
var add = 0;
if (Game.HasUpgrade("One mind")) { add += me.amount * 0.02; }
if (Game.HasUpgrade("Communal brainsweep")) { add += me.amount * 0.02; }
if (Game.HasUpgrade("Elder Pact")) { add += Game.Objects["Portal"].amount * 0.05; }
mult *= 1 + Game.auraMult("Elder Battalion") * 0.01 * (Game.ObjectsOwned - me.amount);
return (me.baseCps + add) * mult;
}, {
totalCookiesThresholdMult: 1000000
}
);
new Game.Object("Farm", "farm|farms|harvested|farm",
"Grows cookie plants from cookie seeds.|[X] more acre|[X] more acres",
"Kitchen|The more kitchens, the more cookies your employees can produce.",
2);
new Game.Object("Mine", "mine|mines|mined|mine",
"Mines out cookie dough and chocolate chips.|[X] mile deeper|[X] miles deeper",
"Secret recipe|These give you the edge you need to outsell those pesky competitors.",
3);
new Game.Object("Factory", "factory|factories|mass-produced|factory",
"Produces large quantities of cookies.|[X] additional patent|[X] additional patents",
"Factory|Mass production is the future of baking. Seize the day, and synergize!",
4);
new Game.Object("Bank", "bank|banks|banked|bank",
"Generates cookies from interest.|Interest rates [X]% better|Interest rates [X]% better",
"Investor|Business folks with a nose for profit, ready to finance your venture as long as there's money to be made.",
15);
new Game.Object("Temple", "temple|temples|discovered|temple",
"Full of precious, ancient chocolate.|[X] sacred artifact retrieved|[X] sacred artifacts retrieved",
"Like|Your social media page is going viral! Amassing likes is the key to a lasting online presence and juicy advertising deals.",
16);
new Game.Object("Wizard tower", "wizard tower|wizard towers|summoned|wizardTower",
"Summons cookies with magic spells.|Incantations have [X] more syllable|Incantations have [X] more syllables",
"Meme|Cookie memes are all the rage! With just the right amount of social media astroturfing, your brand image will be all over the cyberspace.",
17);
new Game.Object("Shipment", "shipment|shipments|shipped|shipment",
"Brings in fresh cookies from the cookie planet.|[X] galaxy fully explored|[X] galaxies fully explored",
"Supermarket|A gigantic cookie emporium - your very own retail chain.",
5);
new Game.Object("Alchemy lab", "alchemy lab|alchemy labs|transmuted|alchemyLab",
"Turns gold into cookies!|[X] primordial element mastered|[X] primordial elements mastered",
"Stock share|You're officially on the stock market, and everyone wants a piece!",
6);
new Game.Object("Portal", "portal|portals|retrieved|portal",
"Opens a door to the Cookieverse.|[X] dimension enslaved|[X] dimensions enslaved",
"TV show|Your cookies have their own sitcom! Hilarious baking hijinks set to the cheesiest laughtrack.",
7);
new Game.Object("Time machine", "time machine|time machines|recovered|timeMachine",
"Brings cookies from the past, before they were even eaten.|[X] century secured|[X] centuries secured",
"Theme park|Cookie theme parks, full of mascots and roller-coasters. Build one, build a hundred!",
8, "Grandmas' grandmas");
new Game.Object("Antimatter condenser", "antimatter condenser|antimatter condensers|condensed|antimatterCondenser",
"Condenses the antimatter in the universe into cookies.|[X] extra quark flavor|[X] extra quark flavors",
"Cookiecoin|A virtual currency, already replacing regular money in some small countries.",
13);
new Game.Object("Prism", "prism|prisms|converted|prism",
"Converts light itself into cookies.|[X] new color discovered|[X] new colors discovered",
"Corporate country|You've made it to the top, and you can now buy entire nations to further your corporate greed. Godspeed.",
14);
new Game.Object("Chancemaker", "chancemaker|chancemakers|spontaneously generated|chancemaker",
"Generates cookies out of thin air through sheer luck.|Chancemakers are powered by [X]-leaf clovers|Chancemakers are powered by [X]-leaf clovers",
"Privatized planet|Actually, you know what's cool? A whole planet dedicated to producing, advertising, selling, and consuming your cookies.",
19);
new Game.Object("Fractal engine", "fractal engine|fractal engines|made from cookies|fractalEngine",
"Turns cookies into even more cookies.|[X] iteration deep|[X] iterations deep",
"Senate seat|Only through political dominion can you truly alter this world to create a brighter, more cookie-friendly future.",
20);
new Game.Object("Javascript console", "javascript console|javascript consoles|programmed|jsConsole",
"Creates cookies from the very code this game was written in.|Equipped with [X] external library|Equipped with [X] external libraries",
"Doctrine|Taking many forms -religion, culture, philosophy- a doctrine may, when handled properly, cause a lasting impact on civilizations, reshaping minds and people and ensuring all future generations share a singular goal - the production, and acquisition, of more cookies.",
32);
new Game.Object("Idleverse", "idleverse|idleverses|hijacked|idleverse",
"There's been countless other idle universes running alongside our own. You've finally found a way to hijack their production and convert whatever they've been making into cookies!|[X] manifold|[X] manifolds",
"Lateral expansions|Sometimes the best way to keep going up is sideways. Diversify your ventures through non-cookie investments.",
33);
new Game.Object("Cortex baker", "cortex baker|cortex bakers|imagined|cortexBaker",
"These artificial brains the size of planets are capable of simply dreaming up cookies into existence. Time and space are inconsequential. Reality is arbitrary.|[X] extra IQ point|[X] extra IQ points",
"Think tank|There's only so many ways you can bring in more profit. Or is there? Hire the most brilliant experts in the known universe and let them scrape their brains for you!",
34);
new Game.Object("You", "You|You|cloned|you",
"You, alone, are the reason behind all these cookies. You figure if there were more of you... maybe you could make even more.|[X] optimized gene|[X] optimized genes",
"You|Your business is as great as it's gonna get. The only real way to improve it anymore is to improve yourself - and become the best Chief Executive Officer this world has ever seen.",
35);
//#endregion Objects/Buildings
//#region YouCustomizer
Game.YouCustomizer.genesById = {};
for (i = 0; i < Game.YouCustomizer.genes.length; i++) {
Game.YouCustomizer.genes[i].n = i;
Game.YouCustomizer.genesById[Game.YouCustomizer.genes[i].id] = Game.YouCustomizer.genes[i];
}
Game.YouCustomizer.genesById["acc2"].choices = Game.YouCustomizer.genesById["acc1"].choices;
Game.YouCustomizer.resetGenes = function () {
for (var i = 0; i < Game.YouCustomizer.genes.length; i++) {
Game.YouCustomizer.currentGenes[i] = Game.YouCustomizer.genes[i].def;
}
};
Game.YouCustomizer.resetGenes();
var makeCustomizerSelector = function (gene, text) {
gene = Game.YouCustomizer.genesById[gene];
$('<div class="customizerSettingRow">' +
'<a id="customizerSelect-L-' + gene.id + '" class="framed smallFancyButton customizerSettingBtn floatLeft" data-gene="' + gene.id + '"><</a>' + text +
' <span id="customizerSelect-N-' + gene.id + '">' +
(gene.isList ? (Game.YouCustomizer.currentGenes[gene.n] + 1) : (Game.YouCustomizer.currentGenes[gene.n] + 1 - gene.choices[0])) +
"</span>" +
'<a id="customizerSelect-R-' + gene.id + '" class="framed smallFancyButton customizerSettingBtn floatRight" data-gene="' + gene.id + '">></a>' +
"</div>").appendTo("#customizerSettingsBlock");
gene.selectEle = byId("customizerSelect-N-" + gene.id);
};
makeCustomizerSelector("hair", loc("Hair"));
makeCustomizerSelector("hairCol", loc("Hair color"));
makeCustomizerSelector("skinCol", loc("Skin color"));
makeCustomizerSelector("head", loc("Head shape"));
makeCustomizerSelector("face", loc("Face"));
makeCustomizerSelector("acc1", loc("Extra") + "-A");
makeCustomizerSelector("acc2", loc("Extra") + "-B");
Game.YouCustomizer.offsetGene = function (gene, off) {
gene = Game.YouCustomizer.genesById[gene];
Game.YouCustomizer.currentGenes[gene.n] += off;
if (gene.isList) {
if (Game.YouCustomizer.currentGenes[gene.n] >= gene.choices.length) { Game.YouCustomizer.currentGenes[gene.n] = 0; }
else if (Game.YouCustomizer.currentGenes[gene.n] < 0) { Game.YouCustomizer.currentGenes[gene.n] = gene.choices.length - 1; }
if (gene.selectEle) { gene.selectEle.innerHTML = Game.YouCustomizer.currentGenes[gene.n] + 1; }
} else {
if (Game.YouCustomizer.currentGenes[gene.n] > gene.choices[1]) { Game.YouCustomizer.currentGenes[gene.n] = gene.choices[0]; }
else if (Game.YouCustomizer.currentGenes[gene.n] < gene.choices[0]) { Game.YouCustomizer.currentGenes[gene.n] = gene.choices[1]; }
if (gene.selectEle) { gene.selectEle.innerHTML = Game.YouCustomizer.currentGenes[gene.n] + 1 - gene.choices[0]; }
}
if (off != 0) {
Game.YouCustomizer.render();
}
};
Game.YouCustomizer.getGeneValue = function (id) {
var gene = Game.YouCustomizer.genesById[id];
if (gene.isList) {
return gene.choices[Game.YouCustomizer.currentGenes[gene.n]];
} else {
return Game.YouCustomizer.currentGenes[gene.n];
}
};
Game.YouCustomizer.assets = {
you: byId("customizerAssetYou"),
youAddons: byId("customizerAssetYouAddons"),
render: byId("customizerRender")
};
Game.YouCustomizer.render = function () {
var ctx = Game.YouCustomizer.assets.render.getContext("2d");
var img = Game.YouCustomizer.assets.you;
var imgAddons = Game.YouCustomizer.assets.youAddons;
ctx.drawImage(img, 0, 0);
var canvasAddon = document.createElement("canvas");
canvasAddon.width = 32;
canvasAddon.height = 32;
var ctxAddon = canvasAddon.getContext("2d");
var canvasCols = document.createElement("canvas");
var colsN = 64;
canvasCols.width = 8;
canvasCols.height = colsN;
var ctxCols = canvasCols.getContext("2d");
ctxCols.drawImage(imgAddons, 0, 0, 8, colsN, 0, 0, 8, colsN);
var imgDataCols = ctxCols.getImageData(0, 0, 8, colsN);
var dataCols = imgDataCols.data;
var cols = [];
var i, r, g, b, a, col;
for (i = 0; i < colsN; i++) {
cols[i] = [
[dataCols[4 + i * 32], dataCols[4 + i * 32 + 1], dataCols[4 + i * 32 + 2]],
[dataCols[4 + i * 32 + 4], dataCols[4 + i * 32 + 1 + 4], dataCols[4 + i * 32 + 2 + 4]],
[dataCols[4 + i * 32 + 8], dataCols[4 + i * 32 + 1 + 8], dataCols[4 + i * 32 + 2 + 8]],
];
}
var imgData = ctx.getImageData(0, 0, 64, 64);
var data = imgData.data;
var colSkinFull = [[32, 14, 10], [180, 80, 54], [208, 144, 101], [225, 192, 150]];
var colSkin = [];
for (var colI = 0; colI < colSkinFull.length; colI++) {
colSkin[colI] = colSkinFull[colI][0] * 1000000 + colSkinFull[colI][1] * 1000 + colSkinFull[colI][2];
}
var colHairFull = [[32, 14, 10], [82, 55, 53], [100, 83, 80], [116, 97, 89]];
var colHair = []; for (colI = 0; colI < colHairFull.length; colI++) {
colHair[colI] = colHairFull[colI][0] * 1000000 + colHairFull[colI][1] * 1000 + colHairFull[colI][2];
}
var shade1 = 0 * 1000000 + 118 * 1000 + 206;
var shade2 = 0 * 1000000 + 71 * 1000 + 125;
//apply addon canvases to main canvas, handling shading on skin and hair where necessary
var addonGenes = ["face", "head", "hair", "acc1", "acc2"];
for (var geneI = 0; geneI < addonGenes.length; geneI++) {
var addonTile = Game.YouCustomizer.getGeneValue(addonGenes[geneI]);
ctxAddon.clearRect(0, 0, 32, 32);
ctxAddon.drawImage(imgAddons, 8 + addonTile[0] * 32, addonTile[1] * 32, 32, 32, 0, 0, 32, 32);
var imgDataAddon = ctxAddon.getImageData(0, 0, 32, 32);
var dataAddon = imgDataAddon.data;
var x = 0; var y = 0;
for (i = 0; i < dataAddon.length; i += 4) {
r = dataAddon[i];
g = dataAddon[i + 1];
b = dataAddon[i + 2];
a = dataAddon[i + 3];
var off = ((x + 16) + y * 64) * 4;
if (a != 0) {
var ro = data[off];
var go = data[off + 1];
var bo = data[off + 2];
col = r * 1000000 + g * 1000 + b;
var shade = col == shade2 ? 2 : col == shade1 ? 1 : 0;
var indShadeOr = colSkin.indexOf(ro * 1000000 + go * 1000 + bo);
var typeOr = 0;
if (indShadeOr > 0) {
typeOr = 1; //is skin
} else if (indShadeOr == -1) {
indShadeOr = colHair.indexOf(ro * 1000000 + go * 1000 + bo);
if (indShadeOr > 0) {
typeOr = 2; //is hair
}
}
if (shade > 0 && indShadeOr > 0)//painting shadow on hair or skin
{ //light blue: shade one stage; dark blue: shade 2 stages
var colOut = (typeOr == 1 ? colSkinFull : typeOr == 2 ? colHairFull : 0)[Math.max(0, indShadeOr - shade)];
data[off] = colOut[0]; data[off + 1] = colOut[1]; data[off + 2] = colOut[2]; data[off + 3] = a;
}
else if (shade == 0) { data[off] = r; data[off + 1] = g; data[off + 2] = b; data[off + 3] = a; }
}
x++;
if (x >= 32) { x = 0; y++; }
}
}
//recolor hair and skin on final image
var skinCol = Game.YouCustomizer.getGeneValue("skinCol");
var hairCol = Game.YouCustomizer.getGeneValue("hairCol");
for (i = 0; i < data.length; i += 4) {
r = data[i];
g = data[i + 1];
b = data[i + 2];
a = data[i + 3];
if (a != 0) {
var indSkin = colSkin.indexOf(r * 1000000 + g * 1000 + b);
if (indSkin > 0) {
col = cols[skinCol][indSkin - 1];
data[i] = col[0]; data[i + 1] = col[1]; data[i + 2] = col[2];
} else {
var indHair = colHair.indexOf(r * 1000000 + g * 1000 + b);
if (indHair > 0) {
col = cols[hairCol][indHair - 1];
data[i] = col[0]; data[i + 1] = col[1]; data[i + 2] = col[2];
}
}
}
}
ctx.putImageData(imgData, 0, 0);
ctx = byId("customizerPreview").getContext("2d");
ctx.clearRect(0, 0, 32, 32);
ctx.drawImage(Game.YouCustomizer.assets.render, -16, 0);
ctx = byId("customizerPreviewBlur").getContext("2d");
ctx.globalCompositeOperation = "source-over";
ctx.clearRect(0, 0, 32, 32);
ctx.drawImage(Game.YouCustomizer.assets.render, -16, 0);
ctx.globalCompositeOperation = "destination-out"; ctx.beginPath(); ctx.arc(16, 16, 11, 0, 2 * Math.PI); ctx.fill();
};
Game.YouCustomizer.update = function () {
for (var i = 0; i < Game.YouCustomizer.genes.length; i++) {
Game.YouCustomizer.offsetGene(Game.YouCustomizer.genes[i].id, 0);
}
Game.YouCustomizer.render();
};
Game.YouCustomizer.randomize = function () {
for (var i = 0; i < Game.YouCustomizer.genes.length; i++) {
Game.YouCustomizer.currentGenes[i] = Math.floor(Math.random() * Game.YouCustomizer.genes[i].choices.length);
}
Game.YouCustomizer.update();
};
$("#customizerRandom").on("click", function () {
Game.YouCustomizer.randomize();
Game.scheduleUpdate();