extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:batman/flashpoint_layer1",
    "layer2": "skarlet:batman/flashpoint_layer2",
    "eyes": "skarlet:batman/flashpoint_eyes",
    "cape": "skarlet:batman/flashpoint_cape",
    "cape2": "skarlet:batman/flashpoint_cape2",
    "shoulders": "skarlet:batman/flashpoint_shoulders",
	"gun": "skarlet:batman/flashpoint_gun"
});

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

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

var shoulders;
var cape;

function init(renderer) {
    renderer.setTexture((entity, renderLayer) => renderLayer == "LEGGINGS" ? "layer2" : "layer1");
    renderer.setLights((entity, renderLayer) => renderLayer == "HELMET" ? "eyes" : null);
	
    renderer.setItemIcons("%s_0", "%s_1", "%s_2", "%s_3");
    renderer.showModel("HELMET", "head", "headwear");
    renderer.showModel("CHESTPLATE", "body", "rightArm", "leftArm");
    renderer.showModel("LEGGINGS", "body", "rightLeg", "leftLeg");
    renderer.showModel("BOOTS", "rightLeg", "leftLeg");
    renderer.fixHatLayer("HELMET");
    
    initEffects(renderer);
    initAnimations(renderer);
}

function initEffects(renderer) {
    utils.addLivery(renderer, "DESERT_EAGLE", "gun");
	
    shoulders = renderer.createEffect("fiskheroes:shield");
    shoulders.texture.set("shoulders");
    shoulders.anchor.set("rightArm");
    shoulders.setCurve(32.5, 80.0);
    shoulders.setOffset(3.5, -0.0, 0.0);
	shoulders.setRotation(180.0, 0.0, 0.0);
    shoulders.mirror = true;
	
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;

    cape = capes.createGlider(renderer, 24, "fiskheroes:cape_batman.mesh.json", physics);
    cape.effect.texture.set("cape");

    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x000000);
    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] }
    ]).slotIndex = 0;
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "rightLeg", "scale": 0.7, "offset": [-2.0, 0.0, 1.0], "rotation": [90.0, 0.0, -7.0] },
        { "anchor": "leftLeg", "scale": 0.7, "offset": [2.0, 0.0, 1.0], "rotation": [90.0, 0.0, 7.0] }
    ]).slotIndex = 1;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity, entity.getInterpolatedData("fiskheroes:wing_animation_timer"));
		shoulders.render();
    }
	if (entity.getData('fiskheroes:gliding')) {
		cape.effect.texture.set("cape2");
	} else {
		cape.effect.texture.set("cape");
	}
}