-
Notifications
You must be signed in to change notification settings - Fork 0
/
magix-wiki.html
1356 lines (1274 loc) · 63.9 KB
/
magix-wiki.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Magix Wiki</title>
<script src="MagixData.js"></script>
<style>
/* Locally use the Domine font from https://fonts.googleapis.com/css?family=Domine */
@font-face {
font-family: "Domine";
font-style: normal;
font-weight: 400;
src: url(a.woff2) format("woff2");
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
font-family: "Domine";
font-style: normal;
font-weight: 400;
src: url(b.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
* {
font-size: 16px;
}
li,
li * {
font-size: 14px;
}
*::selection {
background: #ec80dd88;
}
::-webkit-scrollbar {
-webkit-appearance: none;
width: 17px;
}
::-webkit-scrollbar-track {
background: #333;
box-shadow:
0px 0px 0px 1px #111 inset,
0px 0px 0px 3px #444 inset,
1px 1px 2px 3px #222 inset;
}
::-webkit-scrollbar-thumb {
background: #ccc;
box-shadow:
0px 0px 0px 1px #333 inset,
0px 0px 0px 3px #999 inset,
1px 1px 1px 3px #fff inset;
}
::-webkit-scrollbar-thumb:hover {
background: #ddd;
}
::-webkit-scrollbar-thumb:active {
background: #bbb;
}
h1,
input,
select {
font-size: 30px;
}
#inputs {
text-align: center;
}
#inputs>input {
font-size: 15px;
width: 90%;
}
h1,
button,
.main {
user-select: none;
}
h3 {
font-size: 25px;
}
body {
background-image: url(Magix/bgDarkRockDefault.jpg);
}
header {
text-decoration: underline;
}
.civ2 {
background-image: url(Magix/bgDarkRockC2.jpg);
}
body,
select,
input,
button {
font-family: Domine;
background-color: black;
color: white;
}
#modCreator>button {
background-color: white;
color: #585858;
}
input,
select {
border-radius: 5px;
border: solid 2px #bbb;
}
u {
cursor: pointer;
color: #1caaf7;
}
button {
cursor: pointer;
border-radius: 4px;
border: solid 1px #888;
}
div {
color: #fffb;
word-break: normal;
white-space: pre;
}
textarea {
resize: none;
color: white;
background-color: #8884;
border: solid 1px black;
border-radius: 10px;
}
.darker {
color: #fffb;
}
.nopre {
white-space: normal;
}
.par {
margin-bottom: 6px;
text-indent: 6px;
}
small {
font-size: 80%;
}
.bulleted {
margin: 4px;
padding-left: 20px;
}
.bulleted:before {
content: "\2022";
padding-right: 8px;
}
.divider {
width: 90%;
margin: 8px auto;
height: 1px;
background: linear-gradient(to right, #fff0, #ffffff40, #fff0);
}
.divider:after {
content: "";
display: block;
width: 100%;
height: 1px;
position: relative;
top: 1px;
background: linear-gradient(to right, #0000, #00000080, #0000);
}
.icon,
.wide,
.triple {
cursor: pointer;
image-rendering: optimizeSpeed;
image-rendering: -moz-crisp-edges;
image-rendering: -o-crisp-edges;
image-rendering: -webkit-optimize-contrast;
image-rendering: pixelated;
image-rendering: optimize-contrast;
-ms-interpolation-mode: nearest-neighbor;
border-radius: 3px;
width: 24px;
height: 24px;
margin-bottom: 40px;
transform-origin: top left;
transform: scale(3);
}
.wide {
width: 72px;
}
.triple {
width: 72px;
height: 72px;
}
.large {
transform: scale(5);
margin-bottom: 90px;
}
.shadow {
filter: drop-shadow(0 3px 3px black);
}
.noclick {
border-radius: 1px;
cursor: default;
}
strong {
color: white;
}
.mono {
font-family: monospace;
line-height: 1.2;
}
.ocean {
color: #459bf2;
text-decoration: underline;
}
.land {
color: #509e4e;
text-decoration: underline;
}
</style>
<script src="minisearch.js"></script>
<script src="relaxedJSON.js"></script>
</head>
<body>
<h1>Explore Magix data</h1>
<span class="main">
<input placeholder="Item name here...">
<select name="Item type">
<option value="techs">Techs</option>
<option value="units">Units</option>
<option value="resources">Resources</option>
<option value="traits">Traits</option>
<option value="policies">Policies</option>
<option value="achievements">Achievements</option>
<option value="lands">Lands</option>
<option value="goods">Goods</option>
</select>
<select name="Advanced settings">
<option>Icons and name</option>
<option selected>Minimal values</option>
<option>Some debug values</option>
<option>All debug values</option>
<option>Show property JSON</option>
</select>
</span>
<br>
<label for="a"><input type="checkbox" id="a"> Use the elf race instead of the human race</label>
<button>Export all civ JSON</button><button>Export JSON for this category</button>
<br>
<button>Show mod creator</button>
<hr>
<span id="modCreator" style="display:none">
To select an item you want to modify, click on it. Then, you'll be able to mess with it!
Click on the button below to make a new item of the type you selected at the top.
<br>
<button>Create a new tech</button>
<button>There is nothing to delete.</button>
<button>Update data</button>
<br>
You can write various settings for your mod here.
The fourth input is an object for the sprite data (read below for more info) with various links to your sprites.
(If you're not using it, just replace all of it with <span class="mono">{}</span> instead.)
<div>
Tip: don't know how to use icons or how to set other values?
See a few examples by clicking on images of a few items. You should get the hang of it after a bit!
</div>
<input placeholder="Mod name..." value="Mod Name">
<input placeholder="Author..." value="Author">
<input placeholder="Description..." value="Description of the mod.">
<input placeholder="Sprite data..." value='{customSheet: "about:blank"}'>
<br>
<span id="inputs"></span>
<br>
Confused on why some of these have braces like <span class="mono">{tribalism:true}</span>?
This is called an <b>object</b>. You may also add more items to this list; for example,
<span class="mono">{tribalism:true, stone-knapping:true}</span>.
However, you need the <b>raw name</b> of the item you are trying to add;
you may find this by clicking on the image of the item you want to add to an object!
<div>
Tip: confused why there's an error with the object? If the raw name of something has a space,
you will have to do something like this:
<span class="mono">{"rules of food": true}</span> and it will work. (Otherwise, the quotes are optional.)
Sometimes, arrays will use spaces instead of commas; don't freak out.
</div>
<hr>
<textarea rows="20" cols="100" disabled
placeholder="The automatically generated script will output here. Note that the comment at the start provides important metadata so that you can import it back in to here (make sure to keep it somewhere safe even if you end up removing it upon release)! Copy that comment when you're importing a script in."></textarea>
<div>
Tip: want to release your mod somewhere? You can try a service like file.garden or use GitHub Pages.
We hope you enjoy your modding adventure!
</div>
<textarea rows="5" cols="50" placeholder="Import script data here..."></textarea>
<br>
<button>Import script</button>
<hr>
<div>
Tip: effects and modes are <b>very</b> complex to learn! It's a good idea to look at a few examples.
Here are a few key parts to know:
</div>
<ul class="darker">
<li>each effect or mode is able to have a requirement (the <span class="mono">req</span> property)</li>
<li>modes are unique in that they can have an icon and description</li>
<li>effects are able to work for a specific mode, this works for multiplier effects as well</li>
<li>enable all debug values and look at a few examples; you might understand them much better after</li>
<li>also, be aware that some things might not work as you expect; sometimes, examples teach well</li>
</ul>
<hr>
</span>
<div></div>
<script>
"use strict"
var isModding = true
var modButton = document.getElementsByTagName("button")[2]
var input = document.getElementsByTagName("input")[0]
var select = document.getElementsByTagName("select")[0]
var selectDebug = document.getElementsByTagName("select")[1]
var checkbox = document.getElementsByTagName("input")[1]
var result = document.getElementsByTagName("div")[4]
var modCreator = 0
document.getElementsByTagName("script")[0].remove()
document.getElementsByTagName("button")[0].addEventListener("click", function () {
exportJSON(false)
})
document.getElementsByTagName("button")[1].addEventListener("click", function () {
exportJSON(true)
})
modButton.addEventListener("click", function () {
if (modCreator === 0) {
document.getElementsByTagName("textarea")[0].value = ""
}
modCreator = !modCreator
if (modCreator) {
document.getElementById("modCreator").removeAttribute("style")
modButton.textContent = "Hide mod creator"
} else {
document.getElementById("modCreator").style.display = "none"
modButton.textContent = "Show mod creator"
}
})
document.getElementsByTagName("button")[3].addEventListener("click", createNewThing)
document.getElementsByTagName("button")[4].addEventListener("click", deleteThing)
document.getElementsByTagName("button")[5].addEventListener("click", function () {
updateScript()
generateScript()
})
document.getElementsByTagName("button")[6].addEventListener("click", importScript)
input.addEventListener("input", changeFunc)
select.addEventListener("change", changeFunc)
selectDebug.addEventListener("change", changeFunc)
checkbox.addEventListener("input", function () {
changeFunc()
if (checkbox.checked) {
document.body.className = "civ2"
} else {
document.body.removeAttribute("class")
}
})
function changeFunc() {
result.removeAttribute("class")
var category = select.value
var checkedBox = checkbox.checked
if (checkedBox) {
document.body.className = "civ2"
}
var obj = checkedBox ? civ2Object : civ1Object
var itemCategory = obj[category]
var inputValue = input.value.trim()
var val = selectDebug.selectedIndex - 1
var categorySingular = category === "policies" ? "policy" : category.slice(0, category.length - 1)
document.getElementsByTagName("button")[3].textContent = ["techs", "units", "resources", "traits"].includes(category) ? "Create a new " + categorySingular : (categorySingular === "achievement" ? "You are unable to create an " : "You are unable to create a ") + categorySingular + " with the mod creator."
if (val > 0) {
var itemsToSearch = val === 1 ? ["name", "displayName", "visible", "icon", "civ", "special", "names", "goods", "res", "mult", "image", "ocean", "score", "desc", "hidden", "category", "startWith", "colorGood", "colorBad", "fractional", "turnToByContext", "meta", "getIcon", "partOf", "subRes", "wonder", "wideIcon", "threexthreeIcon", "cost", "costPerStep", "steps", "messageOnStart", "finalStepCost", "finalStepDesc", "use", "req", "modes", "gizmos", "limitPer", "upkeep", "startMode", "tutorialMesg", "chance", "id"] : ["name", "displayName", "type", "tier", "visible", "icon", "civ", "special", "plural", "names", "goods", "res", "mult", "image", "ocean", "score", "desc", "hidden", "category", "startWith", "colorGood", "colorBad", "fractional", "turnToByContext", "meta", "tick", "getDisplayAmount", "getIcon", "partOf", "subRes", "wonder", "wideIcon", "threexthreeIcon", "cost", "costPerStep", "steps", "messageOnStart", "finalStepCost", "finalStepDesc", "use", "req", "modes", "gizmos", "limitPer", "upkeep", "startMode", "effectsOff", "effects", "tutorialMesg", "chance", "id", "mod", "precededBy", "leadsTo"]
var text = []
if (inputValue.length !== 0) {
var searcher = new MiniSearch({
fields: ["displayName", "desc"],
storeFields: (category === "lands" ? ["name", "displayName", "desc", "icon", "id", "ocean"] : ["name", "displayName", "desc", "icon", "id", "precededBy", "leadsTo"]),
searchOptions: {
boost: { name: 0.15, desc: 0.2, displayName: 0.5 },
prefix: true,
fuzzy: 0.1
}
})
searcher.addAll(itemCategory)
inputValue = searcher.search(inputValue).slice(0, 10)
} else {
inputValue = itemCategory
}
for (var i = 0; i < inputValue.length; i++) {
var search = inputValue[i]
if (val == 3) {
text.push('"' + search.name + '": ' + JSON.stringify(search))
} else {
var thing
var icon = getIcon(category === "lands" ? (search.ocean ? [25, 18, "magixmod"] : [14, 4]) : search.icon, true, checkedBox)
var str = "<header>Display name: " + (!search.displayName ? cap(search.name) : search.displayName) + "</header>\r\nDescription: " + parseDesc(search.desc) + ('Icon: <div tabindex="0" onclick="c(' + search.id + ')" class="icon" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div>') + (search.precededBy ? "\r\nPreceded by: " + parseReq(obj, search.precededBy) : "") + (search.leadsTo ? "\r\nLeads to: " + parseReq(obj, search.leadsTo) : "")
str += "\r\n<pre>"
for (var t = 0; t < itemCategory.length; t++) {
thing = itemCategory[t]
if (thing.id === search.id) {
break
}
}
if (category === "achievements" && !thing.visible) {
str = "<small>Note: this achievement is normally not visible</small>\r\n" + str
}
for (t = 0; t < itemsToSearch.length; t++) {
var prop = itemsToSearch[t]
if (["precededBy", "leadsTo", "icon"].includes(prop)) {
var value = thing[prop]
if (value != null) {
str += prop + ": [" + value.join(", ") + "] (" + obj.descriptions[prop].replaceAll("thing", categorySingular) + ".)\r\n"
}
} else if (!(["name", "displayName", "desc", "icon"].includes(prop))) {
var value = thing[prop]
if (value != null) {
str += prop + ": " + (typeof value === "object" ? JSON.stringify(value) : value) + " (" + obj.descriptions[prop].replaceAll("thing", categorySingular) + ".)\r\n"
}
}
}
text.push(str + "</pre>")
}
}
if (text.length !== 0) {
if (val == 3) {
var joined = text.join(",\r\n ")
result.textContent = "{\r\n " + joined.slice(0, joined.length - 1) + "},\r\n}"
result.className = "mono"
} else {
result.innerHTML = "<i><strong>Results:</strong></i> \r\n" + text.join("-------------------------\r\n")
result.removeAttribute("class")
}
} else {
result.innerHTML = "<strong>No results found</strong>"
}
} else if (val == -1) {
var text = []
if (inputValue.length !== 0) {
var searcher = new MiniSearch({
fields: ["displayName", "desc"],
storeFields: (category === "lands" ? ["name", "displayName", "desc", "icon", "ocean", "id"] : ["name", "displayName", "desc", "icon", "leadsTo", "hidden", "visible", "id"]),
searchOptions: {
boost: { name: 0.05, desc: 0.2, displayName: 0.5 },
prefix: true,
fuzzy: 0.1
}
})
searcher.addAll(itemCategory)
inputValue = searcher.search(inputValue).slice(0, 10)
} else {
inputValue = itemCategory
}
for (var i = 0; i < inputValue.length; i++) {
var search = inputValue[i]
var icon = getIcon(category === "lands" ? (search.ocean ? [25, 18, "magixmod"] : [14, 4]) : search.icon, true, checkedBox)
text.push((category === "achievements" && !search.visible ? "<small>Note: this achievement is normally not visible</small>\r\n<header>Display name: " : "<header>Display name: ") + (category === "policies" || category === "lands" ? cap(search.name) : search.displayName) + '</header><div tabindex="0" onclick="c(' + search.id + ')" class="icon large" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div>')
}
result.innerHTML = (text.length !== 0 ? "<i><strong>Results:</strong></i> \r\n" + text.join("\r\n-------------------------\r\n") : "<strong>No results found</strong>")
result.removeAttribute("class")
} else {
var text = []
if (inputValue.length !== 0) {
var searcher = new MiniSearch({
fields: ["displayName", "desc"],
storeFields: (category === "lands" ? ["name", "displayName", "desc", "icon", "ocean", "id"] : ["name", "displayName", "desc", "icon", "leadsTo", "hidden", "visible", "id"]),
searchOptions: {
boost: { name: 0.05, desc: 0.2, displayName: 0.5 },
prefix: true,
fuzzy: 0.1
}
})
searcher.addAll(itemCategory)
inputValue = searcher.search(inputValue).slice(0, 10)
} else {
inputValue = itemCategory
}
for (var i = 0; i < inputValue.length; i++) {
var search = inputValue[i]
var icon = getIcon(category === "lands" ? (search.ocean ? [25, 18, "magixmod"] : [14, 4]) : search.icon, true, checkedBox)
text.push((category === "achievements" && !search.visible ? "<small>Note: this achievement is normally not visible</small>\r\n<header>Display name: " : "<header>Display name: ") + (category === "policies" || category === "lands" ? cap(search.name) : search.displayName) + "</header>\r\nDescription: " + parseDesc(search.desc) + ('Icon: <div tabindex="0" onclick="c(' + search.id + ')" class="icon" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div>') + (search.leadsTo ? "\r\nLeads to: " + parseReq(obj, search.leadsTo) : ""))
}
result.innerHTML = (text.length !== 0 ? "<i><strong>Results:</strong></i> \r\n" + text.join("\r\n-------------------------\r\n") : "<strong>No results found</strong>")
result.removeAttribute("class")
}
}
String.prototype.replaceAll = function (search, replacement) {
return this.replace(new RegExp(search, "g"), replacement)
}
function parseDesc(value) {
return value == null || value.length === 0 ? "none\r\n" : ('<div class="par">' + ((value
.replaceAll("]s", "s]"))
.replace(/\[(.*?)\]/gi, parseFunc))
.replaceAll("http(s?)://", "http$1:#SLASH#SLASH#")
.replaceAll("//", '</div><div class="par">')
.replaceAll("#SLASH#SLASH#", "//")
.replaceAll("@", '</div><div class="par bulleted">')
.replaceAll("<>", '</div><div class="divider"></div><div class="par">') + "</div>")
}
function c(id, category) {
if (category == null) {
category = select.value
}
var civ2 = checkbox.checked
var objc = civ2 ? civ2Object : civ1Object
var obj = objc[category]
for (var i = 0; i < obj.length; i++) {
var t = obj[i]
if (t.id === id) {
var tIcon = t.icon
var icon = getIcon(tIcon, true, civ2)
var text = "<button onclick='changeFunc()'>Back</button>" + (category === "achievements" && !t.visible ? "<br><small>Note: this achievement is normally not visible</small><br><h3>Display name: " : "<h3>Display name: ") + (category === "policies" || category === "lands" ? cap(t.name) : t.displayName) + "</h3>Description: " + parseDesc(t.desc).replace("\r\n", "<br>") + (category === "lands" ? "" : 'Icon layout: <div class="icon noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>')
if (t.wideIcon) {
var icon = getIcon(t.wideIcon, true, civ2)
text += '<div class="wide noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>'
}
if (t.threexthreeIcon) {
var icon = getIcon(t.threexthreeIcon, true, civ2)
text += '<div class="triple noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br><br><br><br><br><br>'
}
if (t.icon.length > 3) {
var i0 = null, i1 = null
for (var l = 0; l < tIcon.length; l++) {
var value = tIcon[l]
if (typeof value === "string") {
icon = getIcon([i0, i1, value], true, civ2)
text += '<div class="icon noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>'
i0 = null
i1 = null
} else if (i1 != null) {
icon = getIcon([i0, i1], true, civ2)
text += '<div class="icon noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>'
i0 = value
i1 = null
} else if (i0 !== null) {
i1 = value
} else {
i0 = value
}
}
if (i1 !== null) {
icon = getIcon([i0, i1], true, civ2)
text += '<div class="icon noclick shadow" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div><br>'
}
}
text += "<br>Raw name: " + t.name + "<br>Type: " + t.type + (t.precededBy ? "<br>Preceded by: " + parseReq(objc, t.precededBy) : "") + (t.leadsTo ? "<br>Leads to: " + parseReq(objc, t.leadsTo) : "") + (t.precededBy && (parseReq(objc, t.req, true) !== "nothing") ? "<br>Also requires: " + parseReq(objc, t.req, true) : "") + (t.steps ? "<br>Steps: " + t.steps : "") + "<br>Internal ID: " + id
var c = t.cost
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Cost: " + parseRes(objc, c)
}
c = t.costPerStep
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Cost per step: " + parseRes(objc, c)
}
c = t.costPerStep2
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Cost per step after 25 steps: " + parseRes(objc, c)
}
c = t.finalStepCost
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Final step cost: " + parseRes(objc, c)
}
c = t.messageOnStart
if (c != null) {
text += "<br>Starting message: " + parseDesc(c)
}
c = t.finalStepDesc
if (c != null) {
text += "<br>Final step popup message: " + parseDesc(c)
}
c = t.use
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Uses: " + parseRes(objc, c)
}
c = t.limitPer
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<br>Limited to every: " + parseRes(objc, c) + " (rounded up)"
}
c = t.names
if (c && c.length !== 0) {
text += "<br>Names: " + c.join(", ")
}
c = t.ocean
if (category === "lands") {
text += "<br>Type of land: " + (c ? '<span class="ocean">ocean</span>' : '<span class="land">normal land</span>')
}
c = t.startWith
if (c) {
text += t.startWith === true ? "<br>Is avaliable at the start: yes" : "<br>Amount given at the start: " + c
}
c = t.skip || (t.req && (t.req.tribalism === false))
if (c) {
text += "<br>Is only obtainable under specific conditions: yes"
}
c = t.getDisplayAmount
if (c) {
text += "<br>Has a customized display amount: yes"
}
c = t.getIcon
if (c) {
text += "<br>Has a custom icon function: yes"
}
c = t.subRes
if (c) {
text += "<br>Subresources: " + parseRes2(objc, c)
}
c = t.meta
if (c) {
text += "<br>Contains other resources within: yes"
}
c = t.partOf
if (c && c != "false") {
text += "<br>Is interally part of: " + c
}
c = t.category
if (c) {
text += "<br>Part of displayed category: " + (c === "debug" ? "<strong>debug</strong>" : c)
}
c = t.chance
if (c) {
text += (category === "techs" ? "<br>Chance multiplier for rolling this tech: " : "<br>Chance (lower means more likely to get): ") + c
}
var e = t.effects
if (e) {
var funcs = noticeEffects(e, "function", 0) + noticeEffects(e, "tick", 0)
var convert = noticeEffects(e, "convert", 0)
var gather = noticeEffects(e, "gather", 0)
var mult = noticeEffects(e, "mult", 0)
var provided = noticeEffects(e, "provide", 0) + noticeEffects(e, "provide res", 0)
text += "<br>Effect count: " + e.length + " (" + funcs + (funcs === 1 ? " function, " : " functions, ") + convert + (convert === 1 ? " conversion of items, " : " conversions of items, ") + gather + (gather === 1 ? " thing to gather, " : " things to gather, ") + mult + (mult === 1 ? " multiplier, " : " multipliers, ") + provided + (provided === 1 ? " resource provider)" : " resource providers)")
if (provided > 0) {
text += "<br>Provides: "
text += parseRes(objc, Object.assign(...noticeEffects(e, "provide res", 1, "what").concat(noticeEffects(e, "provide", 1, "what")))) // Sorry Internet Explorer, but we ain't supporting ya for this wiki (also yeah, this is some pretty weird spread operation, eh?)
}
if (category === "units") {
var reqs = parseReq(objc, t.req)
if (reqs !== "nothing") {
text += "<br>Unlocks after you get " + reqs
}
var breakdown = breakDownEffects(objc, e)
if (breakdown.length !== 0) {
text += "<br>Effect breakdown: <ul>"
c = t.upkeep
if (c != null && Object.getOwnPropertyNames(c).length !== 0) {
text += "<li>has an upkeep of " + parseRes(objc, c) + "</li>"
}
for (var b = 0; b < breakdown.length; b++) {
text += "<li>" + breakdown[b] + "</li>"
}
text += "</ul>"
}
}
}
if (t.modes) {
var modeKeys = Object.keys(t.modes)
var modeLen = modeKeys.length
text += "<br>Modes (" + modeLen + "):<ul>"
for (var m = 0; m < modeLen; m++) {
var key = modeKeys[m]
var mode = t.modes[key]
var icon = mode.icon ? getIcon(mode.icon, true, civ2) : null
text += "<li><strong>" + mode.name + '</strong><ul><li>Internal ID: <span class="mono">' + key + "</span></li><li>Uses: " + parseRes(objc, mode.use) + "</li><li>Requires: " + parseReq(objc, mode.req) + "</li><li>Description: " + parseDesc(mode.desc) + '</li><li>Icon: ' + (icon ? '<div class="icon noclick" style="background-image:' + icon[0] + ';background-position:' + icon[1] + '"></div>' : 'none') + '</li></ul></li>'
}
text += "</ul>"
}
if (category === "techs" || category === "traits") {
var indirect = noticeEffects(e, t.name, 2, objc, "req")
if (indirect.length !== 0) {
text += "<br>Unlocks: " + indirect.join(", ")
}
indirect = noticeEffects(e, t.name, 2, objc, "modes")
if (indirect.length !== 0) {
text += "<br>Unlocks modes for: " + indirect.join(", ")
}
indirect = noticeEffects(e, t.name, 3, objc)
if (indirect.length !== 0) {
text += "<br>Causes effects for: " + indirect.join(", ")
}
}
result.className = "nopre"
result.innerHTML = text
}
}
}
function breakDownEffects(obj, effects) {
var result = []
for (var i = 0; i < effects.length; i++) {
var effect = effects[i]
var type = effect.type
var req = effect.req
var info = ""
if (type === "waste") {
info = "will waste"
} else if (type === "gather") {
if (effect.what) {
info = "gathers " + parseRes(obj, effect.what)
}
} else if (type === "convert") {
info = "converts " + parseRes(obj, effect.from) + " into " + parseRes(obj, effect.into)
} else if (type === "mult") {
info = "has its production rate multiplied by " + effect.value
} else if (type === "addFree" && effect.what.worker) {
info = "each idle worker will work at " + (effect.what.worker * 100) + "% the speed of this unit for free"
}
if (req && Object.getOwnPropertyNames(req).length !== 0) {
info += " if you have " + parseReq(obj, req)
}
var chance = effect.chance
if (chance) {
info += " with a chance of " + (chance * 100) + "%"
}
var context = effect.context
if (context) {
info += ' within the internal context of <span class="mono">' + context + "</span>"
}
var notMode = effect.notMode
if (notMode) {
info += ' if the mode is not <span class="mono">' + notMode + "</span>"
}
var mode = effect.mode
if (mode) {
info += ' for the mode ID <span class="mono">' + mode + "</span>"
}
var max = effect.max
if (max) {
info += " with its gathering capped at " + max
}
var every = effect.every
if (every && every !== 1) {
info += " every " + every + " ticks"
}
if (info) result.push(info)
}
return result
}
function parseReq(obj, reqToSearch, opposite) {
if (reqToSearch == null) {
return "nothing"
}
if (reqToSearch.length) {
var arr = reqToSearch
reqToSearch = {}
for (var i = 0; i < arr.length; i++) {
reqToSearch[arr[i]] = true
}
}
var keys = Object.getOwnPropertyNames(reqToSearch)
var keyLen = keys.length
var end = keyLen - 1
var result = []
var techs = obj.techs
var techLen = techs.length
var success = false
for (var l = 0; l < keyLen; l++) {
var key = keys[l]
for (var o = 0; o < techLen; o++) {
var tech = techs[o]
if (tech.name === key) {
if (opposite && reqToSearch[key]) continue
result.push((reqToSearch[key] ? "" : "a lack of ") + '<u onclick="c(' + tech.id + ",'techs')\">" + tech.displayName + "</u>")
break
}
}
}
techs = obj.traits // traits now but whatever
techLen = techs.length
for (var l = 0; l < keyLen; l++) {
var key = keys[l]
for (var o = 0; o < techLen; o++) {
var tech = techs[o]
if (tech.name === key) {
if (opposite && reqToSearch[key]) continue
result.push((reqToSearch[key] ? "" : "a lack of ") + '<u onclick="c(' + tech.id + ",'traits')\">" + tech.displayName + "</u>")
break
}
}
}
if (!opposite) {
techs = obj.policies // now policies
techLen = techs.length
for (var l = 0; l < keyLen; l++) {
var key = keys[l]
for (var o = 0; o < techLen; o++) {
var tech = techs[o]
if (tech.name === key) {
var state = reqToSearch[key]
result.push('<u onclick="c(' + tech.id + ",'policies')\">" + tech.displayName + "</u>" + (state === "on" ? " enabled" : (state === "off" ? " disabled" : (" is set to " + state))))
break
}
}
}
}
var resultLen = result.length
if (resultLen === 0) {
return "nothing"
} else if (resultLen === 1) {
return result[0]
} else if (resultLen === 2) {
return result[0] + " and " + result[1]
}
return (result.slice(0, resultLen - 1).join(", ") + ", and " + result[resultLen - 1])
}
function parseRes(obj, resToSearch) {
if (resToSearch == null) {
return "nothing"
}
var keys = Object.getOwnPropertyNames(resToSearch)
var keyLen = keys.length
if (keyLen !== 0) {
var separator = keyLen === 2 ? " and " : ", and "
var end = keyLen - 1
var text = ""
var resources = obj.resources
var resLen = resources.length
for (var l = 0; l < keyLen; l++) {
var key = keys[l]
for (var o = 0; o < resLen; o++) {
var res = resources[o]
if (res.name === key) {
text += (l === 0 ? "" : (l === end ? separator : ", ")) + resToSearch[key] + ' <u onclick="c(' + res.id + ",'resources')\">" + res.displayName + "</u>"
break
}
}
}
return text
}
return ""
}
function parseRes2(obj, keys) {
var keyLen = keys.length
if (keyLen !== 0) {
var separator = keyLen === 2 ? " and " : ", and "
var end = keyLen - 1
var text = ""
var resources = obj.resources
var resLen = resources.length
for (var l = 0; l < keyLen; l++) {
var key = keys[l]
for (var o = 0; o < resLen; o++) {
var res = resources[o]
if (res.name === key) {
text += (l === 0 ? "" : (l === end ? separator : ", ")) + ' <u onclick="c(' + res.id + ",'resources')\">" + res.displayName + "</u>"
break
}
}
}
return text
}
return ""
}
function noticeEffects(effects, type, mode, specificData, propertyKey) {
if (mode === 0) { // Determine the amount of effects of this type
var num = 0
for (var i = 0; i < effects.length; i++) {
var e = effects[i]
if (e.type === type) {
num++
}
}
return num
} else if (mode === 1) { // Return all effects of this type, returning a specific property in it if specified
var result = []
for (var i = 0; i < effects.length; i++) {
var e = effects[i]
if (e.type === type) {
result.push(specificData ? e[specificData] : e)
}
}
return result
} else if (mode === 2) { // Search for something specific being a requirement of something else, using specificData as the data object and propertyKey for the key
var result = []
var toIterateOver = ["units", "policies"]
for (var n = 0; n < 2; n++) {
var typeKey = toIterateOver[n]
var things = specificData[typeKey]
for (var i = 0; i < things.length; i++) {
var thing = things[i]
var req = thing[propertyKey]
if (req) {
if (propertyKey === "req") {
if (req[type]) {
result.push('<u onclick="c(' + thing.id + ",'" + typeKey + "')\">" + thing.displayName + "</u>")
break
}
} else {
var props = Object.getOwnPropertyNames(req)
var success = false
for (var m = 0; m < props.length; m++) {
var r = req[props[m]].req
if (r && r[type]) {
result.push('<u onclick="c(' + thing.id + ",'" + typeKey + "')\">" + thing.displayName + "</u>" + ' (with ID <span class="mono">' + props[m] + "</span>)")
success = true
break
}
}
if (success) {
break
}
}
}
}
}
return result
} else if (mode === 3) { // Search for something specific being a requirement of something else, using specificData as the data object, but specifically for effects
var result = []
var toIterateOver = ["techs", "units", "traits", "policies"]
for (var n = 0; n < 4; n++) {
var typeKey = toIterateOver[n]
var things = specificData[typeKey]
for (var i = 0; i < things.length; i++) {
var thing = things[i]
var effects = thing.effects
if (effects) {
var firstTime = true
for (var e = 0; e < effects.length; e++) {
var effect = effects[e]
var req = effect.req
if (req && req[type]) {
if (effect.mode) {
result.push('<u onclick="c(' + thing.id + ",'" + typeKey + "')\">" + thing.displayName + "</u>" + ' (for mode ID <span class="mono">' + effect.mode + "</span>)")
} else if (firstTime) {
firstTime = false
result.push('<u onclick="c(' + thing.id + ",'" + typeKey + "')\">" + thing.displayName + "</u>")
}
}
}
}
}
}
return result
}
}
function cap(str) {
return str == null || str.length === 0 ? "None" : str[0].toUpperCase() + str.slice(1)
}
function parseFunc(str) {
var comma = str.indexOf(",")
return "<strong>" + cap(str.slice(comma === -1 ? 1 : comma + 1, str.length - 1)) + "</strong>"
}
var iconScale = 1
function getIcon(icon, split, civ2) {
//returns a style string
/*examples for the icon parameter:
[1,2] - returns the icon at 1,2 in the default spritesheet
[1,2,3,4] - returns the icon at 1,2, overlaid on top of the icon at 3,4 in the default spritesheet
[1,2,"mySheet"] - returns the icon at 1,2 in the custom spritesheet with id "mySheet"
[1,2,"mySheet",3,4] - returns the icon at 1,2 in the custom spritesheet with id "mySheet" overlaid on top of the icon at 3,4 in the default spritesheet
*/