var LOADTEXTURES = {
    "null": "tmf:null",
    "ghostfreak": "tmf:omnitrix/p1/aliens/ghostfreak.tx.json",
    "ghostfreak_lights": "tmf:omnitrix/p1/lights/ghostfreak_lights.tx.json",
    "ghostfreak_tentacles": "tmf:omnitrix/p1/aliens/ghostfreak_tentacles",
    "ghostfreak_body": "tmf:omnitrix/p1/aliens/ghostfreak_body"
};

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

function init(renderer, getAlien, isCurrent) {

    utils.bindParticles(renderer, "tmf:alien_particles_p1").setCondition(entity => isCurrent(entity));
    
    utils.bindBeam(renderer, "fiskheroes:charged_beam", "tmf:thunder_clap", "body", 0xCACBCB, [
    ]).setCondition(entity => isCurrent(entity));

    var modelGhostfreak = renderer.createResource("MODEL", "tmf:omnitrix/aliens/ghostfreak");
    modelGhostfreak.bindAnimation("tmf:omnitrix/aliens/ghostfreak").setData((entity, data) => {
        data.load(0, entity.isSneaking() ? 1 : 0);
        data.load(1, entity.loop(60));
        data.load(2, entity.loop(80));
        data.load(3, entity.getPunchTimerInterpolated());
        data.load(4, entity.getInterpolatedData('fiskheroes:beam_charge'));
    });
    modelGhostfreak.texture.set("ghostfreak", "ghostfreak_lights");
    ghostfreak = renderer.createEffect("fiskheroes:model").setModel(modelGhostfreak);
    ghostfreak.anchor.ignoreAnchor(true);

    var modelGhostfreakArm = renderer.createResource("MODEL", "tmf:omnitrix/powers/ghostfreak_rArm");
    modelGhostfreakArm.texture.set("ghostfreak", "ghostfreak_lights");
    ghostfreakArm = renderer.createEffect("fiskheroes:model").setModel(modelGhostfreakArm);
    ghostfreakArm.anchor.set("rightArm");

    var modelGhostfreakTentacles = renderer.createResource("MODEL", "tmf:omnitrix/powers/ghostfreak_tentacles");
    modelGhostfreakTentacles.bindAnimation("tmf:omnitrix/powers/ghostfreak_tentacles").setData((entity, data) => {
        data.load(0, entity.getInterpolatedData('tmf:dyn/pt_1'));
        data.load(1, entity.isSneaking() ? 1 : 0);
        data.load(2, entity.loop(60));
    });
    modelGhostfreakTentacles.texture.set("ghostfreak_tentacles");
    ghostfreakTentacles = renderer.createEffect("fiskheroes:model").setModel(modelGhostfreakTentacles);
    ghostfreakTentacles.anchor.ignoreAnchor(true);

    var modelGhostfreakBody = renderer.createResource("MODEL", "tmf:omnitrix/powers/ghostfreak_body");
    modelGhostfreakBody.texture.set("ghostfreak_body");
    ghostfreakBody = renderer.createEffect("fiskheroes:model").setModel(modelGhostfreakBody);
    ghostfreakBody.anchor.ignoreAnchor(true);

    addAnimation(renderer, "ghostfreak.ARM", "tmf:omnitrix/powers/remove_arm").setData((entity, data) => {
        data.load(0, 1);
        }).setCondition(entity => isCurrent(entity));
  

    return {
        getTexture: entity => "null",
        getLights: entity => "null",
        render: (entity, isFirstPersonArm) => {
            if (!isFirstPersonArm) {
                ghostfreak.opacity = entity.getData('fiskheroes:intangible') ? 0.6 : 1;
                ghostfreak.render();
                if ((entity.getData('fiskheroes:beam_charge') + entity.getData('tmf:dyn/pt_1') + entity.getData('tmf:dyn/pc_1')) != 0) {
                    ghostfreakTentacles.setScale(0.2+0.8*entity.getInterpolatedData('tmf:dyn/pc_1'), 0.2+0.8*entity.getInterpolatedData('tmf:dyn/pc_1') ,entity.getInterpolatedData('tmf:dyn/pc_1'));
                    ghostfreakTentacles.setOffset(0, 6*(1-entity.getInterpolatedData('tmf:dyn/pc_1')),0);
                    ghostfreakTentacles.render();
                    ghostfreakBody.setScale(entity.getInterpolatedData('fiskheroes:beam_charge'), 1, entity.getInterpolatedData('fiskheroes:beam_charge'));
                    ghostfreakBody.render();
                }
            }

            if (isFirstPersonArm) {
                ghostfreakArm.opacity = entity.getData('fiskheroes:intangible') ? 0.6 : 1;
                ghostfreakArm.render();
            }
        }
    };
}

