extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarlet:spider_gwen/ghost_spider_layer1",
    "layer2": "skarlet:spider_gwen/ghost_spider_layer2",
	"hood_layer1": "skarlet:spider_gwen/ghost_spider_hood_layer1",
    "spider_sense_1" : "skarlet:spider_gwen/spider_sense_1",
    "spider_sense_2" : "skarlet:spider_gwen/spider_sense_2"
});
var utils = implement("fiskheroes:external/utils");
var chest;

var spider_sense;
var model_spider_sense;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if ((renderLayer == "HELMET" || renderLayer == "CHESTPLATE") && (entity.isDisplayStand() || entity.isBookPlayer() ? entity.getData("fiskheroes:mask_open") : entity.getData("fiskheroes:mask_open_timer2") > 0.35)) {
            return "hood_layer1";
        }
        return renderLayer == "LEGGINGS" ? "layer2" : "layer1";
    });
}

function initEffects(renderer) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(0.9).setYOffset(1);

    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0xD13172);

    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 render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        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();
    }
}

function initAnimations(renderer) {
    parent.initAnimations(renderer);
	
    addAnimation(renderer, "spiderman.MASK", "fiskheroes:remove_cowl")
        .setData((entity, data) => {
            var f = entity.getInterpolatedData("fiskheroes:mask_open_timer2");
            data.load(f < 1 ? f : 0);
        });
		
    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");
    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", ["skarlet:swinging/right_trick", "fiskheroes:swing_rotate_right"]);
    utils.addAnimationEvent(renderer, "WEBSWING_TRICK_LEFT", ["skarlet:swinging/left_trick", "fiskheroes:swing_rotate_left"]);
    utils.addAnimationEvent(renderer, "WEBSWING_ZIP", "fiskheroes:swing_zip");
    utils.addAnimationEvent(renderer, "WEBSWING_DIVE", ["skarlet:swinging/dive1", "skarlet:swinging/dive3", "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");
}
