-
Notifications
You must be signed in to change notification settings - Fork 11
/
ui_automaton.js
1875 lines (1651 loc) · 65.9 KB
/
ui_automaton.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
/*
Ethereal Farm
Copyright (C) 2020-2024 Lode Vandevenne
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
// subject: 0=auto upgrade, 1=auto plant, 2=auto unlock
function showConfigureAutoResourcesDialog(subject) {
var title;
if(subject == 0) title = 'Configure auto upgrade';
else if(subject == 1) title = 'Configure auto plant';
else if(subject == 2) title = 'Configure auto unlock';
var helpindex = subject == 0 ? 29 : (subject == 1 ? 31 : 33);
var dialog = createDialog({
title:title,
help:bind(showRegisteredHelpDialog, helpindex, true),
scrollable:true});
var scrollFlex = dialog.content;
var advanced = autoFinetuningUnlocked();
var texth = 0;
var h = 0.06;
var y = 0;
var addButton = function() {
var h = 0.05;
var flex = new Flex(scrollFlex, 0.01, y, 0.4, y + h);
y += h * 1.2;
return flex;
};
var fractions = [1, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01, 0.005, 0.002, 0.001, 0.0005, 0.0002, 0.0001, 0];
var subjecttitle = subject == 0 ? 'upgrades' : (subject == 1 ? 'planting' : 'unlock');
if(advanced) {
var typenames, order;
var statefraction;
if(subject == 0) {
// auto-upgrade
typenames = ['berry', 'mushroom', 'flower', 'stinging', 'beehive', 'brassica'];
order = [3, 4, 5, 6, 7, 2]; // translate from typenames index to index in state.automaton_autoupgrade_fraction
if(squirrelUnlocked()) {
typenames.push('nuts');
order.push(9);
}
typenames.push('other');
order.push(1);
statefraction = state.automaton_autoupgrade_fraction;
} else if(subject == 1 || subject == 2) {
// auto-plant and auto-unlock
typenames = ['berry', 'mushroom', 'flower', 'stinging', 'beehive', 'mistletoe', 'brassica'];
order = [3, 4, 5, 6, 7, 8, 2]; // translate from typenames index to index in state.automaton_autoupgrade_fraction
if(subject == 1) {
statefraction = state.automaton_autoplant_fraction;
} else {
statefraction = state.automaton_autounlock_fraction;
}
if(squirrelUnlocked()) {
typenames.push('nuts');
order.push(9);
}
typenames.push('other');
order.push(1);
}
var current;
var flex;
texth = 0.12;
flex = new Flex(scrollFlex, 0.01, y, 1, y + 0.07);
flex.div.innerText = 'Select max resource amount for ' + subjecttitle + ' of each crop type:';
y += texth;
var orig_y = y;
if(subject == 2) {
if(autoPrestigeUnlocked()) {
// prestige
var button = addButton();
y += h * 0.2;
button.div.className = 'efButton';
var updateButton = function() {
button.div.textEl.innerText = state.automaton_autoprestige ? 'auto-prestige enabled' : 'auto-prestige disabled';
};
styleButton0(button.div);
centerText2(button.div);
registerTooltip(button.div, 'whether to also apply automation of crop prestige upgrades. This uses the same cost settings as auto-unlock');
updateButton();
addButtonAction(button.div, function() {
state.automaton_autoprestige = (state.automaton_autoprestige ? 0 : 1);
updateButton();
closeTopDialog();
showConfigureAutoResourcesDialog(subject);
}, 'enable or disable auto-prestige');
}
var button = addButton();
y += h * 0.2;
button.div.className = 'efButton';
var updateButton = function() {
button.div.textEl.innerText = state.automaton_autounlock_copy_plant_fraction ? 'shared with auto-plant' : 'customized below';
};
styleButton0(button.div);
centerText2(button.div);
updateButton();
addButtonAction(button.div, function() {
state.automaton_autounlock_copy_plant_fraction = !state.automaton_autounlock_copy_plant_fraction;
updateButton();
closeTopDialog();
showConfigureAutoResourcesDialog(subject);
}, 'share auto-unlock resource fraction settings with auto-plant');
}
var inactive = subject == 2 && state.automaton_autounlock_copy_plant_fraction;
if(!inactive) {
for(var d = 0; d < typenames.length; d++) {
var d2 = order[d];
flex = new Flex(scrollFlex, 0.01, y, 0.4, y + h);
y += h * 1.2;
styleButton0(flex.div);
centerText2(flex.div);
var names = [];
current = 0;
var bestdist = 1;
for(var i = 0; i < fractions.length; i++) {
names[i] = Num(fractions[i]).toPercentString(3, Num.N_FULL);
var dist = Math.abs(fractions[i] - statefraction[d2]);
if(dist < bestdist) {
current = i;
bestdist = dist;
}
}
// if the state has some value that's not present in the UI, change it to that one now to avoid misleading display
statefraction[d2] = fractions[current];
makeDropdown(flex, typenames[d], current, names, bind(function(d2, i) {
statefraction[d2] = fractions[i];
}, d2));
registerTooltip(flex.div, 'max fraction of current amount of resources that the automaton is allowed to spend on this type of auto ' + subjecttitle);
}
y += h / 4;
var flex = new Flex(scrollFlex, 0.01, y, 0.4, y + h);
y += h * 1.2;
styleButton0(flex.div);
centerText2(flex.div);
makeDropdown(flex, 'set all to', current, names, function(i) {
for(var d = 0; d < typenames.length; d++) {
var d2 = order[d];
statefraction[d2] = fractions[i];
}
closeTopDialog();
showConfigureAutoResourcesDialog(subject);
});
}
if(subject == 2) {
var x = 0.5;
y = orig_y;
h = 0.06;
var textFlex = new Flex(scrollFlex, x, y, x + 0.4, y + h);
y += h * 1.2;
var temp = state.automaton_autounlock_max_cost; // only actually stored in state.automaton_autounlock_max_cost if input field changed, rather than just receiving keypress, to avoid unwanted buys while typing
var setMaxCostText = function() {
var text = 'Cost limit: ' + temp.toString();
if(temp.eqr(0)) text += ' (unlimited)';
else text += ' seeds';
textFlex.div.innerText = text;
};
setMaxCostText();
h = 0.06;
var inputFlex = new Flex(scrollFlex, x, y, x + 0.4, y + h);
var area = util.makeAbsElement('textarea', '0', '0', '100%', '100%', inputFlex.div);
var changefun = function() {
var v = Num.parse(area.value);
if(!v || Num.isNaN(v) || v.ltr(0)) v = Num(0);
temp = v;
setMaxCostText();
};
area.onchange = function() {
changefun();
state.automaton_autounlock_max_cost = temp;
};
area.onkeyup = changefun;
y += h * 1.2;
/*area.value = state.automaton_autounlock_max_cost.toString(3, Num.N_SCI);
area.onclick = function() {
area.select();
};*/
y += 0.03;
h = 0.06;
var infoFlex = new Flex(scrollFlex, x, y, x + 0.4, y + h);
var info = '';
info += 'Change cost limit in the text box above. Automaton will not buy unlocks more expensive than this value.';
info += '<br><br>';
info += 'Use 0 to indicate unlimited (default). For example, set to 1001 to prevent auto-unlocking anything higher than blackberry.'
//info += '<br><br>'
//info += 'Supported input notation examples: 0, 1000000, 1e6, 100e48, 1M, 100QiD, ...'
//info += 'The output value above the box renders it in your preferred number notation for verification.';
infoFlex.div.innerHTML = info;
y += h * 1.2;
}
} else { // !advanced
var array = subject == 0 ? state.automaton_autoupgrade_fraction : (subject == 1 ? state.automaton_autoplant_fraction : state.automaton_autounlock_fraction);
flex = addButton();
styleButton0(flex.div);
centerText2(flex.div);
var fractions = [1, 0.5, 0.2, 0.1, 0.05, 0.02, 0.01, 0.005, 0.002, 0.001];
var names = [];
var current = 0;
var bestdist = 1;
for(var i = 0; i < fractions.length; i++) {
names[i] = Num(fractions[i]).toPercentString(3, Num.N_FULL);
var dist = Math.abs(fractions[i] - array[0]);
if(dist < bestdist) {
current = i;
bestdist = dist;
}
}
// if the state has some value that's not present in the UI, change it to that one now to avoid misleading display
array[0] = fractions[current];
makeDropdown(flex, 'max cost', current, names, function(i) {
array[0] = fractions[i];
});
registerTooltip(flex.div, 'max fraction of current amount of resources that the automaton is allowed to spend on auto ' + subjecttitle);
y += 0.03;
h = 0.06;
var infoFlex = new Flex(scrollFlex, 0, y, 1, y + h);
var info = '';
info += 'Start the no-upgrades challenge again and beat its next stage to unlock more finetuning options in this dialog';
infoFlex.div.innerHTML = info;
y += h * 1.2;
}
}
////////////////////////////////////////////////////////////////////////////////
var showingConfigureAutoChoiceDialog = false;
// Function to get the list of choice upgrades, for automaton and amber UI/gameplay. Must be kept manually up to date when adding new choice upgrades
function getChoiceUpgrades() {
return [fern_choice0, active_choice0, watercress_choice0, resin_choice0];
}
// must match the levels of the upgrades returned by getChoiceUpgrades()
function getChoiceUpgradeLevels() {
return [3, 8, 14, 22];
}
function getChoiceUpgradeInfoText(u, u2) {
var text = '';
text += '<b>' + u.choicename_a + ':</b><br>' + u.description_a;
text += '<br><br>';
text += '<b>' + u.choicename_b + ':</b><br>' + u.description_b;
text += '<br><br>';
text += '<b>Manual:</b><br>Handle this upgrade manually instead of through the automaton.';
text += '<br><br>';
text += '<b>Current status: </b>';
if(u2.count == 0) text += ' Not bought';
else if(u2.count == 1) text += ' Bought: ' + u.choicename_a;
else if(u2.count == 2) text += ' Bought: ' + u.choicename_b;
else text += ' Unknown?'; // should normally not happen
// TODO: have this available in the u object instead of hardcoding the levels duplicated here
var treelevel = -1;
if(u.index == fern_choice0) treelevel = 3;
if(u.index == active_choice0) treelevel = 8;
if(u.index == watercress_choice0) treelevel = 14;
if(u.index == resin_choice0) treelevel = 22;
if(treelevel != -1) {
text += '<br><br>';
text += '<b>Unlocked at tree level: </b>' + treelevel;
}
return text;
}
function showConfigureAutoChoiceDialog(subject) {
showingConfigureAutoChoiceDialog = true;
var dialog = createDialog({
onclose:function() {
showingConfigureAutoChoiceDialog = false;
},
scrollable:true,
title:'Configure auto choices'
});
var scrollFlex = dialog.content;
var texth = 0;
var h = 0.06;
var y = 0;
var flex;
texth = 0.15;
flex = new Flex(scrollFlex, 0.01, y, 1, y + 0.07);
flex.div.innerText = 'Choose the action for each choice upgrade dropped by the tree';
y += texth;
var addButton = function() {
var h = 0.08;
var flex = new Flex(scrollFlex, 0.01, y, 0.55, y + h);
y += h * 1.2;
return flex;
};
var addInfoButton = function() {
var h = 0.08;
var h2 = h * 1.2;
var half = h / 2;
var half2 = h2 / 2;
y -= h * 1.2; // undo height increase from main button left of this one
var flex = new Flex(scrollFlex, 0.6, [y + half -half2], [0.6, h2], [y + half + half2]);
y += h * 1.2;
return flex;
};
var choiceupgrades = [fern_choice0, active_choice0, watercress_choice0, resin_choice0];
var choiceupgrade_levels = [3, 8, 14, 22];
var updateChoicesButton = function(flex, i) {
var div = flex.div.textEl;
var u = upgrades[choiceupgrades[i]];
var s = state.automaton_choices[i];
var text = upper(u.name) + ': ';
if(s == 2) {
flex.enabledStyle = 1;
text += upper(u.choicename_a);
} else if(s == 3) {
flex.enabledStyle = 2;
text += upper(u.choicename_b);
} else {
text += 'Manual';
flex.enabledStyle = 0;
}
div.innerText = text;
setButtonIndicationStyle(flex);
};
var setButtonIndicationStyle = function(flex) {
if(flex.enabledStyle != undefined) {
flex.div.className = flex.enabledStyle == 0 ? 'efAutomatonManual' : (flex.enabledStyle == 1 ? 'efAutomatonAuto2' : 'efAutomatonAuto');
}
};
for(var i = 0; i < choiceupgrades.length; i++) {
if(state.g_treelevel < choiceupgrade_levels[i]) continue;
var u = upgrades[choiceupgrades[i]];
var u2 = state.upgrades[choiceupgrades[i]];
flex = addButton();
styleButton0(flex.div);
centerText2(flex.div);
//flex.div.innerText = u.name;
updateChoicesButton(flex, i);
addButtonAction(flex.div, bind(function(flex, i) {
if(!state.automaton_choices[i]) state.automaton_choices[i] = 1;
state.automaton_choices[i]++;
if(state.automaton_choices[i] > 3) state.automaton_choices[i] = 1;
updateChoicesButton(flex, i);
}, flex, i));
var tooltiptext = 'Configure automaton for this specific choice upgrade:<br><br>'
tooltiptext += getChoiceUpgradeInfoText(u, u2);
registerTooltip(flex.div, tooltiptext);
flex = addInfoButton();
styleButton0(flex.div, true);
var canvas = createCanvas('0%', '0%', '100%', '100%', flex.div);
renderImage(image_info, canvas);
addButtonAction(flex.div, bind(function(i) {
var u = upgrades[choiceupgrades[i]];
var u2 = state.upgrades[choiceupgrades[i]];
var dialog = createDialog({title:(u.name + ' info')});
dialog.content.div.innerHTML = getChoiceUpgradeInfoText(u, u2);
}, i));
}
}
var showing_automaton_dialog = false;
function showAutomatonFeatureSourceDialog() {
showing_automaton_dialog = true; // for achievement
var dialog = createDialog({
help:createAutomatonHelpDialog,
title:'Automaton features unlock sources',
scrollable:true,
icon:image_automaton,
onclose:function() {
showing_automaton_dialog = false;
}
});
var text = '';
text += 'This is what unlocked the automaton features you got so far:';
text += '<br/><br/>';
text += ' • Automaton itself: unlock automaton upgrade (ethereal tree level 1)';
text += '<br/>';
text += ' • Blueprints and templates: initial';
text += '<br/>';
text += ' • Clear / Plant entire field buttons: initial';
text += '<br/>';
text += ' • Neighbor bonus in ethereal field: initial';
//text += '<br/>';
//text += ' • Watercress upgrade visible from the start: initial'; // even without blackberry secret, it serves more as a reminder to plant watercress before blackberry unlocks
text += '<br/>';
text += ' • Auto-plant (blueprints, and increase crop tier when unlocked): initial';
text += '<br/>';
if(autoUpgradesUnlocked()) {
text += ' • Auto-upgrades: no-upgrades challenge (ethereal tree level 2)';
text += '<br/>';
}
if(autoFinetuningUnlocked()) {
text += ' • Finetuning options for auto-plant and auto-upgrades costs: no-upgrades challenge stage 2';
text += '<br/>';
}
if(autoChoiceUnlocked()) {
text += ' • Automation of choice upgrades: no-upgrades challenge (ethereal tree level 2)';
text += '<br/>';
}
if(autoUnlockUnlocked()) {
text += ' • Auto-unlock: blackberry challenge (ethereal tree level 3)';
text += '<br/>';
}
if(autoActionUnlocked()) {
text += ' • Auto-action: wither challenge (ethereal tree level 5)';
text += '<br/>';
}
if(autoActionExtraUnlocked()) {
text += ' • Auto-action weather, brassica refresh and fern: wither challenge stage 4';
text += '<br/>';
}
if(autoActionTranscendUnlocked()) {
text += ' • Auto-transcend and seasonal auto-actions: wither challenge stage 6';
text += '<br/>';
}
if(numAutoActionsUnlocked() > 3) {
text += ' • Extra auto-action slots: other wither challenge stages';
text += '<br/>';
}
if(autoPrestigeUnlocked()) {
text += ' • Auto-prestige: truly basic challenge';
text += '<br/>';
}
dialog.content.div.innerHTML = text;
}
function getBluePrintActionTriggerDescription(trigger) {
var text = '';
if(trigger.type == 0) {
text += 'tree level: ' + trigger.level;
} else if(trigger.type == 1 || trigger.type == 2 || trigger.type == 3 || trigger.type == 5) {
var c = crops[trigger.crop - 1];
var p = trigger.prestige;
var cropname = c ? c.name : 'none';
if(c && p) cropname += ' (prestiged)';
if(trigger.type == 1) text += 'unlocked crop: ' + cropname;
if(trigger.type == 2) {
text += 'planted crop: ';
if(trigger.crop_count > 1) text += trigger.crop_count + ' ';
text += cropname;
}
if(trigger.type == 3) {
text += 'fullgrown crop: ';
if(trigger.crop_count > 1) text += trigger.crop_count + ' ';
text += cropname;
}
if(trigger.type == 5) {
text += 'upgraded crop: ' + cropname;
if(trigger.upgrade_level > 1) text += ' level ' + trigger.upgrade_level;
}
} else if(trigger.type == 4) {
text += 'run time: ' + util.formatDuration(trigger.time, true);
}
return text;
}
function getBluePrintActionDescription(index, o) {
var visual_index = haveBeginOfRunAutoAction() ? index : (index + 1);
var text = '';
text += 'Trigger ' + visual_index + ': ';
var trigger = o.getTrigger();
if(index == 0 && haveBeginOfRunAutoAction()) {
text += 'This special limited auto-action can only be used to set up start-of-run.';
} else {
text += getBluePrintActionTriggerDescription(trigger);
}
text += '<br>';
var effect = o.getEffect();
text += 'Effect ' + visual_index + ': ';
var actiontext = '';
if(effect.enable_blueprint) {
var b = state.blueprints[effect.blueprint];
var empty = !b || (b.data.length == 0);
actiontext += 'Override blueprint ' + (effect.blueprint + 1) + ' ' + (empty ? '[empty]' : ('"' + b.name + '"'));;
}
if(effect.enable_blueprint2) {
if(actiontext != '') actiontext += '. ';
var b = state.blueprints2[effect.blueprint2];
var empty = !b || (b.data.length == 0);
actiontext += 'Ethereal blueprint ' + (effect.blueprint2 + 1) + ' ' + (empty ? '[empty]' : ('"' + b.name + '"'));;
}
if(effect.enable_fruit) {
if(actiontext != '') actiontext += '. ';
var f = state.fruit_stored[effect.fruit];
actiontext += 'Select fruit slot ' + (effect.fruit + 1); // fruit slots start at 1 (not 0) due to the keyboard key 1 being leftmost
if(f) {
actiontext += ' "' + f.toString() + '"';
}
}
if(autoActionExtraUnlocked()) {
if(effect.enable_brassica) {
if(actiontext != '') actiontext += '. ';
actiontext += 'Refresh brassica';
}
if(effect.enable_weather) {
if(actiontext != '') actiontext += '. ';
if(effect.weather == 0) actiontext += 'Activate sun';
if(effect.weather == 1) actiontext += 'Activate mist';
if(effect.weather == 2) actiontext += 'Activate rainbow';
}
if(effect.enable_fern) {
if(actiontext != '') actiontext += '. ';
actiontext += 'Pick up fern';
}
if(effect.enable_transcend) {
if(actiontext != '') actiontext += '. ';
actiontext += 'Transcend';
}
if(effect.enable_hold_season) {
if(actiontext != '') actiontext += '. ';
actiontext += 'Hold season';
}
}
if(actiontext == '') actiontext = 'None';
text += actiontext;
if(autoActionSeasonOverrideUnlocked()) {
var has_effect_season_override = false;
for(var i = 0; i < o.effect_season_override.length; i++) has_effect_season_override |= o.effect_season_override[i];
if(has_effect_season_override) {
text += '<br>';
text += 'Seasonal overrides: ' + printSeasonOverrides(o.effect_season_override);
}
}
return text;
}
// turns array of 4 booleans into the names of the seasons that are overridden
function printSeasonOverrides(array) {
var text = '';
var first = true;
for(var i = 0; i < array.length; i++) {
if(array[i]) {
if(!first) text += ', ';
first = false;
text += seasonNames[i];
}
}
if(text == '') text = 'none';
return text;
}
// mark all auto actions that would fulfill the trigger condition as done, this is used to prevent triggering all at once when auto-action was disabled during the time these newly triggered
function markTriggeredAutoActionsAsDone() {
var num = numAutoActionsUnlocked();
for(var j = 0; j < num; j++) {
var b = state.automaton_autoactions[j];
var done = autoActionTriggerConditionReached(j, b);
b.done = done;
b.done2 = done;
}
}
function showConfigureAutoActionTriggerSeasonsDialog(index, closefun) {
var visual_index = haveBeginOfRunAutoAction() ? index : (index + 1);
var o = state.automaton_autoactions[index];
var dialog = createDialog({
title:('Configure auto-action ' + visual_index + ' trigger seasonal overrides'),
help:'This allows to override the auto-action trigger for seasons of your choice. Enable the "override" checkbox of any season to override, and configure the triggers parameters of that season.',
onclose:closefun
});
var scrollFlex = dialog.content;
var texth = 0;
var h = 0.06;
var y = 0;
var addControl = function(opt_height) {
var h = 0.08 * ((opt_height == undefined) ? 1 : opt_height);
var flex = new Flex(scrollFlex, 0.01, y, 0.8, y + h);
y += h * 1.2;
return flex;
};
var flex;
for(var i = 0; i < 4; i++) {
var seasonname = seasonNames[i];
flex = addControl(0.7);
var name = 'Override ' + seasonname;
name += ' (' + getBluePrintActionTriggerDescription(o.trigger_seasonal[i]) + ')';
makeCheckbox(flex, o.trigger_season_override[i], name, bind(function(i, state) {
o.trigger_season_override[i] = state;
}, i));
flex = addControl();
styleButton(flex.div);
centerText2(flex.div);
flex.div.textEl.innerText = 'Configure ' + seasonname + ' trigger';
addButtonAction(flex.div, bind(function(i) {
showConfigureAutoActionTriggerDialog(index, undefined, i);
}, i));
y += 0.05;
}
}
function showConfigureAutoActionTriggerDialog(index, closefun, opt_season) {
var visual_index = haveBeginOfRunAutoAction() ? index : (index + 1);
var o = state.automaton_autoactions[index];
o.done = o.done2 = true; // don't trigger while editing, it can be unexpected
var functions = [];
var names = [];
if(autoActionSeasonOverrideUnlocked() && opt_season == undefined) {
functions = [function(){
showConfigureAutoActionTriggerSeasonsDialog(index, function() {
updateParamButtons();
});
return true; // keep previous dialog open
}];
names = ['seasonal'];
}
if(opt_season != undefined) {
functions = [function(){
o.trigger_seasonal[opt_season] = util.clone(o.trigger);
// Show the new state in the dialog
// The timeout is because otherwise a bug happens with the semi-transparent background overlay around the dialogs, for some reason one layer gets added instead of staying same. TODO fix that
window.setTimeout(function() {
showConfigureAutoActionTriggerDialog(index, closefun, opt_season);
});
}];
names = ['copy from main'];
}
var trigger = o.trigger;
if(opt_season != undefined) {
trigger = o.trigger_seasonal[opt_season];
}
var title = 'Configure auto-action ' + visual_index + ' trigger';
if(opt_season != undefined) {
title += ' (' + seasonNames[opt_season] + ')';
}
var dialog = createDialog({
onclose:function() {
// possibly re-enable the auto-action, if it's set in the future, or disable it if it's set in the past (so it won't trigger right now that you configured it while it applied to the past, intended for a next run)
// e.g. if re-configuring an auto-action to be after 3 hours of run, then re-enable if current runtime is 2 hours, but don't if current runtime is 4 hours
var done = autoActionTriggerConditionReached(index, o);
o.done = o.done2 = done;
o.time2 = 0;
if(closefun) closefun();
},
scrollable:true,
title:title,
help:'Here you can configure the conditions at which this automaton action will trigger, e.g. after some tree level is reached, some crops are unlocked or after a certain time',
functions:functions,
names:names,
cancelname:'back'
});
var scrollFlex = dialog.content;
var texth = 0;
var h = 0.06;
var y = 0;
var flex;
var addControl = function() {
var h = 0.08;
var flex = new Flex(scrollFlex, 0.01, y, 0.6, y + h);
y += h * 1.2;
return flex;
};
var setButtonIndicationStyle = function(flex) {
if(flex.enabledStyle != undefined) {
flex.div.className = flex.enabledStyle == 0 ? 'efAutomatonManual' : (flex.enabledStyle == 1 ? 'efAutomatonAuto2' : 'efAutomatonAuto');
}
};
var flex;
flex = addControl();
styleButton(flex.div);
centerText2(flex.div);
var typenames = ['tree level', 'unlocked crop', 'planted crop', 'fullgrown crop', 'upgraded crop', 'run time'];
// the order in the dropdown is different than the save state order
var typevalues = [0, 1, 2, 3, 5, 4];
var invtypevalues = [0, 1, 2, 3, 5, 4];
makeDropdown(flex, 'Trigger by', invtypevalues[trigger.type], typenames, function(i) {
trigger.type = typevalues[i];
updateParamButtons();
}, true);
//flex.div.className = 'efAutomatonAuto';
var paramflex = addControl();
var paramflex2 = addControl();
var seasonText = addControl();
styleButton(paramflex.div);
centerText2(paramflex.div);
var updateParamButtons = function() {
var text = '';
if(trigger.type == 0) {
text += 'tree level: ' + trigger.level;
} else if(trigger.type == 1 || trigger.type == 2 || trigger.type == 3 || trigger.type == 5) {
var c = crops[trigger.crop - 1];
var p = trigger.prestige;
var cropname = c ? c.name : 'none';
if(c && p) cropname += ' (prestiged)';
if(trigger.type == 1) text += 'unlocked crop: ' + cropname;
if(trigger.type == 2) text += 'planted crop: ' + cropname;
if(trigger.type == 3) text += 'fullgrown crop: ' + cropname;
if(trigger.type == 5) text += 'upgraded crop: ' + cropname;
} else if(trigger.type == 4) {
text += 'run time: ' + util.formatDuration(trigger.time, true);
}
paramflex.div.textEl.innerText = text;
var text2 = '';
if(trigger.type == 5) {
text2 += 'upgrade level: ' + trigger.upgrade_level;
paramflex2.div.style.visibility = 'visible';
} else if(trigger.type == 2 || trigger.type == 3) {
text2 += 'minimum count: ' + trigger.crop_count;
paramflex2.div.style.visibility = 'visible';
} else {
paramflex2.div.style.visibility = 'hidden';
}
paramflex2.div.textEl.innerText = text2;
if(autoActionSeasonOverrideUnlocked() && opt_season == undefined) {
seasonText.div.innerText = 'Seasonal overrides: ' + printSeasonOverrides(o.trigger_season_override);
} else {
seasonText.div.innerText = '';
}
};
addButtonAction(paramflex.div, function() {
if(trigger.type == 0) {
makeTextInput('Tree level', 'Enter tree level at which to perform action', function(text) {
var i = parseInt(text);
if(!(i >= 0 && i < 1000000)) i = 0;
trigger.level = i;
updateParamButtons();
}, '' + trigger.level);
} else if(trigger.type == 1 || trigger.type == 2 || trigger.type == 3 || trigger.type == 5) {
makePlantSelectDialog(trigger.crop, trigger.prestige, function(cropid, prestiged) {
trigger.crop = cropid + 1;
trigger.prestige = prestiged;
updateParamButtons();
});
} else if(trigger.type == 4) {
var current_hours = '' + Math.floor(trigger.time / 3600);
var current_minutes = '' + Math.floor((trigger.time % 3600) / 60);
var current_seconds = '' + (trigger.time % 60);
var current;
if(current_seconds == '0') {
if(current_minutes.length == 1) current_minutes = '0' + current_minutes;
current = current_hours + ':' + current_minutes;
} else {
current = '';
if(current_hours != 0) current += current_hours + 'h ';
if(current_minutes != 0) current += current_minutes + 'm ';
if(current_seconds != 0) current += current_seconds + 's';
current = current.trim();
}
makeTextInput('Run time', 'Enter time since start of run. Supported formats, e.g. for one and a half hours: 1:30, 1h30m, 1.5h or 1.5', function(text) {
var parts = text.split(':');
var parts2 = text.split('h');
var lastchar = parts.length == 1 ? lower(parts[0].charAt(parts[0].length - 1)) : '';
if(lastchar == 'd' || lastchar == 'h' || lastchar == 'm' || lastchar == 's') {
// support an alternative notation such as: 5h for 5 hours, 3d for 3 days, 2m for 2 minutes, etc..., and combinations of those. Month and year are not supported, and it's case-insensitive
var parts2 = parts[0].split(/([a-zA-Z])/); // split by letter separators such that you get both the numeric values and the separator letters. E.g. 3d 1h becomes "3","d"," 1","h",""
trigger.time = 0;
for(var i = 0; i + 1 < parts2.length; i += 2) {
var value = parseFloat(parts2[i].trim());
var unit = parts2[i + 1];
if(unit == 'd') trigger.time += value * 24 * 3600;
else if(unit == 'h') trigger.time += value * 3600;
else if(unit == 'm') trigger.time += value * 60;
else if(unit == 's') trigger.time += value;
}
} else if(parts2.length == 2 && parts.length == 1) {
// support also the form "2h30" and similar
var hours = parseFloat(parts2[0]);
var minutes = parseFloat(parts2[1]);
trigger.time = hours * 3600 + minutes * 60;
} else {
var hours = parseFloat(parts[0]);
var minutes = parts.length > 1 ? parseFloat(parts[1]) : 0;
var seconds = parts.length > 2 ? parseFloat(parts[2]) : 0; // seconds are not mentioned in the documentation to not make it too crowded, but possible
if(!(hours >= 0)) hours = 0;
if(!(minutes >= 0)) minutes = 0;
if(!(seconds >= 0)) seconds = 0;
trigger.time = hours * 3600 + minutes * 60 + seconds;
}
if(isNaN(trigger.time)) trigger.time = 0;
updateParamButtons();
}, '' + current);
}
});
styleButton(paramflex2.div);
centerText2(paramflex2.div);
addButtonAction(paramflex2.div, function() {
if(trigger.type == 5) {
makeTextInput('Upgrade level', 'Enter the upgrade level the crop should have at least (1 for first upgrade)', function(text) {
var i = parseInt(text);
if(!(i >= 1 && i < 1000000)) i = 1;
trigger.upgrade_level = i;
updateParamButtons();
}, '' + trigger.upgrade_level);
}
if(trigger.type == 2 || trigger.type == 3) {
makeTextInput('Minimum count', 'Enter the minimum amount present of this crop', function(text) {
var i = parseInt(text);
if(!(i >= 1 && i < 1000000)) i = 1;
trigger.crop_count = i;
updateParamButtons();
}, '' + trigger.upgrade_level);
}
});
updateParamButtons();
}
function showConfigureAutoActionEffectSeasonsDialog(index) {
var visual_index = haveBeginOfRunAutoAction() ? index : (index + 1);
var o = state.automaton_autoactions[index];
var dialog = createDialog({
title:('Configure auto-action ' + visual_index + ' effect seasonal overrides'),
help:'This allows to override the auto-action effect for seasons of your choice. Enable the "override" checkbox of any season to override, and configure the effect parameters of that season. All effects must be reconfigured (but there\'s a button to copy them from the default effect).'
});
var scrollFlex = dialog.content;
var texth = 0;
var h = 0.06;
var y = 0;
var addControl = function(opt_height) {
var h = 0.08 * ((opt_height == undefined) ? 1 : opt_height);
var flex = new Flex(scrollFlex, 0.01, y, 0.8, y + h);
y += h * 1.2;
return flex;
};
var flex;
for(var i = 0; i < 4; i++) {
var seasonname = seasonNames[i];
flex = addControl(0.7);
makeCheckbox(flex, o.effect_season_override[i], 'Override ' + seasonname, bind(function(i, state) {
o.effect_season_override[i] = state;
}, i));
flex = addControl();
styleButton(flex.div);
centerText2(flex.div);
flex.div.textEl.innerText = 'Configure ' + seasonname + ' effect';
addButtonAction(flex.div, bind(function(i) {
showConfigureAutoActionEffectDialog(index, undefined, i);
}, i));
y += 0.05;
}
}
// opt_season: if not undefined, then configure the season override rather than the main set of effects
function showConfigureAutoActionEffectDialog(index, closefun, opt_season) {
var visual_index = haveBeginOfRunAutoAction() ? index : (index + 1);
var o = state.automaton_autoactions[index];
var functions = [];
var names = [];
if(autoActionSeasonOverrideUnlocked() && opt_season == undefined) {
functions = [function(){
showConfigureAutoActionEffectSeasonsDialog(index);
return true; // keep previous dialog open
}];
names = ['seasonal'];
}
if(opt_season != undefined) {
functions = [function(){
o.effect_seasonal[opt_season] = util.clone(o.effect);
// Show the new state in the dialog
// The timeout is because otherwise a bug happens with the semi-transparent background overlay around the dialogs, for some reason one layer gets added instead of staying same. TODO fix that
window.setTimeout(function() {
showConfigureAutoActionEffectDialog(index, closefun, opt_season);
});
}];
names = ['copy from main'];
}
var effect = o.effect;
if(opt_season != undefined) {
effect = o.effect_seasonal[opt_season];
}
var title = 'Configure auto-action ' + visual_index + ' effect';
if(opt_season != undefined) {
title += ' (' + seasonNames[opt_season] + ')';
}
var dialog = createDialog({
onclose:closefun,
scrollable:true,
title:title,
help:'Here you can enable or disable one or more auto-action effects that occur when the condition is triggered, and choose their parameters.<br><br> - Auto-blueprint: override the field with the chosen blueprint.<br> - Ethereal blueprint: override the ethereal field with the chosen blueprint.<br> - Auto-fruit: activate the chosen fruit.<br> - Other actions may unlock later.',
functions:functions,
names:names,
cancelname:'back'
});
var scrollFlex = dialog.content;
var texth = 0;
var h = 0.06;
var y = 0;
var flex;
var addControl = function(opt_height) {
var h = 0.08 * ((opt_height == undefined) ? 1 : opt_height);
var flex = new Flex(scrollFlex, 0.01, y, 0.8, y + h);
y += h * 1.2;
return flex;
};
var setButtonIndicationStyle = function(flex) {
if(flex.enabledStyle != undefined) {
flex.div.className = flex.enabledStyle == 0 ? 'efAutomatonManual' : (flex.enabledStyle == 1 ? 'efAutomatonAuto2' : 'efAutomatonAuto');
}
};
var flex;
flex = addControl(0.7);
makeCheckbox(flex, effect.enable_blueprint, 'Enable auto-blueprint', function(state) {
effect.enable_blueprint = state;
}, 'Enable auto-blueprint');
flex = addControl();
styleButton(flex.div);
centerText2(flex.div);
var updateBlueprintButton = bind(function(flex, index) {
var i = effect.blueprint;
var b = state.blueprints[i];
var empty = !b || (b.data.length == 0);
flex.div.textEl.innerText = 'Chosen blueprint: [' + (i + 1) + '] ' + (empty ? '[empty]' : b.name);
}, flex, index);
addButtonAction(flex.div, function() {