{"size": 3031, "ext": "js", "max_stars_repo_path": "ui/jobs/components/ast.js", "max_stars_repo_name": "lyze/cactbot", "max_stars_repo_stars_event_min_datetime": "2019-07-20T19:26:34.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-18T04:01:38.000Z", "max_issues_repo_path": "ui/jobs/components/ast.js", "max_issues_repo_name": "lyze/cactbot", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "ui/jobs/components/ast.js", "max_forks_repo_name": "lyze/cactbot", "max_forks_repo_forks_event_min_datetime": "2019-06-18T09:51:26.000Z", "max_forks_repo_forks_event_max_datetime": "2019-07-14T10:08:09.000Z"}
{"max_stars_count": 4, "max_issues_count": null, "max_forks_count": 4, "avg_line_length": 28.5943396226, "max_line_length": 68, "alphanum_fraction": 0.6080501485}
import { kAbility } from '../constants';

let resetFunc = null;
const cardsMap = {
  'Balance': { 'bonus': 'melee', 'seal': 'Solar' },
  'Bole': { 'bonus': 'range', 'seal': 'Solar' },
  'Arrow': { 'bonus': 'melee', 'seal': 'Lunar' },
  'Ewer': { 'bonus': 'range', 'seal': 'Lunar' },
  'Spear': { 'bonus': 'melee', 'seal': 'Celestial' },
  'Spire': { 'bonus': 'range', 'seal': 'Celestial' },
};

export function setup(bars) {
  const combustBox = bars.addProcBox({
    id: 'ast-procs-combust',
    fgColor: 'ast-color-combust',
  });

  const drawBox = bars.addProcBox({
    id: 'ast-procs-draw',
    fgColor: 'ast-color-draw',
  });

  const lucidBox = bars.addProcBox({
    id: 'ast-procs-luciddreaming',
    fgColor: 'ast-color-lucid',
  });

  const cardBox = bars.addResourceBox({
    classList: ['ast-color-card'],
  });

  const sealBox = bars.addResourceBox({
    classList: ['ast-color-seal'],
  });

  bars.onJobDetailUpdate((jobDetail) => {
    const card = jobDetail.heldCard;
    const seals = jobDetail.arcanums;

    // Show on which kind of jobs your card plays better by color
    // Blue on melee, purple on ranged, and grey when no card
    const cardParent = cardBox.parentNode;
    cardParent.classList.remove('melee', 'range');
    if (card in cardsMap)
      cardParent.classList.add(cardsMap[card].bonus);

    // Show whether you already have bars seal
    // O means it's OK to play bars card
    // X means don't play bars card directly if time permits
    if (!cardsMap[card])
      cardBox.innerText = '';
    else if (seals.includes(cardsMap[card].seal))
      cardBox.innerText = 'X';
    else
      cardBox.innerText = 'O';

    // Show how many kind of seals you already have
    // Turn green when you have all 3 kinds of seal
    const sealCount = new Set(seals).size;
    sealBox.innerText = sealCount;
    if (sealCount === 3)
      sealBox.parentNode.classList.add('ready');
    else
      sealBox.parentNode.classList.remove('ready');
  });

  bars.onUseAbility([kAbility.Combust2, kAbility.Combust3], () => {
    combustBox.duration = 0;
    combustBox.duration = 30;
  });
  bars.onUseAbility(kAbility.Combust, () => {
    combustBox.duration = 0;
    combustBox.duration = 18;
  });

  bars.onUseAbility(kAbility.Draw, () => {
    drawBox.duration = 0;
    drawBox.duration = 30;
  });
  bars.onUseAbility(kAbility.LucidDreaming, () => {
    lucidBox.duration = 0;
    lucidBox.duration = 60;
  });

  bars.onStatChange('AST', () => {
    combustBox.valuescale = bars.gcdSpell;
    combustBox.threshold = bars.gcdSpell + 1;
    drawBox.valuescale = bars.gcdSpell;
    drawBox.threshold = bars.gcdSpell + 1;
    lucidBox.valuescale = bars.gcdSpell;
    lucidBox.threshold = bars.gcdSpell + 1;
  });

  resetFunc = (bars) => {
    combustBox.duration = 0;
    drawBox.duration = 0;
    lucidBox.duration = 0;
  };
}

export function reset(bars) {
  if (resetFunc)
    resetFunc(bars);
}
