var LOADTEXTURES = {
    "omnitrix": "tmf:omnitrix/device/omnitrix_prototype.tx.json",
    "omnitrix_lights": "tmf:omnitrix/device/omnitrix_prototype_lights.tx.json",
    "omnitrix_pod": "tmf:omnitrix/device/pod",

	"badge": "tmf:omnitrix/badge/badge_os",
	"badge_lights": "tmf:omnitrix/badge/badge_os_lights.tx.json",

    "null": "tmf:null"
};

var IMPLEMENTS = {
    utils: "fiskheroes:external/utils"
};

function init(renderer, getAlien, isCurrent) {
    utils.bindParticles(renderer, "tmf:omnitrix_transformation");

    transformationGlow = renderer.createEffect("fiskheroes:glowerlay");

    var modelOmnitrixPrototype = renderer.createResource("MODEL", "tmf:omnitrix/device/omnitrix_prototype");
    modelOmnitrixPrototype.texture.set("omnitrix", "omnitrix_lights");
    modelOmnitrixPrototype.bindAnimation("tmf:omnitrix/omnitrix_dial").setData((entity, data) => {
        data.load(0, entity.getInterpolatedData('tmf:dyn/selecting_timer')); 
        data.load(1, entity.getInterpolatedData('tmf:dyn/selecting_timer2')); 
    });
    var omnitrixPrototype = renderer.createEffect("fiskheroes:model").setModel(modelOmnitrixPrototype);

    var modelPod = renderer.createResource("MODEL", "tmf:omnitrix/device/omnitrix_pod");
    modelPod.texture.set("omnitrix_pod");
    var pod = renderer.createEffect("fiskheroes:model").setModel(modelPod);
    pod.setOffset(0, 0, 2);

    addAnimationWithData(renderer, "omnitrix.ARM_MOVEMENT", "tmf:omnitrix/arm_movement","tmf:dyn/selecting_timer");
    return {
        getTexture: entity => "null",
        getLights: entity => "null",
        render: (entity, isFirstPersonArm) => {
                if (isFirstPersonArm) {
                    omnitrixPrototype.setOffset(-14, 4, 2);
                    omnitrixPrototype.setRotation(-60.0, 165.0, -55.0);
                    omnitrixPrototype.anchor.ignoreAnchor(true);	
                } 
                if (!isFirstPersonArm) {
                    omnitrixPrototype.setOffset(0, 0, 0);
                    omnitrixPrototype.setRotation(0.0, 0.0, 0.0);
                    omnitrixPrototype.anchor.ignoreAnchor(false);	
                    omnitrixPrototype.anchor.set("leftArm");
                }

                if (!isFirstPersonArm && entity.as("DISPLAY").getDisplayType() == "FABRICATOR_RESULT") {	
                    pod.render();
                }

            if (entity.getData('tmf:dyn/transformation') && entity.getData('tmf:dyn/transformation_timer') != 1) {
                transformationGlow.color.set(0x83cb59);
                transformationGlow.opacity = entity.getInterpolatedData('tmf:dyn/transformation_timer');
                transformationGlow.render();
            }
            if (!entity.getData('tmf:dyn/transformation') && entity.getData('tmf:dyn/transformation_timer') != 0) {
                transformationGlow.color.set(0xd74f56);
                transformationGlow.opacity = 1.0001-entity.getInterpolatedData('tmf:dyn/transformation_timer');
                transformationGlow.render();
            }
            if (entity.as("DISPLAY").getDisplayType() != "FABRICATOR_RESULT") {	
                omnitrixPrototype.render();
            }
        }
    };
}
