{"size": 1078, "ext": "js", "max_stars_repo_path": "view/src/component/SquadronImage.js", "max_stars_repo_name": "jmthompson2015/star-wars-armada", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "view/src/component/SquadronImage.js", "max_issues_repo_name": "jmthompson2015/star-wars-armada", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "view/src/component/SquadronImage.js", "max_forks_repo_name": "jmthompson2015/star-wars-armada", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.2926829268, "max_line_length": 91, "alphanum_fraction": 0.672541744}
const SquadronImage = {};

const DEG_TO_RADIANS = Math.PI / 180.0;

SquadronImage.draw = (context0, scale, id, image, position, factionColor) => {
  // Setup.
  const width = 35;
  const height = 35;
  const halfWidth = Math.ceil(width / 2);
  const halfHeight = Math.ceil(height / 2);

  const context = context0;
  context.save();
  context.scale(scale, scale);
  context.translate(position.x, position.y);
  context.rotate(position.heading * DEG_TO_RADIANS);

  // Draw background circle.
  context.fillStyle = "rgba(255,255,255,0.4)";
  context.beginPath();
  context.arc(0, 0, halfWidth, 0, 2 * Math.PI);
  context.fill();

  // Draw ship image.
  context.drawImage(image, -image.width / 2, -image.height / 2, image.width, image.height);

  if (id !== undefined) {
    // Draw the ship ID.
    context.rotate(90 * DEG_TO_RADIANS);
    context.fillStyle = factionColor;
    context.font = "14px sans-serif";
    context.fillText(id, -halfHeight, halfWidth);
    context.rotate(-90 * DEG_TO_RADIANS);
  }

  // Cleanup.
  context.restore();
};

export default SquadronImage;
