-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
116 lines (106 loc) · 2.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const ERENGEL_CITIES = [
'Apartments',
'Farm',
'Farmlands',
'Ferry Pier',
'Gatka Trenches',
'Gatka',
'Georgopol',
'Hospital',
'Kameshki',
'Lipovka',
'Mansion',
'Mylta Power Large',
'Mylta Power Small',
'Mylta',
'Novorepnoye',
'Pochinki',
'Primorsk',
'Quarry',
'Ridge Complex',
'Rozhok',
'Ruins',
'School',
'Severny',
'Shelter',
'Shooting Range',
'Sosnovka Island',
'Sosnovka Military Base',
'Stalber',
'Stalber',
'Swamp Town',
'Water Town',
'Woodcutter Camp',
'Yasnaya Polyana',
'Zharki',
];
const MIRAMAR_CITIES = [
'Campo Militar',
'Chumacera',
'Crater Fields',
'Cruz del Valle',
'El Azahar',
'El Pozo',
'Graveyard',
'Hacienda del Patrón',
'Junkyard',
'La Cobreria',
'Los Higos',
'Los Leones',
'Minas Generales',
'Minas del Sur',
'Minas del Valle',
'Monte Nuevo',
'Pecado',
'Power Grid',
'Prison',
'Puerto Paraiso',
'Ruins',
'San Martin',
'Tierra-Bronca',
'Trailer Park',
'Valle del Mar',
'Water Treatment',
];
const init = () => {
let next;
let cities = ERENGEL_CITIES;
let allCities = cities.length;
let firstCity = 0;
let spinning = false;
const mapSelection = document.querySelector('.map-selection');
const cityName = document.querySelector('.city-name');
const ticketButton = document.querySelector('.btn-ticket');
mapSelection.onchange = () => {
if (document.getElementById('M1').checked) {
cities = ERENGEL_CITIES;
changeCity();
} else if (document.getElementById('M2').checked) {
cities = MIRAMAR_CITIES;
changeCity();
}
};
const changeCity = () => {
cityName.innerHTML = cities[firstCity];
firstCity = (firstCity + 1) % allCities;
};
const change = () => {
next = setInterval(changeCity, 120);
};
ticketButton.onclick = () => {
if (!spinning) {
spinning = true;
allCities = cities.length;
cityName.classList.add('animate');
setTimeout(() => {
const random = Math.floor(Math.random() * cities.length);
clearInterval(next);
cityName.innerHTML = cities[random];
cityName.classList.remove('animate');
spinning = false;
}, 2500);
change();
}
};
};
window.addEventListener('DOMContentLoaded', init);