extend("ahhp:hero_with_models");

var utils = implement("fiskheroes:external/utils");
var models_stuff = implement("ahhp:external/model_stuff");

var wings;
var booster_main;
var booster_sides;

loadTextures({
    "wings": "ahhp:cap_falcon_wings",
    "model": "ahhp:cap_falcon_model"
});

function init(renderer) {
    renderer.showModel("HELMET", "head", "headwear");
    renderer.showModel("LEGGINGS", "rightLeg", "leftLeg");
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm");
    renderer.fixHatLayer("HELMET");
    parent.init(renderer);    
    initEffects(renderer);
}

function initEffects(renderer) {
    models = models_stuff.maskToggleModels(renderer, "cap_falcon");
    wings = renderer.createEffect("fiskheroes:wings").setYOffset(-1);
    wings.texture.set("wings");
    wings.anchor.set("body");

    var red_fire = renderer.createResource("ICON", "fiskheroes:blue_fire_layer_%s");
    booster_main = renderer.createEffect("fiskheroes:booster");
    booster_main.setIcon(red_fire).setOffset(0.0, 5.0, 2.6).setSize(1.75, 3.0);
    booster_main.anchor.set("body");
    booster_sides = renderer.createEffect("fiskheroes:booster");
    booster_sides.setIcon(red_fire).setOffset(0.75, 5.0, 2.6).setSize(1.5, 2.0);
    booster_sides.anchor.set("body");
    booster_sides.mirror = true;

    utils.bindParticles(renderer, "fiskheroes:cap_falcon").setCondition(entity => entity.getData("fiskheroes:jetpacking_timer") > 0);
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 1.0, "offset": [0.0, 4.5, 3.75], "rotation": [95.0, -180.0, 0.0] }
    ]).addOffset("QUIVER", -0.3, 1.0, 1.4);
}

function render(entity, renderLayer, isFirstPersonArm) {
    models.render(entity, renderLayer);
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        wings.unfold = entity.getInterpolatedData("fiskheroes:flight_timer");
        wings.shieldUnfold = entity.getInterpolatedData("fiskheroes:shield_blocking_timer");
        wings.render();

        booster_main.progress = booster_sides.progress = entity.getInterpolatedData("fiskheroes:flight_timer");
        booster_main.render();
        booster_sides.render();
    }
}
