-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
182 lines (158 loc) · 5.16 KB
/
script.js
File metadata and controls
182 lines (158 loc) · 5.16 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
const CONFIG = {
images: 12,
maxPlayers: 150,
title: 'Pure RP Title',
description: 'Purescripts Advanced roleplay',
discord: 'https://discord.gg/NT85wSdJy6',
logo: 'https://media.discordapp.net/attachments/1136047160937422928/1443543289654677584/image.png?ex=692973f3&is=69282273&hm=59b23431775c0cbbf5a710943ba31a205154d13c69af2ad42223b3928cb2b665&=&format=webp&quality=lossless',
};
const imageState = {
currentCycle: [],
currentIndex: 0,
};
const discordClicked = () => {
window.invokeNative('openUrl', CONFIG.discord);
};
const getImage = () => {
if (imageState.currentIndex >= imageState.currentCycle.length) {
imageState.currentCycle = Array.from(
{ length: CONFIG.images },
(_, i) => i + 1,
);
for (let i = imageState.currentCycle.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[imageState.currentCycle[i], imageState.currentCycle[j]] = [
imageState.currentCycle[j],
imageState.currentCycle[i],
];
}
imageState.currentIndex = 0;
}
const number = imageState.currentCycle[imageState.currentIndex++];
const imgSrc = `./images/${number}.png`;
return imgSrc;
};
const updateImage = () => {
const imgElement = document.getElementById('randomImage');
const overlay = document.getElementById('imageOverlay');
overlay.style.opacity = 0.25;
setTimeout(() => {
imgElement.src = getImage();
overlay.style.opacity = 1;
}, 500);
};
const tips = [
'Got a new phone sim? Right click on your phone in the phone slot to place a SIM.',
'Third-eye some dumpsters, you might find something useful.',
'Need a bite to eat? Burger Shot has you covered.',
'Police Officer do something wrong? File a complaint at the front desk.',
'Need to grab something from your pockets? Press Tab.',
'You can use /me to enhance your roleplay interactions.',
'Don’t rush — let the story unfold. Quality RP takes time.',
'Civilian jobs are a great way to earn money and build connections.',
'Not sure what to do? Post on Twooter and learn from others in city.',
'Your Apartment is your space, use the tablet to decorate it.',
'Most jobs require the right tools, Mega Mall usually has you covered.',
'Need some major cosmetic changes? Head to the plastic surgeon at the Hospital.',
'Armor requires plates, be sure to stock up when you need it.',
];
const newTip = () => {
const help = document.getElementById('helpText');
const outer = document.getElementById('help');
const num = Math.floor(Math.random() * tips.length);
const randomTip = tips[num];
// help.innerText(randomTip);
help.innerText = randomTip;
// help
outer.className = 'popupBg tip slideRightHome';
setTimeout(() => {
outer.className = 'popupBg tip slideFromRight';
}, 1500);
};
window.onload = () => {
newTip();
setInterval(updateImage, 5000);
setInterval(newTip, 5000);
document.getElementById('title').innerText = CONFIG.title;
document.getElementById('description').innerText = CONFIG.description;
document.getElementById('serverLogo').src = CONFIG.logo;
document.getElementById('maxPlayers').innerText = CONFIG.maxPlayers;
};
let states = {
INIT_BEFORE_MAP_LOADED: {
count: 0,
done: 0,
},
MAP: {
count: 0,
done: 0,
},
INIT_AFTER_MAP_LOADED: {
count: 0,
done: 0,
},
INIT_SESSION: {
count: 0,
done: 0,
},
};
const updateGlobalProgressText = () => {
let totalDone = 0;
let totalCount = 0;
for (let type in states) {
totalDone += states[type].done;
totalCount += states[type].count;
}
document.getElementById('progressStuff').innerText =
`${totalDone}/${totalCount}`;
};
const handlers = {
startInitFunctionOrder: (data) => {
// Reconnecting
if (
data.type === 'INIT_SESSION' &&
states['INIT_BEFORE_MAP_LOADED'].count < 1
) {
states['INIT_BEFORE_MAP_LOADED'].count = 1;
states['INIT_BEFORE_MAP_LOADED'].done = 1;
states['MAP'].count = 1;
states['MAP'].done = 1;
states['INIT_AFTER_MAP_LOADED'].count = 1;
states['INIT_AFTER_MAP_LOADED'].done = 1;
}
states[data.type].count += data.count;
updateGlobalProgressText();
},
initFunctionInvoked: (data) => {
states[data.type].done++;
updateGlobalProgressText();
},
startDataFileEntries: (data) => {
states['MAP'].count = data.count;
updateGlobalProgressText();
},
performMapLoadFunction: () => {
states['MAP'].done++;
updateGlobalProgressText();
},
};
let last = 0;
window.addEventListener('message', (e) =>
(handlers[e.data.eventName] || (() => {}))(e.data),
);
window.addEventListener('DOMContentLoaded', () => {
document.getElementById('currentPlayers').innerText =
window.nuiHandoverData.players;
});
setInterval(() => {
let progress = 0;
for (let type in states) {
if (states[type].done < 1 || states[type].count < 1) continue;
progress += (states[type].done / states[type].count) * 100;
}
let total = Math.min(Math.round(progress / Object.keys(states).length), 100);
if (total < last) total = last;
last = total;
// document.getElementById('progress-bar-value').innerHTML = total;
document.getElementById('progInner').style.width = total + '%';
}, 100);