From bf7708f658cc6299a3b775afe24459b5a808c54d Mon Sep 17 00:00:00 2001 From: Georgios Andreadis Date: Fri, 22 Sep 2017 21:20:54 +0200 Subject: Restructure component and container directories --- src/components/app/map/elements/Backdrop.js | 16 ++++++ src/components/app/map/elements/GrayLayer.js | 17 ++++++ src/components/app/map/elements/HoverTile.js | 27 +++++++++ src/components/app/map/elements/ImageComponent.js | 48 ++++++++++++++++ src/components/app/map/elements/RackFillBar.js | 67 +++++++++++++++++++++++ src/components/app/map/elements/RoomTile.js | 20 +++++++ src/components/app/map/elements/TileObject.js | 25 +++++++++ src/components/app/map/elements/TilePlusIcon.js | 44 +++++++++++++++ src/components/app/map/elements/WallSegment.js | 39 +++++++++++++ 9 files changed, 303 insertions(+) create mode 100644 src/components/app/map/elements/Backdrop.js create mode 100644 src/components/app/map/elements/GrayLayer.js create mode 100644 src/components/app/map/elements/HoverTile.js create mode 100644 src/components/app/map/elements/ImageComponent.js create mode 100644 src/components/app/map/elements/RackFillBar.js create mode 100644 src/components/app/map/elements/RoomTile.js create mode 100644 src/components/app/map/elements/TileObject.js create mode 100644 src/components/app/map/elements/TilePlusIcon.js create mode 100644 src/components/app/map/elements/WallSegment.js (limited to 'src/components/app/map/elements') diff --git a/src/components/app/map/elements/Backdrop.js b/src/components/app/map/elements/Backdrop.js new file mode 100644 index 00000000..9c01df63 --- /dev/null +++ b/src/components/app/map/elements/Backdrop.js @@ -0,0 +1,16 @@ +import React from "react"; +import {Rect} from "react-konva"; +import {BACKDROP_COLOR} from "../../../../util/colors"; +import {MAP_SIZE_IN_PIXELS} from "../MapConstants"; + +const Backdrop = () => ( + +); + +export default Backdrop; diff --git a/src/components/app/map/elements/GrayLayer.js b/src/components/app/map/elements/GrayLayer.js new file mode 100644 index 00000000..c5994d06 --- /dev/null +++ b/src/components/app/map/elements/GrayLayer.js @@ -0,0 +1,17 @@ +import React from "react"; +import {Rect} from "react-konva"; +import {GRAYED_OUT_AREA_COLOR} from "../../../../util/colors"; +import {MAP_SIZE_IN_PIXELS} from "../MapConstants"; + +const GrayLayer = ({onClick}) => ( + +); + +export default GrayLayer; diff --git a/src/components/app/map/elements/HoverTile.js b/src/components/app/map/elements/HoverTile.js new file mode 100644 index 00000000..fc12cbdd --- /dev/null +++ b/src/components/app/map/elements/HoverTile.js @@ -0,0 +1,27 @@ +import PropTypes from "prop-types"; +import React from "react"; +import {Rect} from "react-konva"; +import {ROOM_HOVER_INVALID_COLOR, ROOM_HOVER_VALID_COLOR} from "../../../../util/colors"; +import {TILE_SIZE_IN_PIXELS} from "../MapConstants"; + +const HoverTile = ({pixelX, pixelY, isValid, scale, onClick}) => ( + +); + +HoverTile.propTypes = { + pixelX: PropTypes.number.isRequired, + pixelY: PropTypes.number.isRequired, + isValid: PropTypes.bool.isRequired, + onClick: PropTypes.func.isRequired, +}; + +export default HoverTile; diff --git a/src/components/app/map/elements/ImageComponent.js b/src/components/app/map/elements/ImageComponent.js new file mode 100644 index 00000000..486296ea --- /dev/null +++ b/src/components/app/map/elements/ImageComponent.js @@ -0,0 +1,48 @@ +import PropTypes from "prop-types"; +import React from "react"; +import {Image} from "react-konva"; + +class ImageComponent extends React.Component { + static imageCaches = {}; + static propTypes = { + src: PropTypes.string.isRequired, + x: PropTypes.number.isRequired, + y: PropTypes.number.isRequired, + width: PropTypes.number.isRequired, + height: PropTypes.number.isRequired, + opacity: PropTypes.number.isRequired, + }; + + state = { + image: null + }; + + componentDidMount() { + if (ImageComponent.imageCaches[this.props.src]) { + this.setState({image: ImageComponent.imageCaches[this.props.src]}); + return; + } + + const image = new window.Image(); + image.src = this.props.src; + image.onload = () => { + this.setState({image}); + ImageComponent.imageCaches[this.props.src] = image; + } + } + + render() { + return ( + + ) + } +} + +export default ImageComponent; diff --git a/src/components/app/map/elements/RackFillBar.js b/src/components/app/map/elements/RackFillBar.js new file mode 100644 index 00000000..3a8a1137 --- /dev/null +++ b/src/components/app/map/elements/RackFillBar.js @@ -0,0 +1,67 @@ +import PropTypes from "prop-types"; +import React from "react"; +import {Group, Rect} from "react-konva"; +import { + RACK_ENERGY_BAR_BACKGROUND_COLOR, + RACK_ENERGY_BAR_FILL_COLOR, + RACK_SPACE_BAR_BACKGROUND_COLOR, + RACK_SPACE_BAR_FILL_COLOR +} from "../../../../util/colors"; +import { + OBJECT_BORDER_WIDTH_IN_PIXELS, + OBJECT_MARGIN_IN_PIXELS, + RACK_FILL_ICON_OPACITY, + RACK_FILL_ICON_WIDTH, + TILE_SIZE_IN_PIXELS +} from "../MapConstants"; +import ImageComponent from "./ImageComponent"; + +const RackFillBar = ({positionX, positionY, type, fillFraction}) => { + const halfOfObjectBorderWidth = OBJECT_BORDER_WIDTH_IN_PIXELS / 2; + const x = positionX * TILE_SIZE_IN_PIXELS + OBJECT_MARGIN_IN_PIXELS + + (type === "space" ? halfOfObjectBorderWidth : + 0.5 * (TILE_SIZE_IN_PIXELS - 2 * OBJECT_MARGIN_IN_PIXELS)); + const startY = positionY * TILE_SIZE_IN_PIXELS + OBJECT_MARGIN_IN_PIXELS + halfOfObjectBorderWidth; + const width = 0.5 * (TILE_SIZE_IN_PIXELS - OBJECT_MARGIN_IN_PIXELS * 2) - halfOfObjectBorderWidth; + const fullHeight = TILE_SIZE_IN_PIXELS - OBJECT_MARGIN_IN_PIXELS * 2 - OBJECT_BORDER_WIDTH_IN_PIXELS; + + const fractionHeight = fillFraction * fullHeight; + const fractionY = (positionY + 1) * TILE_SIZE_IN_PIXELS - OBJECT_MARGIN_IN_PIXELS - halfOfObjectBorderWidth + - fractionHeight; + + return ( + + + + + + ); +}; + +RackFillBar.propTypes = { + positionX: PropTypes.number.isRequired, + positionY: PropTypes.number.isRequired, + type: PropTypes.string.isRequired, + fillFraction: PropTypes.number.isRequired, +}; + +export default RackFillBar; diff --git a/src/components/app/map/elements/RoomTile.js b/src/components/app/map/elements/RoomTile.js new file mode 100644 index 00000000..11948a7a --- /dev/null +++ b/src/components/app/map/elements/RoomTile.js @@ -0,0 +1,20 @@ +import React from "react"; +import {Rect} from "react-konva"; +import Shapes from "../../../../shapes/index"; +import {TILE_SIZE_IN_PIXELS} from "../MapConstants"; + +const RoomTile = ({tile, color}) => ( + +); + +RoomTile.propTypes = { + tile: Shapes.Tile, +}; + +export default RoomTile; diff --git a/src/components/app/map/elements/TileObject.js b/src/components/app/map/elements/TileObject.js new file mode 100644 index 00000000..73bfddba --- /dev/null +++ b/src/components/app/map/elements/TileObject.js @@ -0,0 +1,25 @@ +import PropTypes from "prop-types"; +import React from "react"; +import {Rect} from "react-konva"; +import {OBJECT_BORDER_COLOR} from "../../../../util/colors"; +import {OBJECT_BORDER_WIDTH_IN_PIXELS, OBJECT_MARGIN_IN_PIXELS, TILE_SIZE_IN_PIXELS} from "../MapConstants"; + +const TileObject = ({positionX, positionY, color}) => ( + +); + +TileObject.propTypes = { + positionX: PropTypes.number.isRequired, + positionY: PropTypes.number.isRequired, + color: PropTypes.string.isRequired, +}; + +export default TileObject; diff --git a/src/components/app/map/elements/TilePlusIcon.js b/src/components/app/map/elements/TilePlusIcon.js new file mode 100644 index 00000000..b96bf0f5 --- /dev/null +++ b/src/components/app/map/elements/TilePlusIcon.js @@ -0,0 +1,44 @@ +import PropTypes from "prop-types"; +import React from "react"; +import {Group, Line} from "react-konva"; +import {TILE_PLUS_COLOR} from "../../../../util/colors"; +import {TILE_PLUS_MARGIN_IN_PIXELS, TILE_PLUS_WIDTH_IN_PIXELS, TILE_SIZE_IN_PIXELS} from "../MapConstants"; + +const TilePlusIcon = ({pixelX, pixelY, mapScale}) => { + const linePoints = [ + [ + pixelX + 0.5 * TILE_SIZE_IN_PIXELS * mapScale, + pixelY + TILE_PLUS_MARGIN_IN_PIXELS * mapScale, + pixelX + 0.5 * TILE_SIZE_IN_PIXELS * mapScale, + pixelY + TILE_SIZE_IN_PIXELS * mapScale - TILE_PLUS_MARGIN_IN_PIXELS * mapScale, + ], + [ + pixelX + TILE_PLUS_MARGIN_IN_PIXELS * mapScale, + pixelY + 0.5 * TILE_SIZE_IN_PIXELS * mapScale, + pixelX + TILE_SIZE_IN_PIXELS * mapScale - TILE_PLUS_MARGIN_IN_PIXELS * mapScale, + pixelY + 0.5 * TILE_SIZE_IN_PIXELS * mapScale, + ], + ]; + return ( + + {linePoints.map((points, index) => ( + + ))} + + ) +}; + +TilePlusIcon.propTypes = { + pixelX: PropTypes.number, + pixelY: PropTypes.number, + mapScale: PropTypes.number, +}; + +export default TilePlusIcon; diff --git a/src/components/app/map/elements/WallSegment.js b/src/components/app/map/elements/WallSegment.js new file mode 100644 index 00000000..14efd3fc --- /dev/null +++ b/src/components/app/map/elements/WallSegment.js @@ -0,0 +1,39 @@ +import React from "react"; +import {Line} from "react-konva"; +import Shapes from "../../../../shapes/index"; +import {WALL_COLOR} from "../../../../util/colors"; +import {TILE_SIZE_IN_PIXELS, WALL_WIDTH_IN_PIXELS} from "../MapConstants"; + +const WallSegment = ({wallSegment}) => { + let points; + if (wallSegment.isHorizontal) { + points = [ + wallSegment.startPosX * TILE_SIZE_IN_PIXELS, + wallSegment.startPosY * TILE_SIZE_IN_PIXELS, + (wallSegment.startPosX + wallSegment.length) * TILE_SIZE_IN_PIXELS, + wallSegment.startPosY * TILE_SIZE_IN_PIXELS + ]; + } else { + points = [ + wallSegment.startPosX * TILE_SIZE_IN_PIXELS, + wallSegment.startPosY * TILE_SIZE_IN_PIXELS, + wallSegment.startPosX * TILE_SIZE_IN_PIXELS, + (wallSegment.startPosY + wallSegment.length) * TILE_SIZE_IN_PIXELS, + ]; + } + + return ( + + ) +}; + +WallSegment.propTypes = { + wallSegment: Shapes.WallSegment, +}; + +export default WallSegment; -- cgit v1.2.3