Send shipping route weather layout to multiplayer server

This commit is contained in:
Admin 2026-09-21 06:34:35 +00:00
parent 06b47c8ebf
commit 05d9c11075

View File

@ -22,6 +22,7 @@ let inputSequence = 0;
let profile = null; let profile = null;
let selfSnapshot = null; let selfSnapshot = null;
let worldSeed = 'SKYWARD-001'; let worldSeed = 'SKYWARD-001';
let weatherRoutes = [];
let multiplayerEnabled = localStorage.getItem(MULTIPLAYER_ENABLED_KEY) !== 'false'; let multiplayerEnabled = localStorage.getItem(MULTIPLAYER_ENABLED_KEY) !== 'false';
const statusButton = document.createElement('button'); const statusButton = document.createElement('button');
@ -148,6 +149,7 @@ const connect = async () => {
inputSequence = 0; inputSequence = 0;
setStatus('online'); setStatus('online');
emitConnection('online'); emitConnection('online');
sendWeatherLayout();
}); });
ws.addEventListener('message', (event) => { ws.addEventListener('message', (event) => {
@ -217,6 +219,29 @@ const sendInput = (input = {}) => {
return inputSequence; return inputSequence;
}; };
const sendWeatherLayout = () => {
if (socket?.readyState !== WebSocket.OPEN || weatherRoutes.length === 0) return false;
socket.send(JSON.stringify({
type: 'weather-layout',
routes: weatherRoutes,
}));
return true;
};
const setWeatherRoutes = (routes = []) => {
weatherRoutes = (routes || [])
.slice(0, 24)
.map((route) => ({
id: String(route?.id || ''),
fromX: Number(route?.from?.x) || 0,
fromY: Number(route?.from?.y) || 0,
toX: Number(route?.to?.x) || 0,
toY: Number(route?.to?.y) || 0,
width: Number(route?.width) || 220,
}));
sendWeatherLayout();
};
const fire = (side) => { const fire = (side) => {
if (socket?.readyState !== WebSocket.OPEN) return false; if (socket?.readyState !== WebSocket.OPEN) return false;
const normalized = side === 'port' || side === -1 ? 'port' : 'starboard'; const normalized = side === 'port' || side === -1 ? 'port' : 'starboard';
@ -270,6 +295,7 @@ window.airshipMultiplayer = {
logout, logout,
connect, connect,
setEnabled, setEnabled,
setWeatherRoutes,
getState, getState,
getSelfId: () => selfId, getSelfId: () => selfId,
isAuthenticated: () => authenticated, isAuthenticated: () => authenticated,