Skip to content

Instantly share code, notes, and snippets.

@diericx
Created September 10, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diericx/1d5708bce4db56121607c02407d310a3 to your computer and use it in GitHub Desktop.
Save diericx/1d5708bce4db56121607c02407d310a3 to your computer and use it in GitHub Desktop.
import React, { Component } from "react";
import { Rect } from "react-konva";
import { CLASS_IDS } from "../../lib/environmentApi";
class EntityRect extends React.Component {
handleClick = () => {
this.setState({
clicked: true
});
};
render() {
const {
entity,
screenPos,
worldPos,
width,
height,
selected,
onClick
} = this.props;
let fill = "white";
if (!entity || entity.classID === CLASS_IDS.EMPTY) { // Empty
fill = "#32ff7e";
} else if (entity.classID === CLASS_IDS.AGENT) { // Agent
fill = "#18dcff";
} else if (entity.classID === CLASS_IDS.ROCK) { // Rock
fill = "#000000";
} else if (entity.classID === CLASS_IDS.FOOD) { // Food
fill = "#33c466";
}
return (
<Rect
x={screenPos.x}
y={screenPos.y}
width={width}
height={height}
fill={fill}
shadowBlur={selected ? 5 : 0}
onClick={() => onClick(worldPos, entity)}
/>
);
}
}
export default EntityRect;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment