-
Notifications
You must be signed in to change notification settings - Fork 0
/
charactertracking.html
1783 lines (1265 loc) · 59.3 KB
/
charactertracking.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
<style>
#tracking * {
line-height: 16px !important;
white-space: normal;
}
#tracking *:focus{
outline: none !important;
}
html[data-outdoors='1'] #flexiContainer .dimmedScene,
html[data-outdoors='1'] #flexiContainer.indexcards .dimmedScene > .sceneheading {
border-color: #ddd !important;
border-style: dotted !important;
}
html[data-outdoors='1'] #flexiContainer .dimmedScene > .sceneheading{
color: #ddd !important;
}
#characterButton:is(.red, .orange, .yellow, .green, .teal, .cyan, .blue, .purple, .magenta, .pink, .brown, .grey, .black, .white) {
background: none !important;
opacity: 1 !important;
transition: none !important;
}
#characterButton.red > svg path{
fill: hsla(var(--red),100%) !important;
}
#characterButton.orange > svg path{
fill: hsla(var(--orange),100%) !important;
}
#characterButton.yellow > svg path{
fill: hsla(var(--yellow),100%) !important;
}
#characterButton.green > svg path{
fill: hsla(var(--green),100%) !important;
}
#characterButton.teal > svg path{
fill: hsla(var(--teal),100%) !important;
}
#characterButton.cyan > svg path{
fill: hsla(var(--cyan),100%) !important;
}
#characterButton.blue > svg path{
fill: hsla(var(--blue),100%) !important;
}
#characterButton.purple > svg path{
fill: hsla(var(--purple),100%) !important;
}
#characterButton.magenta > svg path{
fill: hsla(var(--magenta),100%) !important;
}
#characterButton.pink > svg path{
fill: hsla(var(--pink),100%) !important;
}
#characterButton.brown > svg path{
fill: hsla(var(--brown),100%) !important;
}
#characterButton.black > svg path{
fill: hsla(var(--black),100%) !important;
}
#characterButton.white > svg path{
fill: hsla(var(--white),100%) !important;
}
#characterButton.grey > svg path{
fill: hsla(var(--grey),100%) !important;
}
.section:not(.level1).dimmedSection:hover>.section-heading:not(#flexiContainer.sectionCards .section-heading){
background-color: rgba(40,40,40,1) !important;
}
.rightfloat{
float: right;
width: 50% !important;
height: 100% !important;
padding-right: 0px !important;
}
#tracking button {
text-align: right;
}
.buttonIsActive {
opacity: 100% !important;
}
svg {
transition: 0.2s !important;
pointer-events: none; /* Or else the icon blocks itself from being clicked. Very weird. */
}
.buttonIsActive svg {
transform: scale(0.7) translateY(2px) !important;
pointer-events: none; /* Or else the icon blocks itself from being clicked. Very weird. */
}
#indexCardButton.buttonIsActive svg {
transform: scale(1) translate(0px, 0px) !important;
}
.bullets {
margin-left: 20px;
}
.bullets::before{
content: "•";
margin-left: -20px;
}
#upperframe, #trackingoutro{
max-width: 560px;
margin-left: auto;
margin-right: auto;
}
#selectedCharacterName, #indexCardText{
font-size: 9px;
font-weight: 500;
line-height: 10px;
text-transform: uppercase;
transform: translateY(calc(-100% - 23px)) translateX(calc(-50% + 16px));
width: 60px !important;
overflow: hidden;
text-overflow: ellipsis;
pointer-events: none; /* Or else the icon blocks itself from being clicked. Very weird. */
}
#indexCardText{
transform: translateY(calc(-100% - 29px)) translateX(calc(-50% + 16px));
}
#indexCardBkg{
padding-left: 50px !important;
padding-top: 3px !important;
font-size: 9px;
font-weight: 500;
line-height: 12px;
text-transform: uppercase;
color: rgba(255,255,255,0.4)
}
/*@todo remmed out all these SELECT stuffs*/
#selectlistparent{
width: 50% ;
}
select, select * {
height: 100% !important;
width: 100% !important;
border-radius: 6px !important;
border: 1px inset;
overflow-y: scroll;
overflow-x: hidden;
font-size: 14px !important;
line-height: 18px !important;
font-weight: 500;
padding: 10px !important;
list-style-position: outside;
}
#tracking select {
min-height: 500px;
}
option {
line-height: 20px !important;
width: 100% !important;
padding: 4px !important;
}
option:nth-of-type(even){
background: #eee;
}
option:checked{
background: #027aff !important;
background-color: #027aff !important;
border: 1px gold dotted
}
#tracking .normalWindowText{
width: 50%;
float: left;
padding-right: 15px !important;
}
.normalWindowText li {
list-style-position: outside !important;
}
ul {
margin-left: -20px;
}
li {
margin-top: 6px !important;
display: list-item;
list-style-position: outside !important;
}
#okbutton2, #deselectAllCharacters {
font-size: 14px;
margin-top: 15px;
margin-bottom: 15px !important;
padding: 5px 0px 5px auto;
}
.scriptTextInWindow {
font-family:'Courier Prime','Courier New', Courier, monospace;
font-size: 13.5px !important;
font-weight: bold;
letter-spacing: -0.3px;
padding-bottom: 0px !important;
padding-top: 1px !important;
line-height: 16px !important;
}
/* html[data-outdoors='1'] #flexiContainer .section.dimmedSection{
color: purple
} */
html[data-outdoors='1'] .dimmedSection > .section-heading:not(#flexiContainer.indexCards .section-heading),
html[data-outdoors='1'] #flexiContainer .dimmedSection > .section-heading {
color: #ddd !important;
opacity: 1;
border: 1px dotted #ddd !important;
}
</style>
<div id="tracking" class="settingsWindow" style="display: none;" onblur="toggleTrackingContainer()">
<div id="selectlistparent" class="rightfloat" style="height: calc(100% - 40px) !important; text-align: right !important;">
<select style="height: 100% !important;" multiple onchange="updateFilter()" id="characterMenuList"></select><br/>
<button class="generalButtonStyle" id="deselectAllCharacters" onclick="deselectAllCharacters()">Deselect all</button>
<!--p id="okbuttonpara2"-->
<button class="generalButtonStyle" id="okbutton2" type="button" onclick="toggleTrackingContainer()">Close</button><!--/p-->
</div>
<div id="trackertext"><p class="normalWindowText"><span class="headline"><br/>Track characters</span><br/><br/>
Select characters in the list to highlight scenes where they appear.<br/><br/>
CMD + click to select multiple.<br/><br/>
Selecting more than one name will highlight scenes where ALL characters are present.<br/><br/>
</p>
</div>
</div>
<script>
var iCameFromToggleCharacter = false
var iCameFromMenu = false
var scenesWithCharacters = []
var searchBoxDelay
var globalScenesWithDialog = []
function collectCharacters(preselectedCharacter) {
// important note: when this was part of the plugin back-and-forth, the plugin ended this by calling updateFilter()
// since I do not call updateFilter from the end of this function, be vigilant about whether this may case problems
// (and no, I don't dare calling updateFilter from here, in case this function should be able to be called without)
mylog()
console.time("collectCharacters2023")
if(!outline) return
let removal = userDefault.excludeVoiceOvers ? /(\(.+\))$/ : ""
let allCharacters2023 = lines.filter(line => line.typeAsString == "Character" && !line.omitted).map(line =>
line.string.replace(/^\^*@*/, "") /* removes dual dialog ^ or forced dialog @ */
.replace(/\'/g, `’`) /* replaces that pesky apostrophe that creates so much problems */
.replace(removal, "").trim()) /* if characters with extensions count as the main character, remove the extension */
//sort the characters by how many times they appear in the script
const characterCounts = allCharacters2023.reduce((acc, val) => {
if (!acc[val]) {
acc[val] = 1;
} else {
acc[val]++;
}
return acc;
}, []);
const sortedCharacters = Object.keys(characterCounts).sort((a, b) => {
return characterCounts[b] - characterCounts[a];
});
//collect all characters in each scene, with different options
let outlineElementsWithCharactersDialogOnly = []
let outlineElementsWithCharactersIncludingAction = []
let outlineElementsWithCharactersInSynopsisOnly = []
let scenesWithDialog2023 = []
let outlineElementNumber = -1
let trimmedName
let wordsplitters = /[,.:;!?\)\(\s\")]+/ //for now, I have removed apostrophes \' from wordsplitters to catch names like O'Neil
for (line of lines){
//if (line.omitted) continue
if (line.typeAsString == "Heading" || line.typeAsString == "Section"){
outlineElementNumber ++
outlineElementsWithCharactersDialogOnly[outlineElementNumber] = []
outlineElementsWithCharactersIncludingAction[outlineElementNumber] = []
outlineElementsWithCharactersInSynopsisOnly[outlineElementNumber] = []
scenesWithDialog2023[outlineElementNumber] = []
}
if (outlineElementNumber < 0) continue
if (line.typeAsString == "Character" && !line.omitted){
trimmedName = line.string.replace(/^@/, "").toUpperCase().replace(removal, "").replace(/\'/, "’").trim()
if(sortedCharacters.some(character => character.toUpperCase() == trimmedName.toUpperCase())){
if (!outlineElementsWithCharactersDialogOnly[outlineElementNumber]?.includes(trimmedName)) {
outlineElementsWithCharactersDialogOnly[outlineElementNumber].push(trimmedName)
}
if (!outlineElementsWithCharactersIncludingAction[outlineElementNumber]?.includes(trimmedName)) {
outlineElementsWithCharactersIncludingAction[outlineElementNumber].push(trimmedName)
}
}
alsoCollectDialog()
}
if (line.typeAsString == "Action" && !line.omitted){
sortedCharacters.forEach(character => {
apostrophedCharacter = character.replace(/’/g, `\'`) //replacing character BACK to normal apostrophe when comparing to avoid repeating for every word
if (compareThese(line.string, apostrophedCharacter)) {
if (!outlineElementsWithCharactersIncludingAction[outlineElementNumber]?.includes(character)) {
outlineElementsWithCharactersIncludingAction[outlineElementNumber].push(character.toUpperCase());
}
}
})
}
if (documentSetting.trackingIncludesSynopsis && line.typeAsString == "Synopse"){
sortedCharacters.forEach(character => {
apostrophedCharacter = character.replace(/’/g, `\'`) //replacing character BACK to normal apostrophe when comparing to avoid repeating for every word
if (compareThese(line.string, apostrophedCharacter)) {
if (!outlineElementsWithCharactersInSynopsisOnly[outlineElementNumber]?.includes(character)) {
outlineElementsWithCharactersInSynopsisOnly[outlineElementNumber].push(character);
}
}
})
}
}
function alsoCollectDialog(){
if (!($id("notepanel").classList.contains("expanded") && $(".selectedtab").classList.contains("dialogtab"))) return
let additionalLines = 0
let currentLine = lines.indexOf(line)
while (["Character", "Dialogue", "Parenthetical"].includes(lines[currentLine + additionalLines]?.typeAsString)){
scenesWithDialog2023[outlineElementNumber].push({
"character": trimmedName,
"position": lines[currentLine + additionalLines].position,
"string": lines[currentLine + additionalLines].string,
"typeAsString": lines[currentLine + additionalLines].typeAsString,
"omitted": lines[currentLine + additionalLines].omitted,
"currentLine": lines[currentLine + additionalLines],
})
additionalLines ++
}
}
function compareThese(string, character){
if (!string.toLowerCase().includes(character.toLowerCase())) return false //to avoid having to loop through all words if not even present
// FIRST, if the character has multiple words, let not split the line but compare directly.
// This will demand at least one uppercase letter in the match (to avoid matching "OLD BROWN" with "his old brown hat")
// which unfortunately means not matching "the third thug" in action with a speaking character "THE THIRD THUG"
// This seems like a reasonable trade-off for now, and will catch "Dr. Zjivago" and "Sheila's mother", both of which are more important.
if (character.includes(" ")){
// if (string.toLowerCase().includes(character.toLowerCase)) return true
const regex = new RegExp(character, 'i');
const match = string.match(regex);
if (match && match[0] != match[0].toLowerCase()) {
return true;
}
}
//THEN, more time-consuming word-by-word comparisons for single-word characters
let words = string.split(wordsplitters)
if (words.includes(character)) return true //spelling is exactly as once captured (text: McLaren, original: @McLaren)
if (words.includes(toInitialsCase(character))) return true //spelling is like a name, regardless of case when captured. (text: Mclaren)
if (words.includes(character.toUpperCase())) return true //character is typed in caps now but perhaps not when captured (text: MCLAREN)
//Below is a test to see if we can also get McLaren as well as McLAREN, and if so at what cost?
if (words.some(word => (word.charAt(0) + word.slice(1).toLowerCase()) === (character.charAt(0) + character.slice(1).toLowerCase()))) return true;
return false
}
//Finally, here's an array with characters in both action AND synopsis
let outlineElementsWithChactersAnywhere =
outlineElementsWithCharactersIncludingAction.map((characters, index) =>
characters.concat(outlineElementsWithCharactersInSynopsisOnly[index])
)
console.timeEnd("collectCharacters2023")
//For now, in order to be able to use old code, let's merge this into the old variable names! Aug 2023
allCharacters = sortedCharacters
globalAllCharacters = allCharacters
scenesWithCharactersProxy =
// documentSetting.trackingIncludesSynopsis ? outlineElementsWithCharactersInSynopsisOnly : outlineElementsWithCharactersIncludingAction
documentSetting.trackingIncludesSynopsis ? outlineElementsWithChactersAnywhere : outlineElementsWithCharactersIncludingAction
//Here's the old code:
//from here, we should potentially make it a new function called applycharactes
if ((!scenesWithCharacters.length) || (scenesWithCharacters != scenesWithCharactersProxy)){
let previouslySelectedCharacters = Array.of(preselectedCharacter) || null
let reselectThese = []
let itemNumber = 0
scenesWithCharacters = scenesWithCharactersProxy //workaround to make this globally accessible
//remember what characters in the menu were selected before
if ($id("characterMenuList").selectedOptions){
previouslySelectedCharacters = Array.from($id("characterMenuList").selectedOptions)
for (character of previouslySelectedCharacters){
reselectThese.push(character.value)
}
}
//populating/re-populating the character menu and track dialog menu (in case something changed)
$id("characterMenuList").innerHTML = ""
$id("allDialogFor").innerHTML = "<option class='menuitem' value='ALL'>ALL</option>"
for (item of allCharacters){
itemNumber ++
$id("characterMenuList").innerHTML +=
`<option class='menuitem' value='${item}'>
${itemNumber<10 ? `(${itemNumber}) ` : ` `}
${item}
</option>`
$id("allDialogFor").innerHTML += `
<option class='menuitem' value="${item}">
${item}
</option>`
}
//and reselect those we remembered previously
if (reselectThese.length){
for (character of reselectThese){
for (i = 0; i < characterMenuList.length; i++){
if (characterMenuList[i].value == character){
characterMenuList.options[i].selected = true;
}
}
}
}
}
if (iCameFromToggleCharacter && allCharacters.length > 0){
toggleSoloCharacter(iCameFromToggleCharacter[0], iCameFromToggleCharacter[1])
}
if (iCameFromMenu){
iCameFromMenu = false
trackingMenu()
}
if(trackingContainerVisibility == 1){
document.getElementById("characterMenuList").focus()
}
mylog("end of collect")
// FINALLY, added for 2023 version:
// make the dialog global so as to be available for the dialogpanel
globalScenesWithDialog = scenesWithDialog2023
}
function alsoFillColorDropdown(){
let dropdown = "<option>(None)</option>"
let alreadySelected = false
for (let color of colorsArray){
if (color == "Remove Color" || color == "Special"){continue}
if ($(".scene." + color.toLowerCase() + ", .section." + color.toLowerCase())){
dropdown += "<option>" + color + "</option>"
if ([...document.getElementById("flexiContainer").classList].includes(color.toLowerCase())){
alreadySelected = color
}
}
}
document.getElementById("colorDropdown").innerHTML = dropdown
document.getElementById("colorDropdown").value = alreadySelected || "(None)"
}
function updateFilter(scenesWithCharactersProxy){
mylog()
let allScenes = $$('.scene')
let allSections = $$('.section')
//if (scenesWithCharactersProxy) {scenesWithCharacters = scenesWithCharactersProxy} //again making it global
let selectedCharacters = $id("characterMenuList").selectedOptions
if (selectedCharacters.length){
for (section of allSections){section.classList.add("dimmedSection")}
for (scene of allScenes){scene.classList.add("dimmedScene")}
for (i=0; i<outline.length; i++){
//if (outline[i].typeAsString == "Heading" || outline[i].typeAsString == "Section"){
let num = i
let removeDim = false
if (scenesWithCharacters[num]){
removeDim = true
for (currentCharacter of selectedCharacters){
if (!scenesWithCharacters[num].includes(currentCharacter.value.toUpperCase())) {
removeDim = false
}
}
}
if (removeDim == true){$id(i).classList.remove("dimmedScene")}
if (removeDim == true){$id(i).classList.remove("dimmedSection")}
//}
}
}
else
{
for (scene of allScenes){scene.classList.remove("dimmedScene")}
for (section of allSections){section.classList.remove("dimmedSection")}
}
mylog("dimming is done")
if (characterMenuList.selectedIndex == -1){
document.getElementById("characterButton").classList.remove("buttonIsActive")
document.getElementById("selectedCharacterName").innerHTML = ""
}else{
document.getElementById("characterButton").classList.add("buttonIsActive")
let selectedCharacters = document.getElementById("characterMenuList").selectedOptions
document.getElementById("selectedCharacterName").innerHTML = ""
for (currentCharacter of selectedCharacters){
document.getElementById("selectedCharacterName").innerHTML += currentCharacter.value + "<br/>"
}
}
updateSelectionInfo()
mylog("end of UpdateFilter")
}
function deselectAllCharacters() {
characterMenuList.selectedIndex = -1;
if($id("trackingMenu")){trackingMenu()}
updateFilter()
}
function toggleSoloCharacter(theKey, actualName) {
mylog()
mylog("theKey is " + theKey + "")
if (!characterMenuList || characterMenuList.length == 0) {
iCameFromToggleCharacter = [theKey, actualName]
collectCharacters()
return
}
if(actualName){
for (theKey = 0; theKey < characterMenuList.length; theKey ++) {
if (actualName.toUpperCase() == characterMenuList.options[theKey].value.toUpperCase()){
theKey ++ //because soon to be reduced by one in the old code
break
}
}
}
theKey -- //shifts one down to zero-based array, but shortcuts starting with 1
if (event && (event.shiftKey || event.metaKey)){
let a = characterMenuList.options[theKey].selected == false;
characterMenuList.options[theKey].selected = a;
}
else
{
if (characterMenuList.selectedIndex != theKey){
characterMenuList.selectedIndex = theKey
}else{
characterMenuList.selectedIndex = -1;
}
}
iCameFromToggleCharacter = false
mylog("exiting, just before sending to updateFilter()")
if($id("trackingMenu")){trackingMenu()}
updateFilter()
}
function simulateAltClick(){
let theSelections = document.getElementById("colorDropdown").selectedOptions
let theSelection = theSelections[0].value
if ($id("flexiContainer").classList.contains("uncolorAllScenesBut")){
muteColors()
} //i.e. if already on, this toggles it off before selecting new color
if (theSelection != "(None)"){ //do not toggle on if user chose "none"
muteColors($(`.scene.${theSelection.toLowerCase()}, .section.${theSelection.toLowerCase()}`))
}
deselectAllElements()
}
function muteColors(theClickedThing, shift){
mylog(theClickedThing?.classList)
// alertThis(theClickedThing.classList)
if (!shift && $id("flexiContainer").classList.contains("uncolorAllScenesBut")){
$id("flexiContainer").classList.remove("uncolorAllScenesBut")
for (let color of colorsArray){
if($id("flexiContainer").classList.contains(color.toLowerCase())){
$id("flexiContainer").classList.remove(color.toLowerCase())
$id("characterButton").classList.remove(color.toLowerCase())
}
}
updateSelectionInfo()
return
}
if(!theClickedThing || !theClickedThing.closest(".synopsis, .scene, .section")){
mylog("returning bc no closest scene or section")
return
}
$id("flexiContainer").classList.add("uncolorAllScenesBut")
theClickedThing = theClickedThing.closest(".synopsis, .scene, .section")
let foundOne = false
for (let color of colorsArray){
if(theClickedThing.classList.contains(color.toLowerCase())){
document.getElementById("flexiContainer").classList.add(color.toLowerCase())
document.getElementById("characterButton").classList.add(color.toLowerCase())
foundOne = true
break
}
}
if (!foundOne && theClickedThing.classList.contains("synopsis")){
theClickedThing = theClickedThing.closest(".scene, .section")
muteColors(theClickedThing, true)
}
deselectAllElements()
updateSelectionInfo()
}
function _____________(){}
function initiateCharacterBubbles(characterName = "ALL"){
collectCharacters(characterName)
//$id("allDialogFor").selectedIndex = 0
showCharacterBubbles(characterName)
}
function unShowCharacterBubbles(){
$$(".sceneChunk").forEach( chunk => { chunk.remove() })
$$(".connectorcontainer").forEach( connector => { connector.remove() })
$$(".displayNumberOf").forEach( numberof => { numberof.remove() })
if(!$id("dialogsearch")?.value) {deselectAllCharacters()} //avoid blinkage: don't remove "dimmedScene" if filtering underway
$$(".scene .orphan").forEach(element => {
element.removeEventListener("mouseenter", function(){
selectSceneChunk($id("dialogIn" + element.id)?.closest(".sceneChunk"))
scrollNicelyIntoView($id("dialogIn" + element.id), $id("dialogpanelcontent"))
})
})
}
function selectSceneChunk(sceneChunk){
if(!sceneChunk) return
$$(".selectedSceneChunk").forEach(sceneChunk => {sceneChunk.classList.remove("selectedSceneChunk")})
sceneChunk.classList.add("selectedSceneChunk")
}
function cycleBubbles(direction){ //send here: -1 or +1
if(!$("#notepanel.expanded .dialogtab.selectedtab")){cycleTabs($(".dialogtab"))}
let allChunks = Array.from($$(".dialogChunk"))
if(!allChunks || allChunks.length == 0) {
initiateCharacterBubbles()
return
}
let selectedNumber = allChunks.indexOf($(".dialogChunk.selectedDialog"))
if(selectedNumber < 0) return //no, make it current?
selectedNumber += Number(direction)
if (selectedNumber > allChunks.length - 1) selectedNumber = 0
if (selectedNumber < 0) selectedNumber = allChunks.length - 1
selectThisDialog(allChunks[selectedNumber].id, true) //if not true, no scroll
}
function selectThisDialog(dlgId, andScroll = false){
let currentChunk = $(".hoveredSceneChunk")
$$(".selectedDialog")?.forEach(element => {element.classList.remove("selectedDialog")})
$$(".isHovered")?.forEach(element => {element.classList.remove("isHovered")})
$$(".hoveredSceneChunk")?.forEach(chunk =>{chunk.classList.remove("hoveredSceneChunk")})
$id(dlgId)?.classList.add("selectedDialog")
$id(dlgId)?.closest(".sceneChunk").classList.add("isHovered")
$id(dlgId)?.closest(".sceneChunk").classList.add("hoveredSceneChunk")
$id($id(dlgId)?.closest(".sceneChunk").dataset.parentId)?.classList.add("isHovered")
if($(".hoveredSceneChunk") != currentChunk) {
createOrUpdateConnectorFor($(".hoveredSceneChunk"))
}
if(andScroll) { scrollNicelyIntoView($id(dlgId) || $(".hasCursor"), $id("dialogpanelcontent")) }
}
function updateDialogPanel(scenesWithDialog){
if (!($id("notepanel").classList.contains("expanded") && $(".selectedtab")?.classList.contains("dialogtab"))){ return }
let alreadySelected = $id("allDialogFor").selectedOptions[0]?.innerText.trim() || "ALL"
collectCharacters()
showCharacterBubbles(alreadySelected, true)
updateDialogPanelSelection()
}
function showCharacterBubbles(characterName, redraw){
mylog()
console.time("bubbles")
// re-select already selected character!
if(characterName){
$id("allDialogFor").selectedIndex = ([...$id("allDialogFor").options].map(option => option.value.toUpperCase())).indexOf(characterName) || 0
}else{
characterName = $id("allDialogFor").selectedOptions[0]?.innerText.trim() || "ALL"
}
let scrolledAmountBeforeRedraw = $id("dialogpanelcontent").scrollTop
let allChunks = $$(".sceneChunk")
//when chunks already present, clean up before doing anything else:
if(allChunks.length > 0){
unShowCharacterBubbles()
}
//if no character is selected, loop all dialog, otherwise only loop dialog for selected character
let selectedScenesWithDialog = characterName == "ALL" ? globalScenesWithDialog : globalScenesWithDialog.map(scene => scene.filter(line => line.character == characterName))
for (let scene of selectedScenesWithDialog){
let theId = selectedScenesWithDialog.indexOf(scene)
// This PROBABLY helps against a bug PROBABLY caused by the scenes being updated from the plugin while this loop is running
if(!$id(theId)) break
let orphanId
if($id(theId)?.classList.contains("section")){
orphanId = $id(theId).querySelector(".orphanText")?.id
}
if (scene.length == 0) continue
let chunk = document.createElement("div")
chunk.id = "dialogIn" + theId
chunk.dataset.orphanId = orphanId
chunk.dataset.parentId = theId
chunk.style.color = $id(theId).querySelector(".sceneheading").style.color
chunk.style.marginBottom = "3px"
chunk.dataset.charactername = characterName
chunk.onmouseenter = function(){
$id(chunk.dataset.parentId).classList.add('isHovered')
createOrUpdateConnectorFor(chunk)
}
chunk.onmouseleave = function(){
$id(chunk.dataset.parentId).classList.remove('isHovered')
$$(".connector").forEach(connector => {connector.remove()})
}
chunk.classList.add("sceneChunk")
chunk.style.width = "100%"
if (outline[theId].omitted) chunk.classList.add("omitted")
chunk.innerHTML = `<p class="chunkHeading"><span style="opacity: 0.4;">${(outline[theId].sceneNumber || "")} </span> ${outline[theId].stringForDisplay}</p>`
let createdChunks = []
let chunkNumber = -1
for (line of scene){
if (line.typeAsString == "Character"){
chunkNumber ++
createdChunks[chunkNumber] = document.createElement("div")
createdChunks[chunkNumber].classList.add("dialogChunk")
createdChunks[chunkNumber].id = "dialog" + line.position
createdChunks[chunkNumber].dataset.line = line.position
createdChunks[chunkNumber].onclick = function(){selectThisDialog("dialog" + line.position)}
//continue
}
let omittedString = ""
if(line.omitted) omittedString = " omitted"
createdChunks[chunkNumber].innerHTML += `<p class="${line.typeAsString.toLowerCase()} ${omittedString}" data-line="${line.position}" data-end-pos="${line.position + line.string.length}" data-length="${line.string.length}"><span class="debug">${line.position}-${line.position + line.string.length}</span>${line.string}</p>`
createdChunks[chunkNumber].innerHTML = createdChunks[chunkNumber].innerHTML.replace(/\/\*(.*)\*\//g, "<span class='omitted'>$1</span>")
createdChunks[chunkNumber].innerHTML = createdChunks[chunkNumber].innerHTML.replace(/\*\*\*(.*)\*\*\*/g, "<b><i>$1</i></b>")
createdChunks[chunkNumber].innerHTML = createdChunks[chunkNumber].innerHTML.replace(/\*\*(.*)\*\*/g, "<b>$1</b>")
createdChunks[chunkNumber].innerHTML = createdChunks[chunkNumber].innerHTML.replace(/\*(.*)\*/g, "<i>$1</i>")
createdChunks[chunkNumber].innerHTML = createdChunks[chunkNumber].innerHTML.replace(/\_(.*)\_/g, "<u>$1</u>")
//hack to update the endPos of the chunk for as long as we keep adding to it
createdChunks[chunkNumber].dataset.endPos = line.position + line.string.length
createdChunks[chunkNumber].querySelector(".debug").innerText = createdChunks[chunkNumber].dataset.line + "-" + createdChunks[chunkNumber].dataset.endPos
}
for (createdChunk of createdChunks){
chunk.appendChild(createdChunk)
}
chunk.dataset.startPos = chunk.firstChild.data-line
chunk.dataset.endPos = chunk.lastChild.data-line + chunk.lastChild.innerText.length
//and the sceneChunk to the sidepanel:
$id("dialogpanelcontent").appendChild(chunk)
if($id("dialogsearch").value) chunk.classList.add("displayNone")
//chunkSizes = chunk.getBoundingClientRect()
//add number of dialogs to corresponding scene
let displayNumberOf = document.createElement("div")
$id(orphanId || theId).appendChild(displayNumberOf)
displayNumberOf.id = "displayNumberOf" + theId //chunk.id
displayNumberOf.dataset.parentId = theId
displayNumberOf.classList.add("displayNumberOf")
displayNumberOf.classList.add("dontDim")
displayNumberOf.style.position = "absolute"
displayNumberOf.style.top = "50%"
displayNumberOf.style.left = "50%"
displayNumberOf.textContent = chunk.querySelectorAll(".dialogChunk").length
displayNumberOf.onmouseenter = onmouseenterForDNO
function onmouseenterForDNO(){
$id("dialogIn" + theId).classList.add("hoveredSceneChunk")
}
displayNumberOf.onmouseleave = onmouseleaveForDNO
function onmouseleaveForDNO(){
$id("dialogIn" + theId).classList.remove("hoveredSceneChunk")
}
displayNumberOf.onclick = onclickForDNO
function onclickForDNO(){
selectSceneChunk(chunk)
scrollNicelyIntoView(chunk.querySelector(".dialogChunk") || chunk, $id("dialogpanelcontent"))
}
//must set color after "displaynumberof", or else getcomputedstyle delivers blank
chunk.style.setProperty("--localColor", window.getComputedStyle($id(theId)).backgroundColor)
chunk.style.backgroundColor = "var(--localColor)"
}
$id("dialogpanelcontent").scrollTo({
top: scrolledAmountBeforeRedraw,
left: 0,
behavior: 'instant'
});
$id("dialogpanelcontent").onscroll = function(){ updateDialogPanelOnScroll() }
if($id("dialogsearch").value) onlyShowMatchingDialogs(true)
console.timeEnd("bubbles")
}
function updateDialogPanelSelection(){
if (!($id("notepanel").classList.contains("expanded") && $(".selectedtab")?.classList.contains("dialogtab"))){ return }
let cursorPosition = Number($id("youAreHere").dataset.location)
$$(".selectedDialog")?.forEach(element => {element.classList.remove("selectedDialog")})
$$(".dialogChunk")?.forEach(element => {element.classList.remove("hasCursor")})
let bestMatch = Array.from($$(".dialogChunk")).find(element => Number(element.dataset.line) <= cursorPosition && Number(element.dataset.endPos) >= cursorPosition)
let bestMatchClosestChunk = bestMatch?.closest(".dialogChunk")
//console.log(cursorPosition, bestMatch?.dataset.line, bestMatch?.dataset.endPos, bestMatchClosestChunk?.textContent)
bestMatchClosestChunk?.classList.add("selectedDialog", "hasCursor")
scrollNicelyIntoView($(".hasCursor"), $id("dialogpanelcontent"))
}
function updateDialogPanelOnScroll(){
let hoveredChunk = $(".sceneChunk.hoveredSceneChunk, .sceneChunk:hover")