extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:supergirl/supergirl_dceu_layer1",
    "layer2": "skarlet:supergirl/supergirl_dceu_layer2",
    "cape": "skarlet:supergirl/supergirl_dceu_cape",
    "eyes": "fiskheroes:reverse_flash_eyes",
	"spit": "skarlet:supergirl/spit"
});

var utils = implement("fiskheroes:external/utils");
var capes = implement("fiskheroes:external/capes");
var chest;
var cape;
var overlay;
var model;

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

    renderer.showModel("CHESTPLATE", "head", "headwear", "body", "rightArm", "leftArm");
}

function initEffects(renderer) { 

	var _model = utils.createModel(renderer, "skarlet:spit", "spit");
    model = renderer.createEffect("fiskheroes:model");
    model.setModel(_model);
    model.anchor.set("head");

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

    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.7).setYOffset(1);
    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");
	
    utils.addCameraShake(renderer, 0.1, 1.5, "fiskheroes:dyn/superhero_landing_timer");
	
    utils.bindTrail(renderer, "skarlet:superman");
    utils.bindTrail(renderer, "skarlet:superman_boost").setCondition(entity => entity.getData("fiskheroes:dyn/flight_super_boost") > 0);

    utils.bindBeam(renderer, "fiskheroes:repulsor_blast", "fiskheroes:repulsor_blast", "leftArm", 0xFF7700, [
        { "firstPerson": [5.0, 3.75, -15.0], "offset": [0.0, 18.8, -3.0], "size": [1.0, 1.0] }
    ]);
    utils.bindBeam(renderer, "fiskheroes:heat_vision", "skarlet:clear", "head", 0xFFFFFF, [{
                "firstPerson": [0, 0, 0],
                "offset": [0, 0, 0],
                "size": [0, 0]
            }]);
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "skarlet:heat_vision", "head", 0xFF0000, [
        { "firstPerson": [2.2, 0.0, 2.0], "offset": [2.2, -3.3, -4.0], "size": [1.0, 0.5] },
        { "firstPerson": [-2.2, 0.0, 2.0], "offset": [-2.2, -3.3, -4.0], "size": [1.0, 0.5] }
    ]).setParticles(renderer.createResource("PARTICLE_EMITTER", "fiskheroes:impact_heat_vision"));
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
    utils.addFlightAnimationWithLanding(renderer, "superman.FLIGHT", "fiskheroes:flight/default.anim.json");
    utils.addHoverAnimation(renderer, "superman.HOVER", "fiskheroes:flight/idle/default");
    addAnimationWithData(renderer, "supergirl.LAND", "skarlet:supergirl_pose", "fiskheroes:dyn/superhero_landing_timer")
        .priority = -8;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (isFirstPersonArm && entity.getInterpolatedData("skarlet:dyn/throw_timer") > 0) {
        model.anchor.ignoreAnchor(true);
    } else {
        model.anchor.ignoreAnchor(false);
    }
    if (entity.getData("skarlet:dyn/throw")) {
    model.setOffset(0, 0, -entity.getInterpolatedData("skarlet:dyn/throw_timer") * (entity.getData("fiskheroes:heat_vision_length") * 16));
    model.render();
    }
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
		chest.render();
        cape.render(entity);
            overlay.opacity = entity.getInterpolatedData("fiskheroes:beam_charge");
            overlay.render();
	}
}