Send a map clear before replace to ensure new state isn't show on old image

This commit is contained in:
Mitchell McCaffrey 2020-04-24 16:18:48 +10:00
parent db8e0c14fb
commit a4e1a898ad
3 changed files with 26 additions and 19 deletions

View File

@ -251,6 +251,22 @@ function Map({
</Box>
);
const mapDrawing = (
<MapDrawing
width={map ? map.width : 0}
height={map ? map.height : 0}
selectedTool={selectedTool}
shapes={drawnShapes}
onShapeAdd={handleShapeAdd}
onShapeRemove={handleShapeRemove}
brushColor={brushColor}
useGridSnapping={useBrushGridSnapping}
gridSize={gridSizeNormalized}
useBrushBlending={useBrushBlending}
useBrushGesture={useBrushGesture}
/>
);
return (
<>
<Box
@ -282,21 +298,9 @@ function Map({
paddingBottom: `${(1 / aspectRatio) * 100}%`,
}}
/>
{mapImage}
<MapDrawing
width={map ? map.width : 0}
height={map ? map.height : 0}
selectedTool={selectedTool}
shapes={drawnShapes}
onShapeAdd={handleShapeAdd}
onShapeRemove={handleShapeRemove}
brushColor={brushColor}
useGridSnapping={useBrushGridSnapping}
gridSize={gridSizeNormalized}
useBrushBlending={useBrushBlending}
useBrushGesture={useBrushGesture}
/>
{mapTokens}
{map && mapImage}
{map && mapDrawing}
{map && mapTokens}
</Box>
</Box>
<MapControls

View File

@ -141,7 +141,7 @@ function SelectMapModal({
});
// Removed the map from the map screen if needed
if (currentMap && currentMap.id === selectedMap.id) {
onMapChange(null);
onMapChange(null, null);
}
}
@ -165,8 +165,7 @@ function SelectMapModal({
if (selectedMap) {
let currentMapState =
(await db.table("states").get(selectedMap.id)) || defaultMapState;
onMapStateChange(currentMapState);
onMapChange(selectedMap);
onMapChange(selectedMap, currentMapState);
onDone();
}
onDone();

View File

@ -48,9 +48,13 @@ function Game() {
}
}, [debouncedMapState]);
function handleMapChange(newMap) {
function handleMapChange(newMap, newMapState) {
setMapState(newMapState);
setMap(newMap);
for (let peer of Object.values(peers)) {
// Clear the map so the new map state isn't shown on an old map
peer.connection.send({ id: "map", data: null });
peer.connection.send({ id: "mapState", data: newMapState });
peer.connection.send({ id: "map", data: newMap });
}
}