extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "wv:vision/vision_layer1",
    "layer2": "wv:vision/vision_layer2",
    "cape": "wv:vision/vision_cape",
    "stone": "wv:vision/vision_stone"
});

var utils = implement("fiskheroes:external/utils");
var capes = implement("fiskheroes:external/capes");

var cape;
var overlay;

function init(renderer) {
    parent.init(renderer);
}

function initEffects(renderer) {
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.weight = 0.9;
    physics.maxFlare = 0.5;
    cape = capes.createDefault(renderer, 24, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.opacity = 0.85;

    overlay = renderer.createEffect("fiskheroes:overlay");
    overlay.texture.set(null, "stone");

    utils.setOpacityWithData(renderer, 0.5, 1.0, "fiskheroes:intangibility_timer");
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "fiskheroes:charged_beam", "head", getBeamColor(), [
        { "firstPerson": [0.0, -6.15, 0.0], "offset": [0.0, -6.15, -4.0], "size": [1.0, 0.5] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_charged_beam"));
    var night_vision = renderer.bindProperty("fiskheroes:night_vision").setCondition(entity => {
        night_vision.factor = 1
            return true;
    })
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimation(renderer, "vision.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "vision.HOVER", "fiskheroes:flight/idle/neutral");
    utils.addAnimationEvent(renderer, "FLIGHT_DIVE", "fiskheroes:iron_man_dive");

    addAnimationWithData(renderer, "iron_man.LAND", "fiskheroes:superhero_landing", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;

    addAnimationWithData(renderer, "iron_man.ROLL", "fiskheroes:flight/barrel_roll", "fiskheroes:barrel_roll_timer")
        .priority = 10;

        addAnimation(renderer, "vision.HOLOSTAND", "wv:levitate")
    .setData((entity, data) => {
        var f = entity.getInterpolatedData("wv:dyn/holoanimation");
        data.load(4*f <= 0.95 ? 4*f : 0.95);
    });
}

function getBeamColor() {
    return 0xFFFF55;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm) {
        if (renderLayer == "HELMET") {
            overlay.opacity = entity.getInterpolatedData("fiskheroes:beam_charge");
            overlay.render();
        }
        else if (renderLayer == "CHESTPLATE") {
            cape.render(entity);
        }
        else
        if (entity.isWearingFullSuit()) {
           (entity.getInterpolatedData("wv:dyn/holoanimation") > 0); {
                overlay.render();
            }
    }
}
}
