From 42778e8be409b97059fa519b53c303cdba502e01 Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Tue, 5 Sep 2017 09:30:42 +0200 Subject: Implement rack creation --- src/containers/map/RoomContainer.js | 2 +- src/containers/map/layers/HoverTileLayer.js | 43 ------------------------ src/containers/map/layers/ObjectHoverLayer.js | 35 +++++++++++++++++++ src/containers/map/layers/RoomHoverLayer.js | 48 +++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 44 deletions(-) delete mode 100644 src/containers/map/layers/HoverTileLayer.js create mode 100644 src/containers/map/layers/ObjectHoverLayer.js create mode 100644 src/containers/map/layers/RoomHoverLayer.js (limited to 'src/containers/map') diff --git a/src/containers/map/RoomContainer.js b/src/containers/map/RoomContainer.js index 2d078e09..9edcb096 100644 --- a/src/containers/map/RoomContainer.js +++ b/src/containers/map/RoomContainer.js @@ -5,7 +5,7 @@ import RoomGroup from "../../components/map/groups/RoomGroup"; const mapStateToProps = (state, ownProps) => { return { interactionLevel: state.interactionLevel, - currentRoomInConstruction: state.currentRoomInConstruction, + currentRoomInConstruction: state.construction.currentRoomInConstruction, room: state.objects.room[ownProps.roomId], }; }; diff --git a/src/containers/map/layers/HoverTileLayer.js b/src/containers/map/layers/HoverTileLayer.js deleted file mode 100644 index d8a1d983..00000000 --- a/src/containers/map/layers/HoverTileLayer.js +++ /dev/null @@ -1,43 +0,0 @@ -import {connect} from "react-redux"; -import {toggleTileAtLocation} from "../../../actions/topology"; -import HoverTileLayerComponent from "../../../components/map/layers/HoverTileLayerComponent"; -import { - deriveValidNextTilePositions, - findPositionInPositions, - findPositionInRooms -} from "../../../util/tile-calculations"; - -const mapStateToProps = state => { - return { - currentRoomInConstruction: state.currentRoomInConstruction, - isValid: (x, y) => { - const newRoom = Object.assign({}, state.objects.room[state.currentRoomInConstruction]); - const oldRooms = Object.keys(state.objects.room) - .map(id => Object.assign({}, state.objects.room[id])) - .filter(room => room.id !== state.currentRoomInConstruction); - - [...oldRooms, newRoom].forEach(room => { - room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId]); - }); - if (newRoom.tileIds.length === 0) { - return findPositionInRooms(oldRooms, x, y) === -1; - } - - const validNextPositions = deriveValidNextTilePositions(oldRooms, newRoom.tiles); - return findPositionInPositions(validNextPositions, x, y) !== -1; - }, - }; -}; - -const mapDispatchToProps = dispatch => { - return { - onClick: (x, y) => dispatch(toggleTileAtLocation(x, y)), - }; -}; - -const HoverTileLayer = connect( - mapStateToProps, - mapDispatchToProps -)(HoverTileLayerComponent); - -export default HoverTileLayer; diff --git a/src/containers/map/layers/ObjectHoverLayer.js b/src/containers/map/layers/ObjectHoverLayer.js new file mode 100644 index 00000000..e9df0384 --- /dev/null +++ b/src/containers/map/layers/ObjectHoverLayer.js @@ -0,0 +1,35 @@ +import {connect} from "react-redux"; +import {addRackToTile} from "../../../actions/topology"; +import ObjectHoverLayerComponent from "../../../components/map/layers/ObjectHoverLayerComponent"; +import {findTileWithPosition} from "../../../util/tile-calculations"; + +const mapStateToProps = state => { + return { + isEnabled: () => state.construction.inObjectConstructionMode, + isValid: (x, y) => { + if (state.interactionLevel.mode !== "ROOM") { + return false; + } + + const currentRoom = state.objects.room[state.interactionLevel.roomId]; + const tiles = currentRoom.tileIds.map(tileId => state.objects.tile[tileId]); + const tile = findTileWithPosition(tiles, x, y); + + return !(tile === null || tile.objectType); + + }, + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onClick: (x, y) => dispatch(addRackToTile(x, y)), + }; +}; + +const ObjectHoverLayer = connect( + mapStateToProps, + mapDispatchToProps +)(ObjectHoverLayerComponent); + +export default ObjectHoverLayer; diff --git a/src/containers/map/layers/RoomHoverLayer.js b/src/containers/map/layers/RoomHoverLayer.js new file mode 100644 index 00000000..188ee51a --- /dev/null +++ b/src/containers/map/layers/RoomHoverLayer.js @@ -0,0 +1,48 @@ +import {connect} from "react-redux"; +import {toggleTileAtLocation} from "../../../actions/topology"; +import RoomHoverLayerComponent from "../../../components/map/layers/RoomHoverLayerComponent"; +import { + deriveValidNextTilePositions, + findPositionInPositions, + findPositionInRooms +} from "../../../util/tile-calculations"; + +const mapStateToProps = state => { + return { + isEnabled: () => state.construction.currentRoomInConstruction !== -1, + isValid: (x, y) => { + if (state.interactionLevel.mode !== "BUILDING") { + return false; + } + + const newRoom = Object.assign({}, state.objects.room[state.construction.currentRoomInConstruction]); + const oldRooms = Object.keys(state.objects.room) + .map(id => Object.assign({}, state.objects.room[id])) + .filter(room => room.datacenterId === state.currentDatacenterId + && room.id !== state.construction.currentRoomInConstruction); + + [...oldRooms, newRoom].forEach(room => { + room.tiles = room.tileIds.map(tileId => state.objects.tile[tileId]); + }); + if (newRoom.tileIds.length === 0) { + return findPositionInRooms(oldRooms, x, y) === -1; + } + + const validNextPositions = deriveValidNextTilePositions(oldRooms, newRoom.tiles); + return findPositionInPositions(validNextPositions, x, y) !== -1; + }, + }; +}; + +const mapDispatchToProps = dispatch => { + return { + onClick: (x, y) => dispatch(toggleTileAtLocation(x, y)), + }; +}; + +const RoomHoverLayer = connect( + mapStateToProps, + mapDispatchToProps +)(RoomHoverLayerComponent); + +export default RoomHoverLayer; -- cgit v1.2.3