From 9d05ebbaeb47173867b43f608083d830e9eecd37 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 8 Mar 2026 10:16:51 -0400 Subject: [PATCH] Arrange tiles neatly when reloading the game The random positioning (which we use for one-at-a-time dealing of tiles) was failing here, because each tile's random position was being chosen against an empty playfield, (the tiles are being added in bulk and the state isn't being updated between tiles). So the letters ended up piling on top of each other. We have a nice way to arrange non-overlapping tiles with the shuff_tiles() function, so just call that once when doing a bulk receive of tiles. --- anagrams/anagrams.jsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/anagrams/anagrams.jsx b/anagrams/anagrams.jsx index ede6c2e..631b913 100644 --- a/anagrams/anagrams.jsx +++ b/anagrams/anagrams.jsx @@ -170,12 +170,17 @@ class Game extends React.Component { receive_center(tiles) { const positions = { ...this.state.tile_positions }; + let new_count = 0; for (const tile of tiles) { if (!positions[tile.id]) { - positions[tile.id] = this._random_position(); + positions[tile.id] = { x: 50, y: 50 }; /* placeholder */ + new_count++; } } - this.setState({ center: tiles, tile_positions: positions }); + this.setState({ center: tiles, tile_positions: positions }, () => { + /* On bulk load (reconnection), arrange tiles in a grid. */ + if (new_count > 1) this.shuffle_tiles(); + }); } receive_letter_reveal(data) { -- 2.45.2