extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarredheroes:bat/batman_comics_layer1",
    "layer2": "skarredheroes:bat/batman_comics_layer2",
    "cape": "skarredheroes:bat/batman_comics_cape",
    "cape2": "skarredheroes:bat/batman_comics_cape2",
	"ring": "skarredheroes:bat/kryptonite_ring",
	"ring_lights": "skarredheroes:bat/kryptonite_ring_lights",
	"blades": "skarredheroes:bat/batman_comics_blades"
});

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

var left_blades;
var right_blades;
var ring;
var ring_bloom;
var cape;

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

function initEffects(renderer) {
	
    right_blades = renderer.createEffect("fiskheroes:shield");
    right_blades.texture.set("blades");
    right_blades.anchor.set("rightArm");
    right_blades.setOffset(3.5, 4.0, 2.0);
	right_blades.setRotation(0.0, -30.0, 0.0);
	
    left_blades = renderer.createEffect("fiskheroes:shield");
    left_blades.texture.set("blades");
    left_blades.anchor.set("leftArm");
    left_blades.setOffset(-3.5, 4.0, 2.0);
	left_blades.setRotation(0.0, 30.0, 0.0);
	
    var model = renderer.createResource("MODEL", "skarredheroes:kryptonite_ring");
    model.texture.set("ring", "ring_lights");
	
    ring = renderer.createEffect("fiskheroes:model").setModel(model);
    ring.anchor.set("rightArm");
    ring.setOffset(1.9, 4.7, 0.5);
	ring.setScale(0.23);
	
    ring_bloom = utils.createLines(renderer, "fiskheroes:atom_booster", 0x22f934, [
        {"start": [0.0, 0.0, 0.0], "end": [0.0, -1.0, 0.0], "size": [8.0, 8.0]}
    ]);
    ring_bloom.anchor.set("rightArm", model.getCubeOffset("upperRingBase2"));
    ring_bloom.setOffset(1.75, 13.9, 0.95).setRotation(0, 0, 0.0).setScale(2.0, 1.0, 2.0);

    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(0x003F53);
    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] }
    ]);
}

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

    addAnimationWithData(renderer, "batman.BELT", "skarredheroes:belt", "fiskheroes:blade_timer");
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (renderLayer == "CHESTPLATE") {
		left_blades.render();
		right_blades.render();
		if (!isFirstPersonArm) {
			cape.render(entity, entity.getInterpolatedData("fiskheroes:wing_animation_timer"));
			if (entity.getData('fiskheroes:gliding')) {
				cape.effect.texture.set("cape2");
			} else {
				cape.effect.texture.set("cape");
			}
		}
		if (entity.getData('fiskheroes:blade_timer') >= 0.3) {
			ring.render();
			ring_bloom.render();
		}
    }
}