Send shipping route weather layout to multiplayer server
This commit is contained in:
parent
06b47c8ebf
commit
05d9c11075
@ -22,6 +22,7 @@ let inputSequence = 0;
|
||||
let profile = null;
|
||||
let selfSnapshot = null;
|
||||
let worldSeed = 'SKYWARD-001';
|
||||
let weatherRoutes = [];
|
||||
let multiplayerEnabled = localStorage.getItem(MULTIPLAYER_ENABLED_KEY) !== 'false';
|
||||
|
||||
const statusButton = document.createElement('button');
|
||||
@ -148,6 +149,7 @@ const connect = async () => {
|
||||
inputSequence = 0;
|
||||
setStatus('online');
|
||||
emitConnection('online');
|
||||
sendWeatherLayout();
|
||||
});
|
||||
|
||||
ws.addEventListener('message', (event) => {
|
||||
@ -217,6 +219,29 @@ const sendInput = (input = {}) => {
|
||||
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) => {
|
||||
if (socket?.readyState !== WebSocket.OPEN) return false;
|
||||
const normalized = side === 'port' || side === -1 ? 'port' : 'starboard';
|
||||
@ -270,6 +295,7 @@ window.airshipMultiplayer = {
|
||||
logout,
|
||||
connect,
|
||||
setEnabled,
|
||||
setWeatherRoutes,
|
||||
getState,
|
||||
getSelfId: () => selfId,
|
||||
isAuthenticated: () => authenticated,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user