"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderChargeBar = exports.newChargeBarSprites = void 0;
const CHARGE_BAR_ANM2 = "gfx/ui/ui_chargebar.anm2";
/**
 * Constructor for a `ChargeBarSprites` object. For more information, see the `renderChargeBar`
 * helper function.
 *
 * Note that this is for the vertical charge bar that represents the number of charges that an
 * active item has, not the circular charge bar that shows e.g. the charge rate of Brimstone.
 */
function newChargeBarSprites(maxCharges) {
    const back = Sprite();
    back.Load(CHARGE_BAR_ANM2, true);
    back.Play("BarEmpty", true);
    const meter = Sprite();
    meter.Load(CHARGE_BAR_ANM2, true);
    meter.Play("BarFull", true);
    const meterBattery = Sprite();
    meterBattery.Load(CHARGE_BAR_ANM2, true);
    meterBattery.Play("BarFull", true);
    const lines = Sprite();
    lines.Load(CHARGE_BAR_ANM2, true);
    lines.Play(`BarOverlay${maxCharges}`, true);
    return {
        back,
        meter,
        meterBattery,
        lines,
        maxCharges,
    };
}
exports.newChargeBarSprites = newChargeBarSprites;
/**
 * Helper function to render a charge bar on the screen. First, call the `newChargeBarSprites`
 * function to initialize the sprites, and then call this function on every render frame.
 *
 * Note that this is for the vertical charge bar that represents the number of charges that an
 * active item has, not the circular charge bar that shows e.g. the charge rate of Brimstone.
 */
function renderChargeBar(sprites, position, normalCharges, batteryCharges) {
    sprites.back.Render(position);
    const normalChargesClamp = getChargeBarClamp(normalCharges, sprites.maxCharges);
    sprites.meter.Render(position, normalChargesClamp);
    const batteryChargesClamp = getChargeBarClamp(batteryCharges, sprites.maxCharges);
    sprites.meterBattery.Render(position, batteryChargesClamp);
    sprites.lines.Render(position);
}
exports.renderChargeBar = renderChargeBar;
function getChargeBarClamp(charges, maxCharges) {
    const meterMultiplier = 24 / maxCharges;
    const meterClip = 26 - charges * meterMultiplier;
    return Vector(0, meterClip);
}
