extend("ahhp:hero_with_models");

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

var wings;
var jetpack;
var booster_main;
var booster_sides;

loadTextures({
    "wings": "ahhp:batman_beyond_wings",
    "jetpack": "ahhp:batman_beyond_jetpack",
    "jetpack_lights": "ahhp:batman_beyond_jetpack_lights",
    "model_lights": "ahhp:batman_beyond_model_lights",
    "model": "ahhp:batman_beyond_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 getIcon() {
    return "fiskheroes:red_fire_layer_%s";
}

function initEffects(renderer) {
    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x000000);
    models = models_stuff.maskToggleModels(renderer, "batman_beyond");
    models_stuff.setOpacityWithMask(renderer);
    wings = renderer.createEffect("fiskheroes:wings").setYOffset(-1);
    wings.texture.set("wings");
    wings.anchor.set("body");

    jetpack = renderer.createEffect("fiskheroes:model");
    jetpack.setModel(utils.createModel(renderer, "fiskheroes:falcon_cap_jetpack", "jetpack", "jetpack_lights"));
    jetpack.anchor.set("body");

    var red_fire = renderer.createResource("ICON", getIcon());
    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:flight_timer") > 0);

    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.7, "offset": [-4.5, 10.5, 0.4], "rotation": [110.0, 5.0, 0.0] }
    ]);
}
function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "batman.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "batman.HOVER", "fiskheroes:flight/idle/neutral");
    addAnimationWithData(renderer, "batman.BLOCKING", "fiskheroes:blocking", "fiskheroes:shield_blocking_timer")
        .priority = -5;
}
function render(entity, renderLayer, isFirstPersonArm) {
    models.render(entity, renderLayer);
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        wings.unfold = entity.getInterpolatedData("fiskheroes:flight_boost_timer");
        wings.shieldUnfold = entity.getInterpolatedData("fiskheroes:shield_blocking_timer");
        wings.render();
        jetpack.render();

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