-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathindex.js
More file actions
4075 lines (3678 loc) · 136 KB
/
Copy pathindex.js
File metadata and controls
4075 lines (3678 loc) · 136 KB
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
/**
* @name Rose-ChromaWheel
* @author Rose Team
* @description Chroma wheel for Pengu Loader
* @link https://github.com/Alban1911/Rose-ChromaWheel
*/
(function createFakeChromaButton() {
const LOG_PREFIX = "[LU-ChromaButton]";
console.log(`${LOG_PREFIX} JS Loaded`);
const BUTTON_CLASS = "lu-chroma-button";
const BUTTON_SELECTOR = `.${BUTTON_CLASS}`;
const PANEL_CLASS = "lu-chroma-panel";
const PANEL_ID = "lu-chroma-panel-container";
const SKIN_SELECTORS = [
".skin-name-text", // Classic Champ Select
".skin-name", // Swiftplay lobby
];
const SPECIAL_BASE_SKIN_IDS = new Set([99007]); // 82054, 145070, 103085, 25080 removed - handled by ROSE-FormsWheel
const SPECIAL_CHROMA_SKIN_IDS = new Set([100001, 88888]); // 145071, 103086, 103087 removed - handled by ROSE-FormsWheel
// HOL skins handled by ROSE-FormsWheel (should not show ChromaWheel buttons)
const HOL_SKIN_IDS = new Set([145070, 145071, 103085, 103086, 103087]);
const chromaParentMap = new Map();
let skinMonitorState = null;
const championSkinCache = new Map(); // championId -> Map(skinId -> skin data)
const skinChromaCache = new Map(); // skinId -> boolean
const skinToChampionMap = new Map(); // skinId -> championId
const pendingChampionRequests = new Map(); // championId -> Promise
// Track selected chroma for button color update (controlled by Python)
let selectedChromaData = null; // { id, primaryColor, colors, name }
let pythonChromaState = null; // { selectedChromaId, chromaColor, chromaColors, currentSkinId }
let championLocked = false; // Track if a champion is locked
let currentPhase = null; // Track the last observed phase so startup replays do not look like a new session
/**
* Escape HTML special characters to prevent XSS (CWE-79)
* @param {string} str - String to escape
* @returns {string} Escaped string safe for innerHTML
*/
function escapeHtml(str) {
if (typeof str !== 'string') return String(str);
return str
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
// Shared bridge API (provided by ROSE-Bridge plugin)
let bridge = null;
function waitForBridge() {
return new Promise((resolve, reject) => {
const timeout = 10000;
const interval = 50;
let elapsed = 0;
const check = () => {
if (window.__roseBridge) return resolve(window.__roseBridge);
elapsed += interval;
if (elapsed >= timeout) return reject(new Error("Bridge not available"));
setTimeout(check, interval);
};
check();
});
}
// Audio: play official chroma click sound when a chroma panel button is clicked
// Using the same endpoint the client uses: sfx-cs-button-chromas-click.ogg
const CHROMA_CLICK_SOUND_URL =
"https://127.0.0.1:65236/fe/lol-champ-select/sounds/sfx-cs-button-chromas-click.ogg";
let chromaClickAudio = null;
function playChromaClickSound() {
try {
if (!chromaClickAudio) {
chromaClickAudio = new Audio(CHROMA_CLICK_SOUND_URL);
} else {
// Reset playback so rapid clicks replay the sound from the start
chromaClickAudio.currentTime = 0;
}
chromaClickAudio.play().catch((err) => {
// Ignore playback errors (e.g. autoplay restrictions) but log for debugging
if (window?.console) {
console.debug(
"[ChromaWheel] Failed to play chroma click sound:",
err
);
}
});
} catch (err) {
if (window?.console) {
console.debug(
"[ChromaWheel] Error initializing chroma click sound:",
err
);
}
}
}
const CSS_RULES = `
.${BUTTON_CLASS} {
pointer-events: auto;
-webkit-user-select: none;
list-style-type: none;
cursor: pointer;
display: block !important;
bottom: 1px;
height: 25px;
left: 50%;
position: absolute;
transform: translateX(-50%) translateY(50%);
width: 25px;
z-index: 10;
direction: ltr;
}
/* Normal champ select carousel positioning */
.skin-selection-item .${BUTTON_CLASS} {
left: 50%;
}
.${BUTTON_CLASS}[data-hidden],
.${BUTTON_CLASS}[data-hidden] * {
pointer-events: none !important;
cursor: default !important;
visibility: hidden !important;
}
.${BUTTON_CLASS} .outer-mask {
pointer-events: auto;
-webkit-user-select: none;
list-style-type: none;
cursor: pointer;
border-radius: 50%;
box-shadow: 0 0 4px 1px rgba(1,10,19,.25);
box-sizing: border-box;
height: 100%;
overflow: hidden;
position: relative;
}
.${BUTTON_CLASS} .frame-color {
--champion-preview-hover-animation-percentage: 0%;
--column-height: 95px;
--font-display: "LoL Display","Times New Roman",Times,Baskerville,Georgia,serif;
--font-body: "LoL Body",Arial,"Helvetica Neue",Helvetica,sans-serif;
pointer-events: auto;
-webkit-user-select: none;
list-style-type: none;
cursor: default;
background-image: linear-gradient(0deg,#695625 0,#a9852d 23%,#b88d35 93%,#c8aa6e);
box-sizing: border-box;
height: 100%;
overflow: hidden;
width: 100%;
padding: 2px;
display: flex;
align-items: center;
justify-content: center;
}
.${BUTTON_CLASS} .content {
pointer-events: auto;
-webkit-user-select: none;
list-style-type: none;
cursor: pointer;
display: block;
background: url(/fe/lol-champ-select/images/config/button-chroma.png) no-repeat;
background-size: contain;
border: 2px solid #010a13;
border-radius: 50%;
box-sizing: border-box;
height: 20px;
width: 20px;
margin: 0;
flex-shrink: 0;
}
.${BUTTON_CLASS} .inner-mask {
-webkit-user-select: none;
list-style-type: none;
cursor: default;
border-radius: 50%;
box-sizing: border-box;
overflow: hidden;
pointer-events: none;
position: absolute;
box-shadow: inset 0 0 4px 4px rgba(0,0,0,.75);
width: calc(100% - 4px);
height: calc(100% - 4px);
left: 2px;
top: 2px;
}
/* Ensure parent containers have relative positioning for absolute button */
.thumbnail-wrapper.active-skin,
.skin-selection-item {
position: relative;
}
.thumbnail-wrapper .${BUTTON_CLASS} {
direction: ltr;
background: transparent;
cursor: pointer;
height: 28px;
width: 28px;
/* Keep the same positioning as base button for consistency */
bottom: 1px;
left: 50%;
position: absolute;
transform: translateX(-50%) translateY(50%);
z-index: 10;
}
/* Show outer-mask in Swiftplay so .content is visible */
.thumbnail-wrapper .${BUTTON_CLASS} .outer-mask {
display: block;
}
/* Swiftplay buttons inherit flexbox centering from .frame-color */
.chroma.icon {
display: none !important;
}
.${PANEL_CLASS} {
position: fixed;
z-index: 10000;
pointer-events: all;
-webkit-user-select: none;
}
.${PANEL_CLASS}[data-no-button] {
pointer-events: none;
cursor: default !important;
}
.${PANEL_CLASS}[data-no-button] * {
pointer-events: none !important;
cursor: default !important;
}
.${PANEL_CLASS} .chroma-modal {
background: #000;
display: flex;
flex-direction: column;
width: 305px;
position: relative;
z-index: 0;
}
.${PANEL_CLASS} .chroma-modal.chroma-view {
max-height: 420px;
min-height: 355px;
}
.${PANEL_CLASS} .flyout {
position: absolute;
overflow: visible;
pointer-events: all;
-webkit-user-select: none;
}
.${PANEL_CLASS}[data-no-button] .flyout {
pointer-events: none !important;
cursor: default !important;
}
.${PANEL_CLASS} .flyout-frame {
position: relative;
transition: 250ms all cubic-bezier(0.02, 0.85, 0.08, 0.99);
}
/* Target the caret/notch element to be above the border */
.${PANEL_CLASS} .flyout .caret,
.${PANEL_CLASS} .flyout [class*="caret"],
.${PANEL_CLASS} lol-uikit-flyout-frame .caret,
.${PANEL_CLASS} lol-uikit-flyout-frame [class*="caret"],
.${PANEL_CLASS} .flyout::part(caret),
.${PANEL_CLASS} lol-uikit-flyout-frame::part(caret) {
z-index: 3 !important;
position: relative;
}
.${PANEL_CLASS} .border {
position: absolute;
top: 0;
left: 0;
box-sizing: border-box;
background-color: transparent;
box-shadow: 0 0 0 1px rgba(1,10,19,0.48);
transition: 250ms all cubic-bezier(0.02, 0.85, 0.08, 0.99);
border-top: 2px solid transparent;
border-left: 2px solid transparent;
border-right: 2px solid transparent;
border-bottom: none;
border-image: linear-gradient(to top, #785a28 0, #463714 50%, #463714 100%) 1 stretch;
border-image-slice: 1 1 0 1;
width: 100%;
height: 100%;
visibility: visible;
z-index: 2;
pointer-events: none;
}
.${PANEL_CLASS} .lc-flyout-content {
position: relative;
}
.${PANEL_CLASS} .chroma-information {
background-size: cover;
border-bottom: thin solid #463714;
flex-grow: 1;
height: 315px;
position: relative;
width: 100%;
z-index: 1;
}
.${PANEL_CLASS} .chroma-information-image {
background-repeat: no-repeat;
background-size: contain;
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
}
.${PANEL_CLASS} .child-skin-name {
bottom: 10px;
color: #f7f0de;
font-family: "LoL Display", "Times New Roman", Times, Baskerville, Georgia, serif;
font-size: 24px;
font-weight: 700;
position: absolute;
text-align: center;
width: 100%;
}
.${PANEL_CLASS} .chroma-selection {
pointer-events: all;
height: 100%;
overflow: auto;
transform: translateZ(0);
-webkit-mask-box-image-source: url("/fe/lol-static-assets/images/uikit/scrollable/scrollable-content-gradient-mask-bottom.png");
-webkit-mask-box-image-slice: 0 8 18 0 fill;
align-items: center;
display: flex;
flex-direction: row;
flex-grow: 0;
flex-wrap: wrap;
justify-content: center;
max-height: 92px;
min-height: 40px;
padding: 7px 0;
width: 100%;
position: relative;
z-index: 1;
}
.${PANEL_CLASS}[data-no-button] .chroma-selection {
pointer-events: none;
cursor: default;
}
.${PANEL_CLASS} .chroma-selection ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 0;
width: 100%;
}
.${PANEL_CLASS} .chroma-selection li {
list-style: none;
margin: 2px 4px; /* Add 1px extra horizontal spacing between buttons */
padding: 0;
display: flex;
align-items: center;
justify-content: center;
}
.${PANEL_CLASS} .chroma-skin-button {
pointer-events: all;
align-items: center;
border-radius: 50%;
box-shadow: 0 0 2px #010a13;
border: none;
display: flex;
height: 26px;
width: 26px;
min-width: 26px;
min-height: 26px;
max-width: 26px;
max-height: 26px;
aspect-ratio: 1 / 1; /* Force square to keep outer circle circular under scaling */
justify-content: center;
margin: 0;
padding: 0;
cursor: pointer;
box-sizing: border-box;
background: transparent !important;
background-color: transparent !important;
flex: 0 0 26px; /* Fixed size in flex to prevent any stretching */
transform: scale(1); /* Override any parent scaling transforms */
}
.${PANEL_CLASS}[data-no-button] .chroma-skin-button {
pointer-events: none !important;
cursor: default !important;
}
.${PANEL_CLASS} .chroma-skin-button:not(.locked) {
cursor: pointer;
opacity: 1 !important; /* Always 100% opacity for non-locked buttons */
}
.${PANEL_CLASS} .chroma-skin-button.locked {
opacity: 1 !important; /* All buttons at 100% opacity, including locked */
cursor: pointer;
/* Keep colors visible, no opacity reduction */
}
.${PANEL_CLASS} .chroma-skin-button .contents {
pointer-events: all;
align-items: center;
border: 2px solid #010a13;
border-radius: 50%;
display: flex;
height: 18px;
width: 18px;
min-width: 18px;
min-height: 18px;
max-width: 18px;
max-height: 18px;
aspect-ratio: 1 / 1; /* Force inner circle to remain perfectly circular */
justify-content: center;
background: linear-gradient(135deg, #27211C 0%, #27211C 50%, #27211C 50%, #27211C 100%);
box-shadow: 0 0 0 2px transparent; /* Reserve space for the hover ring so layout never shifts */
opacity: 1 !important; /* All button contents at 100% opacity always */
transform: scale(1); /* Override any parent scaling transforms */
/* Background will be set/overridden inline based on chroma color */
}
/* Selected / hover state: just change ring color, thickness is constant so no squeezing */
.${PANEL_CLASS} .chroma-skin-button.selected .contents,
.${PANEL_CLASS} .chroma-skin-button:hover .contents {
box-shadow: 0 0 0 2px #c89b3c;
transform: scale(1); /* Maintain perfect circle even on hover */
}
/* All buttons at 100% opacity, no variation on hover or state */
.${PANEL_CLASS} .chroma-skin-button.locked:hover:not([purchase-disabled]) {
opacity: 1 !important;
}
.${PANEL_CLASS} .chroma-skin-button.locked.purchase-disabled {
opacity: 1 !important;
pointer-events: none;
}
`;
function emitBridgeLog(event, data = {}) {
try {
if (bridge) {
bridge.send({
type: "chroma-log",
source: "LU-ChromaWheel",
event,
data,
timestamp: Date.now(),
});
}
} catch (error) {
// Can't use log here since it's not defined yet
console.debug(`${LOG_PREFIX} Failed to emit bridge log`, error);
}
}
// Track pending local preview/asset requests
const pendingLocalPreviews = new Map(); // chromaId -> { chromaImage, chroma }
const pendingLocalAssets = new Map(); // chromaId -> { contents, chroma }
function handleLocalPreviewUrl(data) {
// Handle local preview URL response from Python
const { championId, skinId, chromaId, url } = data;
log.debug(
`[ChromaWheel] Received local preview URL: ${url} for chroma ${chromaId}`
);
// Find the chroma image element that requested this preview
const pending = pendingLocalPreviews.get(chromaId);
if (pending && pending.chromaImage) {
// Use the file:// URL (may not work due to browser security, but worth trying)
// If it doesn't work, Python should serve via HTTP instead
pending.chromaImage.style.background = "";
pending.chromaImage.style.backgroundImage = `url('${url}')`;
pending.chromaImage.style.backgroundSize = "contain";
pending.chromaImage.style.backgroundPosition = "center";
pending.chromaImage.style.backgroundRepeat = "no-repeat";
pending.chromaImage.style.display = "";
log.debug(`[ChromaWheel] Applied local preview URL to chroma image`);
}
// Clean up pending request
pendingLocalPreviews.delete(chromaId);
}
function handleLocalAssetUrl(data) {
// Handle local asset URL response from Python
let { assetPath, chromaId, url } = data;
// Fix: Ensure we use 127.0.0.1 for asset URLs to match the bridge connection
if (url && typeof url === 'string') {
url = url.replace('localhost', '127.0.0.1');
}
log.debug(
`[ChromaWheel] Received local asset URL: ${url} for chroma ${chromaId}`
);
// Special handling: ARAM background image for the panel
if (assetPath === ARAM_BACKGROUND_ASSET_PATH && url) {
aramBackgroundImageUrl = url;
aramBackgroundRequestPending = false;
if (currentChromaInfoElement) {
currentChromaInfoElement.style.backgroundImage = `url('${url}')`;
log.debug(
"[ChromaWheel] Applied ARAM background image to chroma panel"
);
}
}
// Find the button contents element that requested this asset
const pending = pendingLocalAssets.get(chromaId);
if (pending && pending.contents) {
// Use the file:// URL (may not work due to browser security, but worth trying)
// If it doesn't work, Python should serve via HTTP instead
pending.contents.style.background = "";
pending.contents.style.backgroundImage = `url('${url}')`;
pending.contents.style.backgroundSize = "contain";
pending.contents.style.backgroundPosition = "center";
pending.contents.style.backgroundRepeat = "no-repeat";
pending.contents.style.backgroundColor = "";
// Mark that this chroma ID's icon has been applied
pending.contents.setAttribute("data-last-chroma-id", String(chromaId));
log.debug(
`[ChromaWheel] Applied local asset URL to button icon for chroma ${chromaId}`
);
}
// Clean up pending request
pendingLocalAssets.delete(chromaId);
}
function handleChromaStateUpdate(data) {
// Update Python chroma state
pythonChromaState = {
selectedChromaId: data.selectedChromaId,
chromaColor: data.chromaColor,
chromaColors: data.chromaColors,
currentSkinId: data.currentSkinId,
};
log.info(
`[ChromaWheel] Received chroma state from Python: selectedChromaId=${data.selectedChromaId}, chromaColor=${data.chromaColor}`
);
// Note: isMordekaiser and isMorgana are global functions defined elsewhere
// HOL chromas (Kai'Sa and Ahri) are now handled by ROSE-FormsWheel
// Helper to get buttonIconPath for Elementalist Lux forms
const getButtonIconPathForElementalist = (chromaId) => {
if (chromaId === 99007 || (chromaId >= 99991 && chromaId <= 99999)) {
return getElementalistButtonIconPath(chromaId);
}
return null;
};
// Helper to get buttonIconPath for Sahn Uzal Mordekaiser forms
// Note: Mordekaiser handling removed - now handled by ROSE-FormsWheel plugin
const getButtonIconPathForMordekaiser = (chromaId) => {
// This function is kept for compatibility but should not be used
// Mordekaiser is now handled by ROSE-FormsWheel
return null;
};
// Helper to get buttonIconPath for Spirit Blossom Morgana forms
// Note: Morgana handling removed - now handled by ROSE-FormsWheel plugin
const getButtonIconPathForMorgana = (chromaId) => {
// This function is kept for compatibility but should not be used
// Morgana is now handled by ROSE-FormsWheel
return null;
};
// Helper to get buttonIconPath for HOL chromas - removed, handled by ROSE-FormsWheel
// Update selectedChromaData based on Python state
if (data.selectedChromaId && data.chromaColor) {
// Python provided the color directly
const buttonIconPath =
getButtonIconPathForElementalist(data.selectedChromaId) ||
(selectedChromaData && selectedChromaData.id === data.selectedChromaId
? selectedChromaData.buttonIconPath
: null);
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: data.chromaColor,
colors: data.chromaColors || [data.chromaColor],
name: "Selected", // Name will be updated when panel opens
buttonIconPath: buttonIconPath,
};
} else if (data.selectedChromaId) {
// Python provided selectedChromaId but no color - try to find it from cache
let foundChroma = null;
// Get base skin ID - check if currentSkinId is a chroma ID first
// Also check if baseSkinId was provided in the payload (from selectChroma)
let baseSkinId =
data.baseSkinId || data.currentSkinId || skinMonitorState?.skinId;
// If currentSkinId is a chroma ID, get the base skin ID from chromaParentMap
if (baseSkinId && chromaParentMap.has(baseSkinId)) {
baseSkinId = chromaParentMap.get(baseSkinId);
log.debug(
`[ChromaWheel] Found base skin ID ${baseSkinId} for chroma ${data.currentSkinId} from chromaParentMap`
);
}
// Also check if selectedChromaId itself is in the map (in case currentSkinId wasn't set correctly)
if (!baseSkinId && chromaParentMap.has(data.selectedChromaId)) {
baseSkinId = chromaParentMap.get(data.selectedChromaId);
log.debug(
`[ChromaWheel] Found base skin ID ${baseSkinId} for selected chroma ${data.selectedChromaId} from chromaParentMap`
);
}
// Check if this is Elementalist Lux - if so, use local data
if (
data.selectedChromaId === 99007 ||
(data.selectedChromaId >= 99991 && data.selectedChromaId <= 99999)
) {
// Elementalist Lux form - get data from local functions
const baseFormId = 99007;
const luxChampionId = 99;
// Check if it's the base form or a form
if (data.selectedChromaId === baseFormId) {
// Base form
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: null,
colors: [],
name: "Default",
buttonIconPath: getElementalistButtonIconPath(baseFormId),
};
} else {
// Elementalist Lux form (99991-99999)
const forms = getElementalistForms();
const form = forms.find((f) => f.id === data.selectedChromaId);
if (form) {
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: null,
colors: [],
name: form.name || "Selected",
buttonIconPath: getElementalistButtonIconPath(form.id),
};
} else {
// Form not found - use button icon path anyway
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: null,
colors: [],
name: "Selected",
buttonIconPath: getElementalistButtonIconPath(
data.selectedChromaId
),
};
}
}
log.debug(
`[ChromaWheel] Elementalist Lux form detected: ${data.selectedChromaId}, buttonIconPath: ${selectedChromaData.buttonIconPath}`
);
// Note: Mordekaiser (82054) and Spirit Blossom Morgana (25080) handling removed - now handled by ROSE-FormsWheel plugin
// HOL chromas (Kai'Sa and Ahri) are now handled by ROSE-FormsWheel - skip here
} else {
// Regular chroma - try to find from cache
// Fallback: try to infer base skin ID from chroma ID (chroma IDs are typically baseSkinId + offset)
if (!baseSkinId && Number.isFinite(data.selectedChromaId)) {
// Try to find base skin by checking if any cached skin has this chroma
// Or use the base skin ID from skinMonitorState if available
baseSkinId = skinMonitorState?.skinId;
// If skinMonitorState.skinId is also a chroma, try to get base from it
if (baseSkinId && chromaParentMap.has(baseSkinId)) {
baseSkinId = chromaParentMap.get(baseSkinId);
}
}
if (baseSkinId) {
const cachedChromas = getCachedChromasForSkin(baseSkinId);
foundChroma = cachedChromas.find(
(c) => c.id === data.selectedChromaId
);
log.debug(
`[ChromaWheel] Looking for chroma ${data.selectedChromaId
} in base skin ${baseSkinId}, found: ${foundChroma ? "yes" : "no"}`
);
}
if (foundChroma && foundChroma.primaryColor) {
// Preserve buttonIconPath if it exists in foundChroma or in existing selectedChromaData
const buttonIconPath =
foundChroma.buttonIconPath ||
(selectedChromaData &&
selectedChromaData.id === data.selectedChromaId
? selectedChromaData.buttonIconPath
: null);
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: foundChroma.primaryColor,
colors: foundChroma.colors || [foundChroma.primaryColor],
name: foundChroma.name || "Selected",
buttonIconPath: buttonIconPath,
};
log.debug(
`[ChromaWheel] Found chroma color from cache: ${foundChroma.primaryColor}`
);
} else {
// Chroma selected but no color available - try to keep existing selectedChromaData if it matches
if (
selectedChromaData &&
selectedChromaData.id === data.selectedChromaId
) {
log.debug(
`[ChromaWheel] Keeping existing selectedChromaData for chroma ${data.selectedChromaId}`
);
// Keep the existing data, just update the ID to be sure
selectedChromaData.id = data.selectedChromaId;
// Preserve buttonIconPath if it exists
if (!selectedChromaData.buttonIconPath) {
selectedChromaData.buttonIconPath = null;
}
} else {
// No existing data or it doesn't match - treat as default
selectedChromaData = {
id: data.selectedChromaId,
primaryColor: null,
colors: [],
name: "Default",
buttonIconPath: null,
};
log.debug(
`[ChromaWheel] Could not find chroma color for ${data.selectedChromaId}, using default`
);
}
}
}
} else {
// Default/base chroma selected
// Check if currentSkinId is Elementalist Lux base
let buttonIconPath = null;
if (
data.currentSkinId === 99007 ||
(data.currentSkinId >= 99991 && data.currentSkinId <= 99999)
) {
buttonIconPath = getElementalistButtonIconPath(data.currentSkinId);
}
// Note: Mordekaiser (82054), Spirit Blossom Morgana (25080), and HOL chromas (Kai'Sa and Ahri) are now handled by ROSE-FormsWheel - skip here
selectedChromaData = {
id: data.currentSkinId || null,
primaryColor: null,
colors: [],
name: "Default",
buttonIconPath: buttonIconPath,
};
}
// Update button color
updateChromaButtonColor();
}
function resetFrontendSessionState(reason) {
// Clear transient frontend state only when a Champ Select session really starts/ends.
skinMonitorState = null;
pythonChromaState = null;
selectedChromaData = null;
championLocked = false;
// Remove stale UI that may still be attached from the previous session.
const existingPanel = document.getElementById(PANEL_ID);
if (existingPanel) {
existingPanel.remove();
}
document.querySelectorAll(BUTTON_SELECTOR).forEach((button) => {
button.remove();
});
emitBridgeLog("session_state_reset", { reason });
}
function handlePhaseChangeFromPython(data) {
// Use Python-detected game mode to drive ARAM detection for the JS panel
try {
const phase = data.phase;
const gameMode = data.gameMode;
const mapId = data.mapId;
// Late startup can replay "ChampSelect" after skin-state is already current.
// Keep the last seen phase so we only reset on real phase transitions.
const previousPhase = currentPhase;
currentPhase = phase;
if (phase === "ChampSelect") {
// Only reset on a real transition into a new Champ Select session.
// Startup replays can arrive after a valid skin-state payload.
if (previousPhase && previousPhase !== "ChampSelect") {
resetFrontendSessionState("phase-entry");
}
const isAram =
mapId === 12 ||
(typeof gameMode === "string" && gameMode.toUpperCase() === "ARAM");
isAramFromPython = Boolean(isAram);
} else if (phase === "FINALIZATION") {
const isAram =
mapId === 12 ||
(typeof gameMode === "string" && gameMode.toUpperCase() === "ARAM");
isAramFromPython = Boolean(isAram);
} else {
// Leaving champ select / finalization – clear flag
if (
previousPhase === "ChampSelect" ||
previousPhase === "FINALIZATION"
) {
resetFrontendSessionState("phase-exit");
}
isAramFromPython = false;
}
// Observer lifecycle: stop only during actively-playing InProgress so
// Swiftplay skin selection (which happens in Lobby phase) isn't broken.
// See GitHub issue #22.
if (phase === "InProgress") {
stopObserver();
} else {
startObserver();
}
} catch (e) {
// Fail silently – fallback to Ember-based detection
}
}
function requestAramBackgroundImage() {
// Request ARAM panel background image from Python when in ARAM game modes
if (aramBackgroundImageUrl || aramBackgroundRequestPending) {
return;
}
aramBackgroundRequestPending = true;
const payload = {
type: "request-local-asset",
assetPath: ARAM_BACKGROUND_ASSET_PATH,
timestamp: Date.now(),
};
log.debug("[ChromaWheel] Requesting ARAM background image from Python", {
assetPath: ARAM_BACKGROUND_ASSET_PATH,
});
if (bridge) {
bridge.send(payload);
} else {
aramBackgroundRequestPending = false;
log.debug("[ChromaWheel] Bridge not available for ARAM background request");
}
}
const log = {
info: (msg, extra) => {
console.log(`${LOG_PREFIX} ${msg}`, extra ?? "");
emitBridgeLog("info", { message: msg, data: extra });
},
warn: (msg, extra) => {
console.warn(`${LOG_PREFIX} ${msg}`, extra ?? "");
emitBridgeLog("warn", { message: msg, data: extra });
},
debug: (msg, extra) => {
console.debug(`${LOG_PREFIX} ${msg}`, extra ?? "");
emitBridgeLog("debug", { message: msg, data: extra });
},
error: (msg, extra) => {
console.error(`${LOG_PREFIX} ${msg}`, extra ?? "");
emitBridgeLog("error", { message: msg, data: extra });
},
};
function getNumericId(value) {
if (typeof value === "number" && Number.isFinite(value)) {
return value;
}
if (typeof value === "string" && value.trim() !== "") {
const parsed = parseInt(value, 10);
if (!Number.isNaN(parsed)) {
return parsed;
}
}
return null;
}
function extractSkinIdFromData(skinData) {
if (!skinData || typeof skinData !== "object") {
return null;
}
const candidates = [
skinData.skinId,
skinData.id,
skinData.skin?.skinId,
skinData.skin?.id,
skinData.championSkinId,
skinData.parentSkinId,
];
for (const candidate of candidates) {
const numeric = getNumericId(candidate);
if (numeric !== null) {
return numeric;
}
}
return null;
}
function extractSkinIdFromElement(element) {
if (!element) {
return null;
}
const direct = element.getAttribute?.("data-skin-id");
if (direct) {
return getNumericId(direct);
}
const nested = element
.querySelector?.("[data-skin-id]")
?.getAttribute("data-skin-id");
if (nested) {
return getNumericId(nested);
}
return null;
}
function getSkinIdFromContext(skinData, element) {
return extractSkinIdFromData(skinData) ?? extractSkinIdFromElement(element);
}
function getChampionIdFromContext(skinData, skinId, element) {
if (skinData && Number.isFinite(skinData.championId)) {
return skinData.championId;
}
if (element?.dataset?.championId) {
const attrId = getNumericId(element.dataset.championId);
if (Number.isFinite(attrId)) {
return attrId;
}
}
const championElement = element?.closest?.("[data-champion-id]");
if (championElement) {
const attrId = getNumericId(
championElement.getAttribute("data-champion-id")
);
if (Number.isFinite(attrId)) {
return attrId;
}
}
if (Number.isFinite(skinId)) {
const mappedChampion = skinToChampionMap.get(skinId);
if (Number.isFinite(mappedChampion)) {
return mappedChampion;
}
const inferred = Math.floor(skinId / 1000);
if (Number.isFinite(inferred) && inferred > 0) {
return inferred;
}
}
return null;