Keep provider document transport schema-blind

This commit is contained in:
Meta Vens 2026-07-10 15:13:39 +01:00
commit 01f296f89d

View file

@ -973,7 +973,7 @@ async function fetchProviderDocument(catalog, request) {
endpoint: route.endpoint,
schemaId: document.schemaId,
recordKey: document.recordKey,
document: normalizeProviderDocumentPayload(document.schemaId, decodeMessagePack(bufferFromPayload(document.payload))),
document: decodeMessagePack(bufferFromPayload(document.payload)),
};
}
@ -1060,228 +1060,6 @@ function closeProviderRudpPeers() {
providerRudpPeers.clear();
}
function normalizeProviderDocumentPayload(schemaId, value) {
const documentSchema = Array.isArray(value) ? value[0] : value?.schema;
if (
schemaMatches(schemaId, "gamecult.fields.splats.v1") ||
schemaMatches(documentSchema, "gamecult.fields.splats.v1")
) {
return normalizeRenderSplatsViewport(value);
}
if (
schemaMatches(schemaId, "gamecult.fields.gravity.v1") ||
schemaMatches(documentSchema, "gamecult.fields.gravity.v1")
) {
return normalizeGravityViewport(value);
}
if (
schemaMatches(schemaId, "gamecult.fields.objects.v1") ||
schemaMatches(documentSchema, "gamecult.fields.objects.v1")
) {
return normalizeObjectsViewport(value);
}
return value;
}
function schemaMatches(schemaId, expected) {
return String(schemaId || "") === expected;
}
function normalizeRenderSplatsViewport(value) {
if (!Array.isArray(value)) return value;
const splats = Array.isArray(value[9]) ? value[9] : [];
return {
schema: value[0],
frameId: value[1],
publishedAtUtc: value[2],
simulationTimeSeconds: value[3],
runId: value[4],
zoneIndex: value[5],
zoneName: value[6],
viewport: normalizeViewport(value[7]),
layers: Array.isArray(value[8]) ? value[8].map(normalizeRenderSplatLayer) : [],
splats: {
count: splats[0] ?? 0,
centerX: splats[1] || [],
centerY: splats[2] || [],
halfExtentX: splats[3] || [],
halfExtentY: splats[4] || [],
rotationCos: splats[5] || [],
rotationSin: splats[6] || [],
channel: splats[7] || [],
falloff: splats[8] || [],
valueR: splats[9] || [],
valueG: splats[10] || [],
valueB: splats[11] || [],
valueA: splats[12] || [],
sourceKey: splats[13] || [],
layerIndex: splats[14] || [],
sourceKind: splats[15] || [],
frequencyX: splats[16] || [],
frequencyY: splats[17] || [],
phaseX: splats[18] || [],
phaseY: splats[19] || [],
animationSpeed: splats[20] || [],
sourceFlags: splats[21] || [],
},
};
}
function normalizeViewport(value) {
return Array.isArray(value)
? { minX: value[0], minY: value[1], maxX: value[2], maxY: value[3] }
: value;
}
function normalizeRenderSplatLayer(value) {
if (!Array.isArray(value)) return value;
return {
layerKey: value[0],
displayName: value[1],
channel: value[2],
blendMode: value[3],
graphicsFormat: value[4],
clearBeforeDraw: value[5],
clearR: value[6],
clearG: value[7],
clearB: value[8],
clearA: value[9],
};
}
function normalizeGravityViewport(value) {
if (!Array.isArray(value)) return value;
return {
schema: value[0],
frameId: value[1],
publishedAtUtc: value[2],
simulationTimeSeconds: value[3],
runId: value[4],
zoneIndex: value[5],
zoneName: value[6],
viewport: normalizeViewport(value[7]),
gravityInfluences: Array.isArray(value[8]) ? value[8].map(normalizeGravityInfluence) : [],
bodies: Array.isArray(value[9]) ? value[9].map(normalizeBodyView) : [],
terrainRadius: value[10],
terrainDepth: value[11],
terrainDepthExponent: value[12],
terrainWaveFrequency: value[13],
};
}
function normalizeObjectsViewport(value) {
if (!Array.isArray(value)) return value;
return {
schema: value[0],
frameId: value[1],
publishedAtUtc: value[2],
simulationTimeSeconds: value[3],
runId: value[4],
zoneIndex: value[5],
zoneName: value[6],
currentEntityKey: value[7],
viewport: normalizeViewport(value[8]),
controlledEntityIndices: Array.isArray(value[9]) ? value[9] : [],
objects: Array.isArray(value[10]) ? value[10].map(normalizeViewportObject) : [],
};
}
function normalizeGravityInfluence(value) {
if (!Array.isArray(value)) return value;
return {
bodyKey: value[0],
orbitKey: value[1],
kind: value[2],
x: value[3],
y: value[4],
radius: value[5],
gravityDepth: value[6],
gravityDepthExponent: value[7],
waveRadius: value[8],
waveDepth: value[9],
waveSpeed: value[10],
};
}
function normalizeBodyView(value) {
if (!Array.isArray(value)) return value;
return {
bodyKey: value[0],
orbitKey: value[1],
name: value[2],
kind: value[3],
x: value[4],
y: value[5],
radius: value[6],
isAsteroidBelt: value[7],
body: value[8],
iconAsset: normalizeAssetRef(value[9]),
};
}
function normalizeViewportObject(value) {
if (!Array.isArray(value)) return value;
return {
entityIndex: value[0],
entityKey: value[1],
displayName: value[2],
kind: value[3],
factionKey: value[4],
x: value[5],
y: value[6],
z: value[7],
directionX: value[8],
directionY: value[9],
velocityX: value[10],
velocityY: value[11],
controlled: value[12],
targetEntityIndex: value[13],
isActive: value[14],
visibility: value[15],
status: normalizeEntityStatus(value[16]),
inventory: Array.isArray(value[17]) ? value[17].map(normalizeInventoryItem) : [],
iconAsset: normalizeAssetRef(value[18]),
};
}
function normalizeEntityStatus(value) {
if (!Array.isArray(value)) return value || {};
return {
hull: value[0],
shield: value[1],
heat: value[2],
};
}
function normalizeInventoryItem(value) {
if (!Array.isArray(value)) return value;
return {
source: value[0],
itemKey: value[1],
quantity: value[2],
quality: value[3],
durability: value[4],
enabled: value[5],
sourceIndex: value[6],
x: value[7],
y: value[8],
iconAsset: normalizeAssetRef(value[9]),
};
}
function normalizeAssetRef(value) {
if (!Array.isArray(value)) return value || {};
return {
assetKey: value[0],
kind: value[1],
uri: value[2],
transport: value[3],
contentHash: value[4],
mimeType: value[5],
metadata: value[6] || {},
};
}
function findProviderSnapshotRoute(catalog, providerId) {
const normalized = String(providerId || "").trim();
const providers = (catalog.providers || []).filter((provider) => {