Alexainc commited on
Commit ยท
451a23a
1
Parent(s): 8c6c894
fix syntax error in olinda bot logic
Browse files- public/index.html +37 -13
- server/db.js +6 -2
- server/index.js +5 -4
public/index.html
CHANGED
|
@@ -1301,11 +1301,19 @@
|
|
| 1301 |
onclick="switchMainLB('global')">๐ Global Arena</div>
|
| 1302 |
</div>
|
| 1303 |
|
| 1304 |
-
<div id="
|
| 1305 |
-
<div style="display:flex; gap:8px; overflow-x:auto; padding-bottom:5px; scrollbar-width: none;">
|
| 1306 |
-
<
|
| 1307 |
-
<
|
| 1308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1309 |
</div>
|
| 1310 |
|
| 1311 |
<div id="lbSportsSelector" style="display:none; margin-top:10px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 10px;">
|
|
@@ -2747,7 +2755,7 @@
|
|
| 2747 |
document.getElementById('leaderboardView').classList.add('active');
|
| 2748 |
const navItem = document.getElementById('navLeaderboard');
|
| 2749 |
if (navItem) navItem.classList.add('active');
|
| 2750 |
-
|
| 2751 |
} else if (tab === 'profile') {
|
| 2752 |
document.getElementById('profileView').classList.add('active');
|
| 2753 |
const navItem = document.getElementById('navProfile');
|
|
@@ -2758,29 +2766,41 @@
|
|
| 2758 |
if (isHapticsSupported() && tg?.HapticFeedback) tg?.HapticFeedback.impactOccurred('light');
|
| 2759 |
}
|
| 2760 |
|
|
|
|
|
|
|
| 2761 |
function switchMainLB(mainType) {
|
|
|
|
| 2762 |
document.querySelectorAll('#lbMainTabs .lb-tab').forEach(t => t.classList.remove('active'));
|
|
|
|
| 2763 |
if (mainType === 'village') {
|
| 2764 |
document.querySelectorAll('#lbMainTabs .lb-tab')[0].classList.add('active');
|
| 2765 |
-
document.getElementById('
|
|
|
|
| 2766 |
switchLB('village_players');
|
| 2767 |
} else {
|
| 2768 |
document.querySelectorAll('#lbMainTabs .lb-tab')[1].classList.add('active');
|
| 2769 |
-
document.getElementById('
|
|
|
|
| 2770 |
switchLB('global');
|
| 2771 |
}
|
| 2772 |
}
|
| 2773 |
|
| 2774 |
function switchLB(type) {
|
| 2775 |
currentLBType = type;
|
|
|
|
| 2776 |
|
| 2777 |
// Sub-tab highlighting
|
| 2778 |
document.querySelectorAll('.sub-lb-tab').forEach(t => t.classList.remove('active'));
|
| 2779 |
const games = ['kamba', 'pancha', 'kotta', 'math', 'aliyata', 'kana', 'grease', 'papaya', 'dehi', 'olinda'];
|
| 2780 |
|
| 2781 |
-
if (
|
| 2782 |
-
|
| 2783 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2784 |
|
| 2785 |
// Sport tab highlighting
|
| 2786 |
document.getElementById('lbSportsSelector').style.display = games.includes(type) ? 'block' : 'none';
|
|
@@ -2803,12 +2823,16 @@
|
|
| 2803 |
'olinda': 'OLINDA KELIYA TOP RANKS'
|
| 2804 |
};
|
| 2805 |
const lbTitle = document.getElementById('lbContextTitle');
|
| 2806 |
-
if (lbTitle)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2807 |
|
| 2808 |
const container = document.getElementById('leaderboardContent');
|
| 2809 |
if (container) container.innerHTML = '<div style="text-align:center; padding:40px; color:var(--text-muted); font-size:0.9rem;">๐ฎ Summoning Rankings...</div>';
|
| 2810 |
|
| 2811 |
-
socket.emit('get_leaderboard', { type });
|
| 2812 |
}
|
| 2813 |
|
| 2814 |
async function loadProfile() {
|
|
|
|
| 1301 |
onclick="switchMainLB('global')">๐ Global Arena</div>
|
| 1302 |
</div>
|
| 1303 |
|
| 1304 |
+
<div id="lbSubTabs" style="margin-bottom:15px;">
|
| 1305 |
+
<div id="lbSubHeader" style="display:flex; gap:8px; overflow-x:auto; padding-bottom:5px; scrollbar-width: none;">
|
| 1306 |
+
<!-- Village Sub-tabs -->
|
| 1307 |
+
<div id="villageSubTabs" style="display:flex; gap:8px;">
|
| 1308 |
+
<button class="btn-micro sub-lb-tab active" onclick="switchLB('village_players')">๐ฅ Overall Players</button>
|
| 1309 |
+
<button class="btn-micro sub-lb-tab" onclick="switchLB('pancha')">๐ฒ Village Sports</button>
|
| 1310 |
+
</div>
|
| 1311 |
+
<!-- Global Sub-tabs -->
|
| 1312 |
+
<div id="globalSubTabs" style="display:none; gap:8px;">
|
| 1313 |
+
<button class="btn-micro sub-lb-tab" onclick="switchLB('global')">๐ Overall Players</button>
|
| 1314 |
+
<button class="btn-micro sub-lb-tab" onclick="switchLB('village_rank')">๐๏ธ Village vs Village</button>
|
| 1315 |
+
<button class="btn-micro sub-lb-tab" onclick="switchLB('pancha')">๐ฒ World Sports</button>
|
| 1316 |
+
</div>
|
| 1317 |
</div>
|
| 1318 |
|
| 1319 |
<div id="lbSportsSelector" style="display:none; margin-top:10px; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 10px;">
|
|
|
|
| 2755 |
document.getElementById('leaderboardView').classList.add('active');
|
| 2756 |
const navItem = document.getElementById('navLeaderboard');
|
| 2757 |
if (navItem) navItem.classList.add('active');
|
| 2758 |
+
switchMainLB('village'); // Corrected initialization
|
| 2759 |
} else if (tab === 'profile') {
|
| 2760 |
document.getElementById('profileView').classList.add('active');
|
| 2761 |
const navItem = document.getElementById('navProfile');
|
|
|
|
| 2766 |
if (isHapticsSupported() && tg?.HapticFeedback) tg?.HapticFeedback.impactOccurred('light');
|
| 2767 |
}
|
| 2768 |
|
| 2769 |
+
let currentMainLB = 'village';
|
| 2770 |
+
|
| 2771 |
function switchMainLB(mainType) {
|
| 2772 |
+
currentMainLB = mainType;
|
| 2773 |
document.querySelectorAll('#lbMainTabs .lb-tab').forEach(t => t.classList.remove('active'));
|
| 2774 |
+
|
| 2775 |
if (mainType === 'village') {
|
| 2776 |
document.querySelectorAll('#lbMainTabs .lb-tab')[0].classList.add('active');
|
| 2777 |
+
document.getElementById('villageSubTabs').style.display = 'flex';
|
| 2778 |
+
document.getElementById('globalSubTabs').style.display = 'none';
|
| 2779 |
switchLB('village_players');
|
| 2780 |
} else {
|
| 2781 |
document.querySelectorAll('#lbMainTabs .lb-tab')[1].classList.add('active');
|
| 2782 |
+
document.getElementById('villageSubTabs').style.display = 'none';
|
| 2783 |
+
document.getElementById('globalSubTabs').style.display = 'flex';
|
| 2784 |
switchLB('global');
|
| 2785 |
}
|
| 2786 |
}
|
| 2787 |
|
| 2788 |
function switchLB(type) {
|
| 2789 |
currentLBType = type;
|
| 2790 |
+
const villageOnly = currentMainLB === 'village';
|
| 2791 |
|
| 2792 |
// Sub-tab highlighting
|
| 2793 |
document.querySelectorAll('.sub-lb-tab').forEach(t => t.classList.remove('active'));
|
| 2794 |
const games = ['kamba', 'pancha', 'kotta', 'math', 'aliyata', 'kana', 'grease', 'papaya', 'dehi', 'olinda'];
|
| 2795 |
|
| 2796 |
+
if (currentMainLB === 'village') {
|
| 2797 |
+
if (type === 'village_players') document.querySelectorAll('#villageSubTabs .sub-lb-tab')[0].classList.add('active');
|
| 2798 |
+
else if (games.includes(type)) document.querySelectorAll('#villageSubTabs .sub-lb-tab')[1].classList.add('active');
|
| 2799 |
+
} else {
|
| 2800 |
+
if (type === 'global') document.querySelectorAll('#globalSubTabs .sub-lb-tab')[0].classList.add('active');
|
| 2801 |
+
else if (type === 'village_rank') document.querySelectorAll('#globalSubTabs .sub-lb-tab')[1].classList.add('active');
|
| 2802 |
+
else if (games.includes(type)) document.querySelectorAll('#globalSubTabs .sub-lb-tab')[2].classList.add('active');
|
| 2803 |
+
}
|
| 2804 |
|
| 2805 |
// Sport tab highlighting
|
| 2806 |
document.getElementById('lbSportsSelector').style.display = games.includes(type) ? 'block' : 'none';
|
|
|
|
| 2823 |
'olinda': 'OLINDA KELIYA TOP RANKS'
|
| 2824 |
};
|
| 2825 |
const lbTitle = document.getElementById('lbContextTitle');
|
| 2826 |
+
if (lbTitle) {
|
| 2827 |
+
let contextPrefix = villageOnly ? "VILLAGE " : "GLOBAL ";
|
| 2828 |
+
if (type === 'village_rank') contextPrefix = "";
|
| 2829 |
+
lbTitle.innerText = contextPrefix + (titleMap[type] || type.toUpperCase());
|
| 2830 |
+
}
|
| 2831 |
|
| 2832 |
const container = document.getElementById('leaderboardContent');
|
| 2833 |
if (container) container.innerHTML = '<div style="text-align:center; padding:40px; color:var(--text-muted); font-size:0.9rem;">๐ฎ Summoning Rankings...</div>';
|
| 2834 |
|
| 2835 |
+
socket.emit('get_leaderboard', { type, villageOnly });
|
| 2836 |
}
|
| 2837 |
|
| 2838 |
async function loadProfile() {
|
server/db.js
CHANGED
|
@@ -69,15 +69,19 @@ async function getVillageLeaderboard() {
|
|
| 69 |
return await Village.find().sort({ points: -1 }).limit(10);
|
| 70 |
}
|
| 71 |
|
| 72 |
-
async function getGameLeaderboard(gameType) {
|
| 73 |
const query = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
if (gameType && gameType !== 'global') {
|
| 75 |
query[`gameStats.${gameType}`] = { $gt: 0 };
|
| 76 |
return await User.find(query)
|
| 77 |
.sort({ [`gameStats.${gameType}`]: -1 })
|
| 78 |
.limit(10);
|
| 79 |
}
|
| 80 |
-
return await User.find().sort({ totalWins: -1 }).limit(10);
|
| 81 |
}
|
| 82 |
|
| 83 |
async function getUserProfile(tgId) {
|
|
|
|
| 69 |
return await Village.find().sort({ points: -1 }).limit(10);
|
| 70 |
}
|
| 71 |
|
| 72 |
+
async function getGameLeaderboard(gameType, villageId = null) {
|
| 73 |
const query = {};
|
| 74 |
+
if (villageId && villageId !== 'Global' && villageId !== 'Global Village') {
|
| 75 |
+
query.lastVillageId = villageId;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
if (gameType && gameType !== 'global') {
|
| 79 |
query[`gameStats.${gameType}`] = { $gt: 0 };
|
| 80 |
return await User.find(query)
|
| 81 |
.sort({ [`gameStats.${gameType}`]: -1 })
|
| 82 |
.limit(10);
|
| 83 |
}
|
| 84 |
+
return await User.find(query).sort({ totalWins: -1 }).limit(10);
|
| 85 |
}
|
| 86 |
|
| 87 |
async function getUserProfile(tgId) {
|
server/index.js
CHANGED
|
@@ -274,21 +274,22 @@ io.on('connection', (socket) => {
|
|
| 274 |
|
| 275 |
socket.on('get_leaderboard', async (data) => {
|
| 276 |
const type = data.type || 'global';
|
|
|
|
| 277 |
try {
|
| 278 |
let result = [];
|
| 279 |
const games = ['kamba', 'pancha', 'kotta', 'math', 'aliyata', 'kana', 'grease', 'papaya', 'dehi', 'olinda'];
|
|
|
|
| 280 |
|
| 281 |
if (type === 'global') {
|
| 282 |
-
result = await db.getGameLeaderboard('global');
|
| 283 |
} else if (type === 'village_rank') {
|
| 284 |
result = await db.getVillageLeaderboard();
|
| 285 |
} else if (type === 'village_players') {
|
| 286 |
-
const vId = socket.handshake.query.villageId;
|
| 287 |
result = await db.getVillagePlayers(vId);
|
| 288 |
} else if (games.includes(type)) {
|
| 289 |
-
result = await db.getGameLeaderboard(type);
|
| 290 |
} else {
|
| 291 |
-
result = await db.getGameLeaderboard('global');
|
| 292 |
}
|
| 293 |
socket.emit('leaderboard_data', result || []);
|
| 294 |
} catch (err) {
|
|
|
|
| 274 |
|
| 275 |
socket.on('get_leaderboard', async (data) => {
|
| 276 |
const type = data.type || 'global';
|
| 277 |
+
const villageOnly = data.villageOnly || false;
|
| 278 |
try {
|
| 279 |
let result = [];
|
| 280 |
const games = ['kamba', 'pancha', 'kotta', 'math', 'aliyata', 'kana', 'grease', 'papaya', 'dehi', 'olinda'];
|
| 281 |
+
const vId = socket.handshake.query.villageId;
|
| 282 |
|
| 283 |
if (type === 'global') {
|
| 284 |
+
result = await db.getGameLeaderboard('global', villageOnly ? vId : null);
|
| 285 |
} else if (type === 'village_rank') {
|
| 286 |
result = await db.getVillageLeaderboard();
|
| 287 |
} else if (type === 'village_players') {
|
|
|
|
| 288 |
result = await db.getVillagePlayers(vId);
|
| 289 |
} else if (games.includes(type)) {
|
| 290 |
+
result = await db.getGameLeaderboard(type, villageOnly ? vId : null);
|
| 291 |
} else {
|
| 292 |
+
result = await db.getGameLeaderboard('global', villageOnly ? vId : null);
|
| 293 |
}
|
| 294 |
socket.emit('leaderboard_data', result || []);
|
| 295 |
} catch (err) {
|