extend("ahhp:hero_with_models");

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

loadTextures({
    "cape": "ahhp:robin_cape",
    "model_lights": "ahhp:robin_model_lights",
    "model": "ahhp:robin_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) {
    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x339E38);
    models = models_stuff.maskToggleModels(renderer, "robin");
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    cape = capes.createDefault(renderer, 20, "fiskheroes:cape_default.mesh.json", physics);
    cape.effect.texture.set("cape");
    cape.effect.width = 14;
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.7, "offset": [0.0, 5.0, 3.0], "rotation": [0.0, 0.0, -45.0] }
    ]);
}

function render(entity, renderLayer, isFirstPersonArm) {
    models.render(entity, renderLayer);
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity, entity.getInterpolatedData("fiskheroes:wing_animation_timer"));
    }
}
