Skip to content

Commit

Permalink
优化 tile re-render
Browse files Browse the repository at this point in the history
  • Loading branch information
schneiderlin committed Feb 7, 2024
1 parent d33dce6 commit 4a358d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
24 changes: 12 additions & 12 deletions client/components/game/GameMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function GameMap() {
};

const { setSelectedMapTileInfo, halfArmy, clearQueue, popQueue, selectGeneral,

handlePositionChange, testIfNextPossibleMove,
handleClick,
attackUp, attackDown, attackLeft, attackRight } = useGameDispatch();
Expand Down Expand Up @@ -373,17 +373,17 @@ function GameMap() {
{displayMapData.map((tiles, x) => {
return tiles.map((tile, y) => {
return (
<MapTile
isNextPossibleMove={testIfNextPossibleMove(tile.tile[0], x, y)}
handleClick={() => handleClick(tile.tile, x, y, myPlayerIndex)}
// handleClick={() => { }}
key={`${x}/${y}`}
zoom={zoom}
size={tileSize}
x={x}
y={y}
{...tile}
warringStatesMode={room.warringStatesMode} />
<div key={`${x}/${y}`}
onClick={() => handleClick(tile.tile, x, y, myPlayerIndex)}>
<MapTile
isNextPossibleMove={testIfNextPossibleMove(tile.tile[0], x, y)}
zoom={zoom}
size={tileSize}
x={x}
y={y}
{...tile}
warringStatesMode={room.warringStatesMode} />
</div>
);
});
})}
Expand Down
5 changes: 1 addition & 4 deletions client/components/game/MapTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ interface MapTileProps {
isSelected: boolean;
isNextPossibleMove: boolean;
warringStatesMode: boolean;
handleClick: () => void;
}

export default React.memo(function MapTile(props: MapTileProps) {
Expand All @@ -46,9 +45,8 @@ export default React.memo(function MapTile(props: MapTileProps) {
isSelected,
isNextPossibleMove,
warringStatesMode = false,
handleClick
} = props;
// console.log(`${x} ${y} render`, new Date().toISOString());
console.log(`${x} ${y} render`, new Date().toISOString());
const [cursorStyle, setCursorStyle] = useState('default');

const [tileType, color, unitsCount] = tile;
Expand Down Expand Up @@ -151,7 +149,6 @@ export default React.memo(function MapTile(props: MapTileProps) {
}}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
onClick={handleClick}
>
<div
style={{
Expand Down

0 comments on commit 4a358d0

Please sign in to comment.