Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import React, { Component } from "react";
  2. import { Rect } from "react-konva";
  3. import { CLASS_IDS } from "../../lib/environmentApi";
  4. class EntityRect extends React.Component {
  5. handleClick = () => {
  6. this.setState({
  7. clicked: true
  8. });
  9. };
  10.  
  11. render() {
  12. const {
  13. entity,
  14. screenPos,
  15. worldPos,
  16. width,
  17. height,
  18. selected,
  19. onClick
  20. } = this.props;
  21. let fill = "white";
  22. if (!entity || entity.classID === CLASS_IDS.EMPTY) { // Empty
  23. fill = "#32ff7e";
  24. } else if (entity.classID === CLASS_IDS.AGENT) { // Agent
  25. fill = "#18dcff";
  26. } else if (entity.classID === CLASS_IDS.ROCK) { // Rock
  27. fill = "#000000";
  28. } else if (entity.classID === CLASS_IDS.FOOD) { // Food
  29. fill = "#33c466";
  30. }
  31. return (
  32. <Rect
  33. x={screenPos.x}
  34. y={screenPos.y}
  35. width={width}
  36. height={height}
  37. fill={fill}
  38. shadowBlur={selected ? 5 : 0}
  39. onClick={() => onClick(worldPos, entity)}
  40. />
  41. );
  42. }
  43. }
  44.  
  45. export default EntityRect;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement