-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (109 loc) · 4.82 KB
/
script.js
File metadata and controls
127 lines (109 loc) · 4.82 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
document.body.style.overflow = 'hidden';
const buttonActions = {
1: ['platform1', 'platform3'],
2: ['platform3', 'platform4'],
3: ['platform1'],
4: ['platform3'],
5: ['platform2'],
6: ['platform2', 'platform3'],
7: ['platform2', 'platform4'],
8: ['platform2', 'platform3'],
9: ['platform3'],
10: ['platform1', 'platform2'],
11: ['platform1'],
12: ['platform1', 'platform3']
};
const leftButtons = [1, 2, 3, 4, 5, 6];
const rightButtons = [7, 8, 9, 10, 11, 12];
const maxActiveButtons = 3; // Максимум активных кнопок
document.querySelectorAll('.switch').forEach((button, index) => {
button.addEventListener('click', () => {
const isActive = button.classList.toggle('active');
if (isActive && getActiveButtonCount() > maxActiveButtons) {
button.classList.remove('active');
} else {
handleButtonPress(index + 1);
updatePlatformStates();
}
});
});
function getActiveButtonCount() {
return document.querySelectorAll('.switch.active').length;
}
function handleButtonPress(buttonIndex) {
const platforms = buttonActions[buttonIndex];
if (platforms) {
platforms.forEach(platformId => {
const platform = document.querySelector(`#${platformId}`);
if (document.querySelector(`#btn${buttonIndex}`).classList.contains('active')) {
if (platform.dataset.state !== 'fixed') {
platform.classList.add('ghost');
platform.dataset.state = 'ghost';
}
} else {
// При деактивации кнопки
if (platform.dataset.state === 'ghost' && !isPlatformSupported(platformId)) {
platform.classList.remove('ghost');
platform.dataset.state = 'invisible';
}
}
});
}
}
function updatePlatformStates() {
const allPlatforms = ['platform1', 'platform2', 'platform3', 'platform4'];
// Обновляем состояние фиксированных платформ
allPlatforms.forEach(platformId => {
const platform = document.querySelector(`#${platformId}`);
if (platform.dataset.state === 'fixed' && !isPlatformSupportedByBothSides(platformId)) {
platform.classList.remove('fixed');
platform.classList.add('ghost');
platform.dataset.state = 'ghost';
}
});
// Обновляем состояние призрачных платформ
allPlatforms.forEach(platformId => {
const platform = document.querySelector(`#${platformId}`);
const isGhost = platform.dataset.state === 'ghost';
const affectedByLeft = leftButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) && document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
const affectedByRight = rightButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) && document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
if (affectedByLeft && affectedByRight) {
if (isGhost && platform.dataset.state !== 'fixed') {
platform.classList.remove('ghost');
platform.classList.add('fixed');
platform.dataset.state = 'fixed';
}
} else if (platform.dataset.state === 'ghost' && !isPlatformSupported(platformId)) {
if (!isPlatformSupported(platformId)) {
platform.classList.remove('ghost');
platform.dataset.state = 'invisible';
}
}
});
}
function isPlatformSupportedByBothSides(platformId) {
const isSupportedByLeft = leftButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) &&
document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
const isSupportedByRight = rightButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) &&
document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
return isSupportedByLeft && isSupportedByRight;
}
function isPlatformSupported(platformId) {
const isSupportedByLeft = leftButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) &&
document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
const isSupportedByRight = rightButtons.some(buttonIndex =>
buttonActions[buttonIndex].includes(platformId) &&
document.querySelector(`#btn${buttonIndex}`).classList.contains('active')
);
return isSupportedByLeft || isSupportedByRight;
}