import { CHUNK_SIZE } from "../protocol/constants.js"; export function speechReadability (distanceTiles, chunkSize = CHUNK_SIZE) { const dropStart = chunkSize * 0.5; const silent = chunkSize; if (distanceTiles <= dropStart) { return 1; } if (distanceTiles >= silent) { return 0; } return (silent - distanceTiles) / (silent - dropStart); } export function obscureSpeech (text, readability, seed = 1) { if (readability >= 1) { return text; } if (readability <= 0) { return ""; } let rng = seed >>> 0 || 1; let result = ""; for (const char of text) { rng = stepRng(rng); if (isStableSpeechChar(char) || rng / 0x100000000 <= readability) { result += char; } else { result += "."; } } return result; } function isStableSpeechChar (char) { return !/[\p{L}\p{N}]/u.test(char); } function stepRng (value) { return (Math.imul(value, 1664525) + 1013904223) >>> 0; }