summaryrefslogtreecommitdiff
path: root/frontend/src/store/middlewares
diff options
context:
space:
mode:
authorjc0b <j@jc0b.computer>2020-07-22 16:28:47 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2020-08-24 19:48:21 +0200
commitd7469b9ebb01cf36a78cc98aab31fa8f307c4f65 (patch)
treed0535fa0cfe95001302fbd2b0d046d51caab6ffd /frontend/src/store/middlewares
parent67b6ec800df8e023efadb60ae5f7919030b19789 (diff)
parent9e7cb3bd367607b32e102c3a87b68b33c53dec46 (diff)
Merge branch 'master' onto working copy
Diffstat (limited to 'frontend/src/store/middlewares')
-rw-r--r--frontend/src/store/middlewares/dummy-middleware.js2
-rw-r--r--frontend/src/store/middlewares/viewport-adjustment.js27
2 files changed, 8 insertions, 21 deletions
diff --git a/frontend/src/store/middlewares/dummy-middleware.js b/frontend/src/store/middlewares/dummy-middleware.js
index ed5670c5..5ba35691 100644
--- a/frontend/src/store/middlewares/dummy-middleware.js
+++ b/frontend/src/store/middlewares/dummy-middleware.js
@@ -1,3 +1,3 @@
-export const dummyMiddleware = store => next => action => {
+export const dummyMiddleware = (store) => (next) => (action) => {
next(action)
}
diff --git a/frontend/src/store/middlewares/viewport-adjustment.js b/frontend/src/store/middlewares/viewport-adjustment.js
index 84f2a3e9..b4472c54 100644
--- a/frontend/src/store/middlewares/viewport-adjustment.js
+++ b/frontend/src/store/middlewares/viewport-adjustment.js
@@ -9,7 +9,7 @@ import {
} from '../../components/app/map/MapConstants'
import { calculateRoomListBounds } from '../../util/tile-calculations'
-export const viewportAdjustmentMiddleware = store => next => action => {
+export const viewportAdjustmentMiddleware = (store) => (next) => (action) => {
const state = store.getState()
let topologyId = '-1'
@@ -17,21 +17,15 @@ export const viewportAdjustmentMiddleware = store => next => action => {
if (action.type === SET_CURRENT_TOPOLOGY && action.topologyId !== '-1') {
topologyId = action.topologyId
mapDimensions = state.map.dimensions
- } else if (
- action.type === SET_MAP_DIMENSIONS &&
- state.currentTopologyId !== '-1'
- ) {
+ } else if (action.type === SET_MAP_DIMENSIONS && state.currentTopologyId !== '-1') {
topologyId = state.currentTopologyId
mapDimensions = { width: action.width, height: action.height }
}
if (topologyId !== '-1') {
const roomIds = state.objects.topology[topologyId].roomIds
- const rooms = roomIds.map(id => Object.assign({}, state.objects.room[id]))
- rooms.forEach(
- room =>
- (room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId])),
- )
+ const rooms = roomIds.map((id) => Object.assign({}, state.objects.room[id]))
+ rooms.forEach((room) => (room.tiles = room.tileIds.map((tileId) => state.objects.tile[tileId])))
let hasNoTiles = true
for (let i in rooms) {
@@ -42,11 +36,7 @@ export const viewportAdjustmentMiddleware = store => next => action => {
}
if (!hasNoTiles) {
- const viewportParams = calculateParametersToZoomInOnRooms(
- rooms,
- mapDimensions.width,
- mapDimensions.height,
- )
+ const viewportParams = calculateParametersToZoomInOnRooms(rooms, mapDimensions.width, mapDimensions.height)
store.dispatch(setMapPosition(viewportParams.newX, viewportParams.newY))
store.dispatch(setMapScale(viewportParams.newScale))
}
@@ -75,11 +65,8 @@ function calculateNewScale(bounds, mapWidth, mapHeight) {
const width = bounds.max.x - bounds.min.x
const height = bounds.max.y - bounds.min.y
- const scaleX =
- (mapWidth - 2 * SIDEBAR_WIDTH) /
- (width * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING)
- const scaleY =
- mapHeight / (height * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING)
+ const scaleX = (mapWidth - 2 * SIDEBAR_WIDTH) / (width * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING)
+ const scaleY = mapHeight / (height * TILE_SIZE_IN_PIXELS + 2 * VIEWPORT_PADDING)
const newScale = Math.min(scaleX, scaleY)
return Math.min(Math.max(MAP_MIN_SCALE, newScale), MAP_MAX_SCALE)