Because svelte can react to assignments within an object as well as to an object itself, perhaps it's best to replace this monstrosity with an object:
// Letting the state variables go uninitialized is safe,
// because they are initialized by resetGame before they are ever read
let apple;
let gameState;
let headDirection;
let headDirectionQueue;
let score;
let snake;
let willGrow;
function resetGame() {
const initialSnake = [
{ x: 4, y: 4 },
{ x: 4, y: 3 },
{ x: 4, y: 2 },
];
apple = drawRandomOpenSpace(BOARD_DIMENSIONS, initialSnake);
gameState = GAME_STATES.START_SCREEN;
headDirection = DIRECTION.SOUTH;
headDirectionQueue = [];
score = 0;
snake = initialSnake;
willGrow = false;
}
Because svelte can react to assignments within an object as well as to an object itself, perhaps it's best to replace this monstrosity with an object: