extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:spider_girl/spider_girl_layer1",
    "layer2": "skarlet:spider_girl/spider_girl_layer2",
    "spider_sense_1" : "skarlet:spider_girl/spider_sense_1",
    "spider_sense_2" : "skarlet:spider_girl/spider_sense_2"
});

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

var chest;

var spider_sense;
var model_spider_sense;

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

function initEffects(renderer) {
    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0xDC2901);
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.5).setYOffset(1);

    model_spider_sense = renderer.createResource("MODEL", "skarlet:spider_sense");
    model_spider_sense.texture.set(null, "spider_sense_1");

    spider_sense = renderer.createEffect("fiskheroes:model").setModel(model_spider_sense);
    spider_sense.anchor.set("head");
}

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

    renderer.removeCustomAnimation("basic.AIMING");

    addAnimationWithData(renderer, "spiderman.AIMING", "fiskheroes:web_aim_right", "fiskheroes:web_aim_right_timer")
        .priority = 2;

    addAnimationWithData(renderer, "spiderman.AIMING_LEFT", "fiskheroes:web_aim_left", "fiskheroes:web_aim_left_timer")
        .priority = 2;

    addAnimationWithData(renderer, "spiderman.WEB_RAPPEL", "fiskheroes:web_rappel", "fiskheroes:web_rappel_timer")
        .priority = 5;

    utils.addAnimationEvent(renderer, "WEBSWING_DEFAULT", ["fiskheroes:swing_default", "fiskheroes:swing_default2"]);
    utils.addAnimationEvent(renderer, "WEBSWING_RIGHT", "fiskheroes:swing_right");
    utils.addAnimationEvent(renderer, "WEBSWING_LEFT", "fiskheroes:swing_left");
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_DEFAULT", [
        "skarlet:swinging/front_flip2",
        "skarlet:swinging/front_flip3",
        "fiskheroes:swing_roll",
        "fiskheroes:swing_roll2",
        "fiskheroes:swing_roll5"
    ]);
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_RIGHT", ["fiskheroes:swing_rotate_right"]);
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_LEFT", ["fiskheroes:swing_rotate_left"]);
    utils.addAnimationEvent(renderer, "WEBSWING_ZIP", "fiskheroes:swing_zip");
    utils.addAnimationEvent(renderer, "WEBSWING_DIVE", ["skarlet:swinging/dive2", "fiskheroes:swing_dive", "fiskheroes:swing_dive2"]);
    utils.addAnimationEvent(renderer, "WEBSWING_LEAP", "fiskheroes:swing_springboard");
    utils.addAnimationEvent(renderer, "WEBSWING_SHOOT_RIGHT", "fiskheroes:web_swing_shoot_right");
    utils.addAnimationEvent(renderer, "WEBSWING_SHOOT_LEFT", "fiskheroes:web_swing_shoot_left");
    utils.addAnimationEvent(renderer, "WEBSHOOTER_SHOOT_RIGHT", "fiskheroes:web_shoot_right");
    utils.addAnimationEvent(renderer, "WEBSHOOTER_SHOOT_LEFT", "fiskheroes:web_shoot_left");
    utils.addAnimationEvent(renderer, "CEILING_CRAWL", "fiskheroes:crawl_ceiling");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
        if (!isFirstPersonArm) {
            chest.render();
        }
	}

    if (renderLayer == "HELMET" && entity.getData("skarlet:dyn/spider_sense")) {
        if (entity.ticksExisted() % 5 >= 0 && entity.ticksExisted() % 5 < 2.5) {
            model_spider_sense.texture.set(null, "spider_sense_1");
        } else {
            model_spider_sense.texture.set(null, "spider_sense_2");
        }
        spider_sense.render();
    }
}