Spaces:
Sleeping
Sleeping
Commit
·
a7d41bc
1
Parent(s):
a4a9194
fix(vs-people): initialize socket listeners when switching game modes
Browse files
trigo-web/app/dist/assets/{index-BsbKWb8A.js → index-CMsE5CnF.js}
RENAMED
|
The diff for this file is too large to render.
See raw diff
|
|
|
trigo-web/app/dist/index.html
CHANGED
|
@@ -5,7 +5,7 @@
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Trigo - 3D Go Game</title>
|
| 8 |
-
<script type="module" crossorigin src="/assets/index-
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-Siwlapuk.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
|
|
|
| 5 |
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
<title>Trigo - 3D Go Game</title>
|
| 8 |
+
<script type="module" crossorigin src="/assets/index-CMsE5CnF.js"></script>
|
| 9 |
<link rel="stylesheet" crossorigin href="/assets/index-Siwlapuk.css">
|
| 10 |
</head>
|
| 11 |
<body>
|
trigo-web/app/src/views/TrigoView.vue
CHANGED
|
@@ -1392,6 +1392,220 @@
|
|
| 1392 |
}
|
| 1393 |
});
|
| 1394 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1395 |
// Lifecycle hooks
|
| 1396 |
onMounted(() => {
|
| 1397 |
console.log("[TrigoView] Component mounted, gameMode:", gameMode.value, "route.path:", route.path, "route.meta.mode:", route.meta.mode);
|
|
@@ -1471,187 +1685,30 @@
|
|
| 1471 |
});
|
| 1472 |
}
|
| 1473 |
|
| 1474 |
-
//
|
| 1475 |
if (gameMode.value === "vs-people") {
|
| 1476 |
-
|
| 1477 |
-
|
| 1478 |
-
// Listen for nickname changes
|
| 1479 |
-
socketApi.onNicknameChanged((data) => {
|
| 1480 |
-
console.log(
|
| 1481 |
-
`[TrigoView] Player ${data.playerId} changed nickname: ${data.oldNickname} -> ${data.nickname}`
|
| 1482 |
-
);
|
| 1483 |
-
|
| 1484 |
-
// If it's not us, update opponent nickname
|
| 1485 |
-
if (data.playerId !== socketApi.socket.id) {
|
| 1486 |
-
playerStore.setOpponentNickname(data.nickname);
|
| 1487 |
-
}
|
| 1488 |
-
});
|
| 1489 |
-
|
| 1490 |
-
// Listen for game updates (moves, passes, undo, redo)
|
| 1491 |
-
socketApi.onGameUpdate((data) => {
|
| 1492 |
-
console.log("[TrigoView] Game update received:", data);
|
| 1493 |
-
|
| 1494 |
-
// Update current player from server
|
| 1495 |
-
if (data.currentPlayer) {
|
| 1496 |
-
gameStore.setCurrentPlayer(data.currentPlayer);
|
| 1497 |
-
}
|
| 1498 |
-
|
| 1499 |
-
// Handle different actions
|
| 1500 |
-
if (data.action === "move" && data.lastMove) {
|
| 1501 |
-
const { x, y, z } = data.lastMove;
|
| 1502 |
-
// Apply move to local game state
|
| 1503 |
-
const result = gameStore.makeMove(x, y, z);
|
| 1504 |
-
|
| 1505 |
-
if (result.success && viewport) {
|
| 1506 |
-
// Add stone to viewport
|
| 1507 |
-
const stoneColor = gameStore.opponentPlayer;
|
| 1508 |
-
viewport.addStone(x, y, z, stoneColor);
|
| 1509 |
-
|
| 1510 |
-
// Remove captured stones
|
| 1511 |
-
if (data.capturedPositions && data.capturedPositions.length > 0) {
|
| 1512 |
-
data.capturedPositions.forEach((pos: { x: number; y: number; z: number }) => {
|
| 1513 |
-
viewport.removeStone(pos.x, pos.y, pos.z);
|
| 1514 |
-
});
|
| 1515 |
-
console.log(`[TrigoView] Captured ${data.capturedPositions.length} stone(s)`);
|
| 1516 |
-
}
|
| 1517 |
-
|
| 1518 |
-
// Hide territory visualization
|
| 1519 |
-
viewport.hideDomainCubes();
|
| 1520 |
-
showTerritoryMode.value = false;
|
| 1521 |
-
}
|
| 1522 |
-
} else if (data.action === "pass") {
|
| 1523 |
-
gameStore.pass();
|
| 1524 |
-
console.log("[TrigoView] Pass received from server");
|
| 1525 |
-
} else if (data.action === "undo" || data.action === "redo") {
|
| 1526 |
-
// For undo/redo, reload game from TGN
|
| 1527 |
-
if (data.tgn && viewport) {
|
| 1528 |
-
gameStore.loadFromTGN(data.tgn);
|
| 1529 |
-
// Resync viewport with game state
|
| 1530 |
-
viewport.clearBoard();
|
| 1531 |
-
syncViewportWithGame();
|
| 1532 |
-
}
|
| 1533 |
-
}
|
| 1534 |
-
});
|
| 1535 |
-
|
| 1536 |
-
// Listen for player joined
|
| 1537 |
-
socketApi.onPlayerJoined((data) => {
|
| 1538 |
-
console.log("[TrigoView] Player joined:", data);
|
| 1539 |
-
playerStore.setOpponentNickname(data.nickname);
|
| 1540 |
-
|
| 1541 |
-
// Start game when second player joins
|
| 1542 |
-
if (!gameStarted.value) {
|
| 1543 |
-
gameStore.startGame();
|
| 1544 |
-
if (viewport) {
|
| 1545 |
-
viewport.setGameActive(true);
|
| 1546 |
-
}
|
| 1547 |
-
console.log("[TrigoView] Game started - opponent joined");
|
| 1548 |
-
}
|
| 1549 |
-
});
|
| 1550 |
-
|
| 1551 |
-
// Listen for player left
|
| 1552 |
-
socketApi.onPlayerLeft((data) => {
|
| 1553 |
-
console.log("[TrigoView] Player left:", data);
|
| 1554 |
-
playerStore.setOpponentNickname(null);
|
| 1555 |
-
});
|
| 1556 |
-
|
| 1557 |
-
// Listen for player disconnected
|
| 1558 |
-
socketApi.onPlayerDisconnected((data) => {
|
| 1559 |
-
console.log("[TrigoView] Player disconnected:", data);
|
| 1560 |
-
if (data.playerId !== socketApi.socket.id) {
|
| 1561 |
-
playerStore.setOpponentNickname(null);
|
| 1562 |
-
}
|
| 1563 |
-
});
|
| 1564 |
-
|
| 1565 |
-
// Listen for game ended
|
| 1566 |
-
socketApi.onGameEnded((data) => {
|
| 1567 |
-
console.log("[TrigoView] Game ended:", data);
|
| 1568 |
-
alert(`Game ended! Winner: ${data.winner || "None"}\nReason: ${data.reason}`);
|
| 1569 |
-
});
|
| 1570 |
-
|
| 1571 |
-
// Listen for game reset
|
| 1572 |
-
socketApi.onGameReset((data) => {
|
| 1573 |
-
console.log("[TrigoView] Game reset:", data);
|
| 1574 |
-
// Reload game state
|
| 1575 |
-
if (data.tgn) {
|
| 1576 |
-
gameStore.loadFromTGN(data.tgn);
|
| 1577 |
-
} else {
|
| 1578 |
-
gameStore.resetGame(boardShape.value);
|
| 1579 |
-
}
|
| 1580 |
-
if (viewport) {
|
| 1581 |
-
viewport.clearBoard();
|
| 1582 |
-
}
|
| 1583 |
-
// Update player colors if changed
|
| 1584 |
-
if (data.players && socketApi.socket.id) {
|
| 1585 |
-
const myPlayer = data.players[socketApi.socket.id];
|
| 1586 |
-
if (myPlayer) {
|
| 1587 |
-
playerStore.playerColor = myPlayer.color;
|
| 1588 |
-
}
|
| 1589 |
-
}
|
| 1590 |
-
});
|
| 1591 |
-
|
| 1592 |
-
// Listen for errors
|
| 1593 |
-
socketApi.onError((data) => {
|
| 1594 |
-
console.error("[TrigoView] Socket error:", data.message);
|
| 1595 |
-
});
|
| 1596 |
-
|
| 1597 |
-
// Setup room list listeners for room selector
|
| 1598 |
-
setupRoomListeners();
|
| 1599 |
-
|
| 1600 |
-
// Set player ID when socket connects
|
| 1601 |
-
if (socketApi.socket.id) {
|
| 1602 |
-
playerStore.setPlayerId(socketApi.socket.id);
|
| 1603 |
-
}
|
| 1604 |
-
|
| 1605 |
-
// Listen for browser navigation (back/forward) and URL changes
|
| 1606 |
-
window.addEventListener("popstate", handleUrlChange);
|
| 1607 |
-
|
| 1608 |
-
// Handle socket connection and reconnection
|
| 1609 |
-
socketApi.socket.on("connect", () => {
|
| 1610 |
-
console.log("[TrigoView] Socket connected in VS People mode");
|
| 1611 |
-
|
| 1612 |
-
// Update player ID and connection status
|
| 1613 |
-
if (socketApi.socket.id) {
|
| 1614 |
-
playerStore.setPlayerId(socketApi.socket.id);
|
| 1615 |
-
}
|
| 1616 |
-
|
| 1617 |
-
// Fetch room list for room selector
|
| 1618 |
-
fetchRoomList();
|
| 1619 |
-
|
| 1620 |
-
// Initialize room based on URL hash (only if not already in a room)
|
| 1621 |
-
if (!playerStore.roomId && !isJoiningRoom.value) {
|
| 1622 |
-
console.log("[TrigoView] Initializing room after socket connection");
|
| 1623 |
-
initializeMultiplayerRoom();
|
| 1624 |
-
}
|
| 1625 |
-
});
|
| 1626 |
-
|
| 1627 |
-
// Handle socket disconnection
|
| 1628 |
-
socketApi.socket.on("disconnect", () => {
|
| 1629 |
-
console.log("[TrigoView] Socket disconnected in VS People mode");
|
| 1630 |
-
// Don't reset roomId - we want to rejoin on reconnect
|
| 1631 |
-
if (playerStore.roomId) {
|
| 1632 |
-
playerStore.connectionStatus = "connected"; // Still have room info, just disconnected
|
| 1633 |
-
} else {
|
| 1634 |
-
playerStore.disconnect();
|
| 1635 |
-
}
|
| 1636 |
-
});
|
| 1637 |
-
|
| 1638 |
-
// If socket is already connected, initialize room immediately
|
| 1639 |
-
if (socketApi.socket.connected) {
|
| 1640 |
-
console.log("[TrigoView] Socket already connected, initializing room");
|
| 1641 |
-
fetchRoomList();
|
| 1642 |
-
initializeMultiplayerRoom();
|
| 1643 |
-
}
|
| 1644 |
}
|
| 1645 |
|
| 1646 |
// Add keyboard shortcuts
|
| 1647 |
window.addEventListener("keydown", handleKeyPress);
|
| 1648 |
});
|
| 1649 |
|
| 1650 |
-
// Watch for game mode changes and initialize
|
| 1651 |
watch(gameMode, (newMode, oldMode) => {
|
| 1652 |
console.log(`[TrigoView] Game mode changed: ${oldMode} -> ${newMode}`);
|
| 1653 |
|
| 1654 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1655 |
console.log("[TrigoView] Switching to VS AI mode, initializing AI agent...");
|
| 1656 |
aiAgent.initialize()
|
| 1657 |
.then(() => {
|
|
@@ -1674,22 +1731,8 @@
|
|
| 1674 |
// Remove keyboard shortcuts
|
| 1675 |
window.removeEventListener("keydown", handleKeyPress);
|
| 1676 |
|
| 1677 |
-
// Cleanup
|
| 1678 |
-
|
| 1679 |
-
console.log("[TrigoView] Cleaning up socket listeners...");
|
| 1680 |
-
socketApi.offNicknameChanged();
|
| 1681 |
-
socketApi.offGameUpdate();
|
| 1682 |
-
socketApi.offPlayerJoined();
|
| 1683 |
-
socketApi.offPlayerLeft();
|
| 1684 |
-
socketApi.offPlayerDisconnected();
|
| 1685 |
-
socketApi.offGameEnded();
|
| 1686 |
-
socketApi.offGameReset();
|
| 1687 |
-
socketApi.offError();
|
| 1688 |
-
cleanupRoomListeners();
|
| 1689 |
-
|
| 1690 |
-
// Remove URL change listener
|
| 1691 |
-
window.removeEventListener("popstate", handleUrlChange);
|
| 1692 |
-
}
|
| 1693 |
|
| 1694 |
// Disconnect ResizeObserver
|
| 1695 |
if (resizeObserver) {
|
|
|
|
| 1392 |
}
|
| 1393 |
});
|
| 1394 |
|
| 1395 |
+
|
| 1396 |
+
// Flag to track if VS People mode has been initialized
|
| 1397 |
+
let vsPeopleModeInitialized = false;
|
| 1398 |
+
|
| 1399 |
+
// Initialize VS People mode - sets up all socket event listeners
|
| 1400 |
+
const initializeVsPeopleMode = () => {
|
| 1401 |
+
if (vsPeopleModeInitialized) {
|
| 1402 |
+
console.log("[TrigoView] VS People mode already initialized, skipping...");
|
| 1403 |
+
return;
|
| 1404 |
+
}
|
| 1405 |
+
|
| 1406 |
+
console.log("[TrigoView] Initializing VS People mode...");
|
| 1407 |
+
vsPeopleModeInitialized = true;
|
| 1408 |
+
|
| 1409 |
+
// Listen for nickname changes
|
| 1410 |
+
socketApi.onNicknameChanged((data) => {
|
| 1411 |
+
console.log(
|
| 1412 |
+
`[TrigoView] Player ${data.playerId} changed nickname: ${data.oldNickname} -> ${data.nickname}`
|
| 1413 |
+
);
|
| 1414 |
+
|
| 1415 |
+
// If it's not us, update opponent nickname
|
| 1416 |
+
if (data.playerId !== socketApi.socket.id) {
|
| 1417 |
+
playerStore.setOpponentNickname(data.nickname);
|
| 1418 |
+
}
|
| 1419 |
+
});
|
| 1420 |
+
|
| 1421 |
+
// Listen for game updates (moves, passes, undo, redo)
|
| 1422 |
+
socketApi.onGameUpdate((data) => {
|
| 1423 |
+
console.log("[TrigoView] Game update received:", data);
|
| 1424 |
+
|
| 1425 |
+
// Update current player from server
|
| 1426 |
+
if (data.currentPlayer) {
|
| 1427 |
+
gameStore.setCurrentPlayer(data.currentPlayer);
|
| 1428 |
+
}
|
| 1429 |
+
|
| 1430 |
+
// Handle different actions
|
| 1431 |
+
if (data.action === "move" && data.lastMove) {
|
| 1432 |
+
const { x, y, z } = data.lastMove;
|
| 1433 |
+
// Apply move to local game state
|
| 1434 |
+
const result = gameStore.makeMove(x, y, z);
|
| 1435 |
+
|
| 1436 |
+
if (result.success && viewport) {
|
| 1437 |
+
// Add stone to viewport
|
| 1438 |
+
const stoneColor = gameStore.opponentPlayer;
|
| 1439 |
+
viewport.addStone(x, y, z, stoneColor);
|
| 1440 |
+
|
| 1441 |
+
// Remove captured stones
|
| 1442 |
+
if (data.capturedPositions && data.capturedPositions.length > 0) {
|
| 1443 |
+
data.capturedPositions.forEach((pos: { x: number; y: number; z: number }) => {
|
| 1444 |
+
viewport.removeStone(pos.x, pos.y, pos.z);
|
| 1445 |
+
});
|
| 1446 |
+
console.log(`[TrigoView] Captured ${data.capturedPositions.length} stone(s)`);
|
| 1447 |
+
}
|
| 1448 |
+
|
| 1449 |
+
// Hide territory visualization
|
| 1450 |
+
viewport.hideDomainCubes();
|
| 1451 |
+
showTerritoryMode.value = false;
|
| 1452 |
+
}
|
| 1453 |
+
} else if (data.action === "pass") {
|
| 1454 |
+
gameStore.pass();
|
| 1455 |
+
console.log("[TrigoView] Pass received from server");
|
| 1456 |
+
} else if (data.action === "undo" || data.action === "redo") {
|
| 1457 |
+
// For undo/redo, reload game from TGN
|
| 1458 |
+
if (data.tgn && viewport) {
|
| 1459 |
+
gameStore.loadFromTGN(data.tgn);
|
| 1460 |
+
// Resync viewport with game state
|
| 1461 |
+
viewport.clearBoard();
|
| 1462 |
+
syncViewportWithGame();
|
| 1463 |
+
}
|
| 1464 |
+
}
|
| 1465 |
+
});
|
| 1466 |
+
|
| 1467 |
+
// Listen for player joined
|
| 1468 |
+
socketApi.onPlayerJoined((data) => {
|
| 1469 |
+
console.log("[TrigoView] Player joined:", data);
|
| 1470 |
+
playerStore.setOpponentNickname(data.nickname);
|
| 1471 |
+
|
| 1472 |
+
// Start game when second player joins
|
| 1473 |
+
if (!gameStarted.value) {
|
| 1474 |
+
gameStore.startGame();
|
| 1475 |
+
if (viewport) {
|
| 1476 |
+
viewport.setGameActive(true);
|
| 1477 |
+
}
|
| 1478 |
+
console.log("[TrigoView] Game started - opponent joined");
|
| 1479 |
+
}
|
| 1480 |
+
});
|
| 1481 |
+
|
| 1482 |
+
// Listen for player left
|
| 1483 |
+
socketApi.onPlayerLeft((data) => {
|
| 1484 |
+
console.log("[TrigoView] Player left:", data);
|
| 1485 |
+
playerStore.setOpponentNickname(null);
|
| 1486 |
+
});
|
| 1487 |
+
|
| 1488 |
+
// Listen for player disconnected
|
| 1489 |
+
socketApi.onPlayerDisconnected((data) => {
|
| 1490 |
+
console.log("[TrigoView] Player disconnected:", data);
|
| 1491 |
+
if (data.playerId !== socketApi.socket.id) {
|
| 1492 |
+
playerStore.setOpponentNickname(null);
|
| 1493 |
+
}
|
| 1494 |
+
});
|
| 1495 |
+
|
| 1496 |
+
// Listen for game ended
|
| 1497 |
+
socketApi.onGameEnded((data) => {
|
| 1498 |
+
console.log("[TrigoView] Game ended:", data);
|
| 1499 |
+
alert(`Game ended! Winner: ${data.winner || "None"}\nReason: ${data.reason}`);
|
| 1500 |
+
});
|
| 1501 |
+
|
| 1502 |
+
// Listen for game reset
|
| 1503 |
+
socketApi.onGameReset((data) => {
|
| 1504 |
+
console.log("[TrigoView] Game reset:", data);
|
| 1505 |
+
// Reload game state
|
| 1506 |
+
if (data.tgn) {
|
| 1507 |
+
gameStore.loadFromTGN(data.tgn);
|
| 1508 |
+
} else {
|
| 1509 |
+
gameStore.resetGame(boardShape.value);
|
| 1510 |
+
}
|
| 1511 |
+
if (viewport) {
|
| 1512 |
+
viewport.clearBoard();
|
| 1513 |
+
}
|
| 1514 |
+
// Update player colors if changed
|
| 1515 |
+
if (data.players && socketApi.socket.id) {
|
| 1516 |
+
const myPlayer = data.players[socketApi.socket.id];
|
| 1517 |
+
if (myPlayer) {
|
| 1518 |
+
playerStore.playerColor = myPlayer.color;
|
| 1519 |
+
}
|
| 1520 |
+
}
|
| 1521 |
+
});
|
| 1522 |
+
|
| 1523 |
+
// Listen for errors
|
| 1524 |
+
socketApi.onError((data) => {
|
| 1525 |
+
console.error("[TrigoView] Socket error:", data.message);
|
| 1526 |
+
});
|
| 1527 |
+
|
| 1528 |
+
// Setup room list listeners for room selector
|
| 1529 |
+
setupRoomListeners();
|
| 1530 |
+
|
| 1531 |
+
// Set player ID when socket connects
|
| 1532 |
+
if (socketApi.socket.id) {
|
| 1533 |
+
playerStore.setPlayerId(socketApi.socket.id);
|
| 1534 |
+
}
|
| 1535 |
+
|
| 1536 |
+
// Listen for browser navigation (back/forward) and URL changes
|
| 1537 |
+
window.addEventListener("popstate", handleUrlChange);
|
| 1538 |
+
|
| 1539 |
+
// Handle socket connection and reconnection
|
| 1540 |
+
socketApi.socket.on("connect", () => {
|
| 1541 |
+
console.log("[TrigoView] Socket connected in VS People mode");
|
| 1542 |
+
|
| 1543 |
+
// Update player ID and connection status
|
| 1544 |
+
if (socketApi.socket.id) {
|
| 1545 |
+
playerStore.setPlayerId(socketApi.socket.id);
|
| 1546 |
+
}
|
| 1547 |
+
|
| 1548 |
+
// Fetch room list for room selector
|
| 1549 |
+
fetchRoomList();
|
| 1550 |
+
|
| 1551 |
+
// Initialize room based on URL hash (only if not already in a room)
|
| 1552 |
+
if (!playerStore.roomId && !isJoiningRoom.value) {
|
| 1553 |
+
console.log("[TrigoView] Initializing room after socket connection");
|
| 1554 |
+
initializeMultiplayerRoom();
|
| 1555 |
+
}
|
| 1556 |
+
});
|
| 1557 |
+
|
| 1558 |
+
// Handle socket disconnection
|
| 1559 |
+
socketApi.socket.on("disconnect", () => {
|
| 1560 |
+
console.log("[TrigoView] Socket disconnected in VS People mode");
|
| 1561 |
+
// Don't reset roomId - we want to rejoin on reconnect
|
| 1562 |
+
if (playerStore.roomId) {
|
| 1563 |
+
playerStore.connectionStatus = "connected"; // Still have room info, just disconnected
|
| 1564 |
+
} else {
|
| 1565 |
+
playerStore.disconnect();
|
| 1566 |
+
}
|
| 1567 |
+
});
|
| 1568 |
+
|
| 1569 |
+
// If socket is already connected, initialize room immediately
|
| 1570 |
+
if (socketApi.socket.connected) {
|
| 1571 |
+
console.log("[TrigoView] Socket already connected, initializing room");
|
| 1572 |
+
fetchRoomList();
|
| 1573 |
+
initializeMultiplayerRoom();
|
| 1574 |
+
}
|
| 1575 |
+
};
|
| 1576 |
+
|
| 1577 |
+
|
| 1578 |
+
// Cleanup VS People mode - removes all socket event listeners
|
| 1579 |
+
const cleanupVsPeopleMode = () => {
|
| 1580 |
+
if (!vsPeopleModeInitialized) {
|
| 1581 |
+
return;
|
| 1582 |
+
}
|
| 1583 |
+
|
| 1584 |
+
console.log("[TrigoView] Cleaning up VS People mode...");
|
| 1585 |
+
vsPeopleModeInitialized = false;
|
| 1586 |
+
|
| 1587 |
+
socketApi.offNicknameChanged();
|
| 1588 |
+
socketApi.offGameUpdate();
|
| 1589 |
+
socketApi.offPlayerJoined();
|
| 1590 |
+
socketApi.offPlayerLeft();
|
| 1591 |
+
socketApi.offPlayerDisconnected();
|
| 1592 |
+
socketApi.offGameEnded();
|
| 1593 |
+
socketApi.offGameReset();
|
| 1594 |
+
socketApi.offError();
|
| 1595 |
+
cleanupRoomListeners();
|
| 1596 |
+
|
| 1597 |
+
// Remove URL change listener
|
| 1598 |
+
window.removeEventListener("popstate", handleUrlChange);
|
| 1599 |
+
|
| 1600 |
+
// Remove socket event listeners
|
| 1601 |
+
socketApi.socket.off("connect");
|
| 1602 |
+
socketApi.socket.off("disconnect");
|
| 1603 |
+
|
| 1604 |
+
// Reset player store state
|
| 1605 |
+
playerStore.disconnect();
|
| 1606 |
+
};
|
| 1607 |
+
|
| 1608 |
+
|
| 1609 |
// Lifecycle hooks
|
| 1610 |
onMounted(() => {
|
| 1611 |
console.log("[TrigoView] Component mounted, gameMode:", gameMode.value, "route.path:", route.path, "route.meta.mode:", route.meta.mode);
|
|
|
|
| 1685 |
});
|
| 1686 |
}
|
| 1687 |
|
| 1688 |
+
// Initialize VS People mode if needed
|
| 1689 |
if (gameMode.value === "vs-people") {
|
| 1690 |
+
initializeVsPeopleMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1691 |
}
|
| 1692 |
|
| 1693 |
// Add keyboard shortcuts
|
| 1694 |
window.addEventListener("keydown", handleKeyPress);
|
| 1695 |
});
|
| 1696 |
|
| 1697 |
+
// Watch for game mode changes and initialize modes as needed
|
| 1698 |
watch(gameMode, (newMode, oldMode) => {
|
| 1699 |
console.log(`[TrigoView] Game mode changed: ${oldMode} -> ${newMode}`);
|
| 1700 |
|
| 1701 |
+
// Cleanup previous mode
|
| 1702 |
+
if (oldMode === "vs-people") {
|
| 1703 |
+
console.log("[TrigoView] Switching away from VS People mode, cleaning up...");
|
| 1704 |
+
cleanupVsPeopleMode();
|
| 1705 |
+
}
|
| 1706 |
+
|
| 1707 |
+
// Initialize new mode
|
| 1708 |
+
if (newMode === "vs-people") {
|
| 1709 |
+
console.log("[TrigoView] Switching to VS People mode, initializing...");
|
| 1710 |
+
initializeVsPeopleMode();
|
| 1711 |
+
} else if (newMode === "vs-ai" && !aiReady.value) {
|
| 1712 |
console.log("[TrigoView] Switching to VS AI mode, initializing AI agent...");
|
| 1713 |
aiAgent.initialize()
|
| 1714 |
.then(() => {
|
|
|
|
| 1731 |
// Remove keyboard shortcuts
|
| 1732 |
window.removeEventListener("keydown", handleKeyPress);
|
| 1733 |
|
| 1734 |
+
// Cleanup VS People mode if active
|
| 1735 |
+
cleanupVsPeopleMode();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1736 |
|
| 1737 |
// Disconnect ResizeObserver
|
| 1738 |
if (resizeObserver) {
|
trigo-web/app/test-frontend-flow.cjs
DELETED
|
@@ -1,62 +0,0 @@
|
|
| 1 |
-
const { io } = require('socket.io-client');
|
| 2 |
-
|
| 3 |
-
console.log('=== Testing Frontend Flow on HF Space ===');
|
| 4 |
-
console.log('');
|
| 5 |
-
|
| 6 |
-
const serverUrl = 'https://k-l-lambda-trigo.hf.space';
|
| 7 |
-
console.log('[1] Creating socket with URL:', serverUrl);
|
| 8 |
-
|
| 9 |
-
let socketConnectedOnCreate = false;
|
| 10 |
-
const socket = io(serverUrl, {
|
| 11 |
-
autoConnect: true,
|
| 12 |
-
reconnection: true,
|
| 13 |
-
transports: ['polling', 'websocket']
|
| 14 |
-
});
|
| 15 |
-
|
| 16 |
-
// Check if connected immediately (before setting up listeners)
|
| 17 |
-
console.log('[2] Socket connected immediately after create?', socket.connected);
|
| 18 |
-
socketConnectedOnCreate = socket.connected;
|
| 19 |
-
|
| 20 |
-
// Set up connect listener (simulating what useSocket does)
|
| 21 |
-
socket.on('connect', () => {
|
| 22 |
-
console.log('[3a] Socket connect event fired! ID:', socket.id);
|
| 23 |
-
console.log('[3b] Socket.connected value:', socket.connected);
|
| 24 |
-
});
|
| 25 |
-
|
| 26 |
-
// Simulate onMounted running "shortly after"
|
| 27 |
-
setTimeout(() => {
|
| 28 |
-
console.log('');
|
| 29 |
-
console.log('[4] === Simulating onMounted ===');
|
| 30 |
-
console.log('[4a] gameMode is "vs-people" (assumed)');
|
| 31 |
-
console.log('[4b] Setting up connect listener in TrigoView...');
|
| 32 |
-
|
| 33 |
-
// This is what TrigoView does - set up another connect listener
|
| 34 |
-
socket.on('connect', () => {
|
| 35 |
-
console.log('[5] TrigoView connect listener fired!');
|
| 36 |
-
console.log('[5a] Would call fetchRoomList() here');
|
| 37 |
-
|
| 38 |
-
socket.emit('listRooms', (response) => {
|
| 39 |
-
console.log('[5b] listRooms response:', JSON.stringify(response));
|
| 40 |
-
});
|
| 41 |
-
});
|
| 42 |
-
|
| 43 |
-
// Check if socket is already connected
|
| 44 |
-
console.log('[4c] socket.connected at onMounted time:', socket.connected);
|
| 45 |
-
|
| 46 |
-
if (socket.connected) {
|
| 47 |
-
console.log('[4d] Socket already connected, calling fetchRoomList directly');
|
| 48 |
-
socket.emit('listRooms', (response) => {
|
| 49 |
-
console.log('[4e] listRooms response:', JSON.stringify(response));
|
| 50 |
-
socket.disconnect();
|
| 51 |
-
process.exit(0);
|
| 52 |
-
});
|
| 53 |
-
} else {
|
| 54 |
-
console.log('[4d] Socket not connected yet, waiting for connect event');
|
| 55 |
-
}
|
| 56 |
-
}, 100); // Small delay to simulate Vue's mounting
|
| 57 |
-
|
| 58 |
-
setTimeout(() => {
|
| 59 |
-
console.log('Timeout - test complete');
|
| 60 |
-
socket.disconnect();
|
| 61 |
-
process.exit(0);
|
| 62 |
-
}, 10000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
trigo-web/app/test-hf-rooms.cjs
DELETED
|
@@ -1,41 +0,0 @@
|
|
| 1 |
-
const { io } = require('socket.io-client');
|
| 2 |
-
|
| 3 |
-
const socket = io('https://k-l-lambda-trigo.hf.space', {
|
| 4 |
-
transports: ['websocket', 'polling'],
|
| 5 |
-
timeout: 10000
|
| 6 |
-
});
|
| 7 |
-
|
| 8 |
-
socket.on('connect', () => {
|
| 9 |
-
console.log('Connected to HF Space, socket id:', socket.id);
|
| 10 |
-
|
| 11 |
-
// Test listRooms
|
| 12 |
-
console.log('Calling listRooms...');
|
| 13 |
-
socket.emit('listRooms', (response) => {
|
| 14 |
-
console.log('listRooms response:', JSON.stringify(response, null, 2));
|
| 15 |
-
|
| 16 |
-
// Create a room to test
|
| 17 |
-
console.log('Creating a room...');
|
| 18 |
-
socket.emit('joinRoom', { nickname: 'TestBot' }, (joinResponse) => {
|
| 19 |
-
console.log('joinRoom response:', JSON.stringify(joinResponse, null, 2));
|
| 20 |
-
|
| 21 |
-
// List rooms again
|
| 22 |
-
setTimeout(() => {
|
| 23 |
-
socket.emit('listRooms', (response2) => {
|
| 24 |
-
console.log('listRooms after create:', JSON.stringify(response2, null, 2));
|
| 25 |
-
socket.disconnect();
|
| 26 |
-
process.exit(0);
|
| 27 |
-
});
|
| 28 |
-
}, 500);
|
| 29 |
-
});
|
| 30 |
-
});
|
| 31 |
-
});
|
| 32 |
-
|
| 33 |
-
socket.on('connect_error', (err) => {
|
| 34 |
-
console.error('Connection error:', err.message);
|
| 35 |
-
process.exit(1);
|
| 36 |
-
});
|
| 37 |
-
|
| 38 |
-
setTimeout(() => {
|
| 39 |
-
console.log('Timeout - no response');
|
| 40 |
-
process.exit(1);
|
| 41 |
-
}, 15000);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|