// The two one-cell marks that are not things in the world: the order the ship is
// flying to, and the pointer the dev build draws in place of the browser's cursor.
import * as THREE from 'three';
import { lum } from './ink';
import { plate } from './shapes';

// A click target: a plus of 5 cells, bright enough to read past the dust. It is
// built in cells and scaled by the view, so a plate is one glyph at every zoom
// instead of one glyph at the one zoom its world size happens to match.
export function crosshair(): THREE.Group {
  const g = new THREE.Group();
  for (const [dx, dy] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) {
    const p = plate(1, 1, dx || dy ? 0.75 : 1);
    p.position.set(dx, dy, 0);
    g.add(p);
  }
  g.position.z = 0.5;
  g.renderOrder = 2; // over every body and piece: it is an order, not a thing
  return g;
}

// The pointer: a ring of whole cells around the pointer cell, one cell per plate.
// The browser's own pointer is hidden, so the game draws one that lands on the cell
// a click will resolve to. It is a ring and not a plus, so it can never be read as
// the order marker the ship is flying to.
export function reticle(): THREE.Group {
  const g = new THREE.Group();
  for (const dx of [-1, 0, 1]) {
    for (const dy of [-1, 0, 1]) {
      if (!dx && !dy) continue;
      const p = plate(1, 1, 1); // a full cell: a smaller plate is averaged away
      p.material.color.copy(TONE.space);
      p.position.set(dx, dy, 0);
      g.add(p);
    }
  }
  g.position.z = 1; // over the fuel gauge
  g.renderOrder = 1; // and after it too: a cell of gauge must never hide the pointer
  return g;
}

// What the ring says about the cell it is on: nothing is just space, a body is a
// place to orbit, and a hull that is not yours is a fight. Never the cream of your
// own hull, or the pointer would vanish on the one thing it sits on most.
export const TONE = { space: lum(1, 4), body: lum(1, 6), hull: lum(1, 14) };
