loadTextures({
    "base": "skarlet:pop_gun",
    "christmas": "skarlet:pop_gun_christmas",
    "crosshair": "skarlet:crosshairs/pop_gun"
});

var utils = implement("fisktag:external/utils");

var model;

function init(renderer) {
    model = utils.createModel(renderer, "skarlet:pop_gun", "base");
    model.bindAnimation("skarlet:revolver_reload").setData((entity, data) => {
        if (cancelAnimations) {
            data.load(0);
            return;
        }
        data.load(entity.getInterpolatedData("fiskheroes:reload_timer"));
    });
    renderer.setModel(model);

    utils.addPlayerAnimationWithData(renderer, "skarlet:revolver_reload", "fiskheroes:reload_timer").priority = 10;

    utils.makeDilatingCrosshair(renderer, "crosshair", 15, 11, [
        { "pos": [7, 5], "size": [1, 1] }, // Center
        { "pos": [2, 1], "size": [5, 9], "axis": [-1, 0] }, // Left
        { "pos": [8, 1], "size": [5, 9], "axis": [1, 0] } // Right
    ], 0, 2, 2);

    utils.bindScopedBeam(renderer, "skarlet:bullet", 0xB97317, [
        { "firstPerson": [-5.0, 4.5, -18.0], "offset": [0.0, 15.0, -4.0], "size": [4.0, 4.0] }
    ], [3.0, -2.0, -2.0]);
}

function render(renderer, entity, glProxy, renderType, scopeTimer, recoil, isLeftSide) {
    if (entity.isWearingFullSuit() && entity.getWornChestplate().suitType() == "skarlet:harley_quinn/christmas") {
        model.texture.set("christmas");
    } else {
        model.texture.set("base");
    }
    glProxy.translate(0, -0.85, -0.52);

    if (renderType === "EQUIPPED_FIRST_PERSON") {
	    cancelAnimations = false;
        var f = 1 - scopeTimer * 0.4;
        recoil *= 0.7;
        glProxy.translate(-Math.sin(entity.getInterpolatedData("fiskheroes:scope_timer") * Math.PI / 2) * 0.25, 0.1, 0.3 * recoil);
        glProxy.rotate(-recoil * (20 - scopeTimer * 7), 1, 0, 0);
        glProxy.translate(0.02 * recoil * (1 - scopeTimer), -0.04 * recoil * f, (Math.sin(recoil * Math.PI) * 0.1) * f);
    } else {
	    cancelAnimations = true;
    }

    glProxy.scale(1.5);
}
