Fix grid editor mutably changing grid state

This commit is contained in:
Mitchell McCaffrey 2021-06-12 13:14:46 +10:00
parent 833f0082ba
commit 3d74dfc88a
2 changed files with 8 additions and 2 deletions

View File

@ -77,7 +77,10 @@ function MapGridEditor({ map, onGridChange }) {
Vector2.subtract(position, previousPosition)
);
const inset = map.grid.inset;
const inset = {
topLeft: { ...map.grid.inset.topLeft },
bottomRight: { ...map.grid.inset.bottomRight },
};
if (direction.x === 0 && direction.y === 0) {
return inset;

View File

@ -212,7 +212,10 @@ export function getGridDefaultInset(grid, mapWidth, mapHeight) {
* @returns {GridInset}
*/
export function getGridUpdatedInset(grid, mapWidth, mapHeight) {
let inset = grid.inset;
let inset = {
topLeft: { ...grid.inset.topLeft },
bottomRight: { ...grid.inset.bottomRight },
};
// Take current inset width and use it to calculate the new height
if (grid.size.x > 0 && grid.size.x > 0) {
// Convert to px relative to map size