<commit_before>var SCENES = [
			{
			name:'houseEntrance',
			pano:'#house_entrance',
			hotspots: [
					{
						id:'hall_H',
						connected: 'hall',
						position: "-10.8 -0.7836511050129384 6.393604706111482",
						rotation: "0 -60 0",
                        src: "./assets/panos/hall.jpg"
					}
				],
            download: false
			},
			{
			name:'hall',
			pano:'#hall',
			hotspots: [
					{
						id:'livingRoom_H',
						connected: 'livingRoom',
						position: "-13 -0.7836511050129384 6.393604706111482",
						rotation: "0 -60 0",
						src: "./assets/panos/livingRoom.jpg"
					},
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-9.33 -2.54 -7.16",
						rotation: "0 -140 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'livingRoom',
			pano:'#living_room',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-12.8 -0.9 1.82",
						rotation: "0 -60 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'diningRoom',
			pano:'#dining_room',
			hotspots: [
					{
						id:'kitchen_H',
						connected: 'kitchen',
						position: "-15 -0.103 3.383",
						rotation: "0 -60 0",
						src: "./assets/panos/kitchen.jpg"
					},
					{
						id:'bedroomTwo_H',
						connected: 'bedRoomTwo',
						position: "14.48 1.253 11.65",
						rotation: "0 47.61 0",
						src: "./assets/panos/bedroomTwo.jpg"
					},
					{

						id:'bedroomOne_H',
						connected: 'bedRoomOne',
						position: "11.79 -0.20 14.34",
						rotation: "0 34.66 0",
						src: "./assets/panos/bedroomOne.jpg"
					},
					{
						id:'guestRoom_H',
						connected: 'guestRoom',
						position: "13.55 1.272 2.929",
						rotation: "0 93.5 0",
						src: "./assets/panos/guestRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'kitchen',
			pano:'#kitchen',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "9.229 -0.31 10.36",
						rotation: "0 -137 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwo',
			pano:'#bedroom_two',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "5.687 -1.92 11.44",
						rotation: "0 36.84 0",
						src: "./assets/panos/CorridorView.jpg"
					},
					{
						id:'bedroomTwoAnotherView_H',
						connected: 'bedRoomTwoViewTwo',
						position: "7.02 -1.92 -11.8",
						rotation: "0 143.2 0",
						src: "./assets/panos/bedroomTwoAnotherView.jpg"
					},{
						id:'bedroomTwoBathroom_H',
						connected: 'bedRoomTwoBathroom',
						position: "-14.0 -1.92 -10.8",
						rotation: "0 -128.0 0",
						src: "./assets/panos/bedroomTwoBathroomView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwoViewTwo',
			pano:'#bedroom_two_view2',
			hotspots: [
					{
						id:'bedroomTwo',
						connected: 'bedRoomTwo',
						position: "-8.91 -1.92 11.85",
						rotation: "0 -41.8 0",
						src: "./assets/panos/bedroomTwo.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwoBathroom',
			pano:'#bedroom_two_bathroom',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "10.45 1.033 13.56",
						rotation: "0 51.39 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomOne',
			pano:'#bedroom_one',
			hotspots: [
					{
						id:'bedRoomOneBathroom_H',
						connected: 'bedRoomOneBathroom',
						position: "-8.10 -0.75 4.833",
						rotation: "0 -57.8 0",
						src: "./assets/panos/bedroomOneBathroom.jpg"
					},
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "-15.9 0.232 1.012",
						rotation: "0 -80.3 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomOneBathroom',
			pano:'#bedroom_one_bathroom',
			hotspots: [
					{
						id:'bedroomOne_H',
						connected: 'bedRoomOne',
						position: "6.363 0.055 -6.06",
						rotation: "0 126.2 0",
						src: "./assets/panos/bedroomOne.jpg"
					}
				],
            download: false
			},
			{
			name:'guestRoom',
			pano:'#guest_room',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "11.61 -0.27 2.413",
						rotation: "0 104 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'commonBathRoom',
			pano:'#common_bathroom',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-0.01 -1.92 -10.7",
						rotation: "0 -180 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'CorridorView',
			pano:'#corridor_view',
			hotspots: [
					{
						id:'guestRoom_H',
                        connected : 'guestRoom',
						position:'-4.85 -0.83 -6.33',
						rotation: '0.0 -147.0 0.0',
                        src: "./assets/panos/guestRoom.jpg"
					},{
						id:'commonBathRoom_H',
                        connected : 'commonBathRoom',
						position:'5.95 0.812 8.691',
						rotation: '0 35.06 0',
                        src: "./assets/panos/commonBathroom.jpg"
					},{
						id:'bedRoomTwo_H',
                        connected : "bedRoomTwo",
						position:"11.29 -1.33 -18.2",
						rotation:"0 156.3 0",
                        src: "./assets/panos/bedroomTwo.jpg"
					},{
						id:'bedRoomOne_H',
                        connected : "bedRoomOne",
						position:"14.43 1.48 -11.3",
						rotation:"0 137.6 0",
                        src: "./assets/panos/bedroomOne.jpg"
					},{
						id:'hall',
                        connected : "hall",
						position:"-10.7 -1.57 9.476",
						rotation:"0 -50.3 0",
                        src: "./assets/panos/hall.jpg"
					}
				],
            download: false
			}
		];


var sceneArray = [];

/**
 * finds scene in SCENES json array
 * @param  {[String]} sceneName [name of scene]
 */
var findScene = function(sceneName) {
    var count = 0;
    var countFinal = 0;
    SCENES.map(function(scene){
        if(scene.name !== sceneName){
            count = count + 1;
        } else {
            countFinal = count;
        }
    });
    return countFinal;
}


/**
 * Search for hotspots from currentScene
 * get ID and src for each hotspot
 * add the images to <a-assets>
 * set download flag as true to prevent re-download
 */
var preloadImage = function(hotspot) {
    var num = findScene(hotspot.connected);
    if(SCENES[num].download == false) {
        var img = new Image();
        var newSceneId = hotspot.connected;
        var newSceneImgUrl = hotspot.src;

        img.src = newSceneImgUrl;
        img.id = newSceneId;
        document.querySelector('a-assets').appendChild(img);
        SCENES[num].download = true;
        // console.log(document.querySelectorAll('a-assets'));
    }
}

/**
 * renders a hotspot on current scene
 * adds the hotspots to <a-scene />
 * @param  {[String]} hotspot [hotspot to be rendered]
 */
var renderHotspot = function(hotspot){
	var entity = document.createElement('a-entity');
	entity.setAttribute('template','src: #link');
	entity.setAttribute('data-thumb','#hotspot');
	entity.setAttribute('data-src',hotspot.connected);
	entity.setAttribute('data-title',hotspot.connected);
	entity.setAttribute('position',hotspot.position);
	entity.setAttribute('rotation',hotspot.rotation);
	entity.setAttribute('class','hotspotClass');
	document.querySelector('a-scene').append(entity);
}


/**
 * loads a new scene by replacing old scene and replacing hotspots
 * @param  {[String]} sceneName  [new scene]
 * @param  {[String]} loadedFrom [old scene]
 */
var loadScene = function(sceneName,loadedFrom){
	sceneArray.push(sceneName);
	SCENES.map(function(scene){
		if(scene.name === sceneName){
            setTimeout(function() {
                removeHotspots();
                console.log("hotspots removed.");
            }, 50);

            var sky = document.querySelector('a-sky');
            sky.removeAttribute("src");

            var sky_image = document.getElementById(scene.name);
            var loader = document.querySelector("#loader_entity");
            sky_image.addEventListener("loaded", function() {

                // remove loader after all assets are loaded
                console.log("images loaded.");
                console.log("loader = " + loader);
                loader.setAttribute('visible', false);
                console.log("loader made false.");
                console.log("loader = " + loader);

                // set new sky
                sky.setAttribute('src',"#" + scene.name);
                sky.setAttribute('color','');
                console.log("sky changed.");
            });

            // load new hotspots and new scene's images
            setTimeout(function() {
                scene.hotspots.map(function(hotspot){
                    preloadImage(hotspot);
                    renderHotspot(hotspot);
                });
                console.log("images preloaded and hotspots rendered.");
            }, 50);
		}
	});
}

/**
 * removes all hotspots of old scene<commit_msg>[WIP] testing loader-2.3.1<commit_after>var SCENES = [
			{
			name:'houseEntrance',
			pano:'#house_entrance',
			hotspots: [
					{
						id:'hall_H',
						connected: 'hall',
						position: "-10.8 -0.7836511050129384 6.393604706111482",
						rotation: "0 -60 0",
                        src: "./assets/panos/hall.jpg"
					}
				],
            download: false
			},
			{
			name:'hall',
			pano:'#hall',
			hotspots: [
					{
						id:'livingRoom_H',
						connected: 'livingRoom',
						position: "-13 -0.7836511050129384 6.393604706111482",
						rotation: "0 -60 0",
						src: "./assets/panos/livingRoom.jpg"
					},
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-9.33 -2.54 -7.16",
						rotation: "0 -140 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'livingRoom',
			pano:'#living_room',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-12.8 -0.9 1.82",
						rotation: "0 -60 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'diningRoom',
			pano:'#dining_room',
			hotspots: [
					{
						id:'kitchen_H',
						connected: 'kitchen',
						position: "-15 -0.103 3.383",
						rotation: "0 -60 0",
						src: "./assets/panos/kitchen.jpg"
					},
					{
						id:'bedroomTwo_H',
						connected: 'bedRoomTwo',
						position: "14.48 1.253 11.65",
						rotation: "0 47.61 0",
						src: "./assets/panos/bedroomTwo.jpg"
					},
					{

						id:'bedroomOne_H',
						connected: 'bedRoomOne',
						position: "11.79 -0.20 14.34",
						rotation: "0 34.66 0",
						src: "./assets/panos/bedroomOne.jpg"
					},
					{
						id:'guestRoom_H',
						connected: 'guestRoom',
						position: "13.55 1.272 2.929",
						rotation: "0 93.5 0",
						src: "./assets/panos/guestRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'kitchen',
			pano:'#kitchen',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "9.229 -0.31 10.36",
						rotation: "0 -137 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwo',
			pano:'#bedroom_two',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "5.687 -1.92 11.44",
						rotation: "0 36.84 0",
						src: "./assets/panos/CorridorView.jpg"
					},
					{
						id:'bedroomTwoAnotherView_H',
						connected: 'bedRoomTwoViewTwo',
						position: "7.02 -1.92 -11.8",
						rotation: "0 143.2 0",
						src: "./assets/panos/bedroomTwoAnotherView.jpg"
					},{
						id:'bedroomTwoBathroom_H',
						connected: 'bedRoomTwoBathroom',
						position: "-14.0 -1.92 -10.8",
						rotation: "0 -128.0 0",
						src: "./assets/panos/bedroomTwoBathroomView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwoViewTwo',
			pano:'#bedroom_two_view2',
			hotspots: [
					{
						id:'bedroomTwo',
						connected: 'bedRoomTwo',
						position: "-8.91 -1.92 11.85",
						rotation: "0 -41.8 0",
						src: "./assets/panos/bedroomTwo.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomTwoBathroom',
			pano:'#bedroom_two_bathroom',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "10.45 1.033 13.56",
						rotation: "0 51.39 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomOne',
			pano:'#bedroom_one',
			hotspots: [
					{
						id:'bedRoomOneBathroom_H',
						connected: 'bedRoomOneBathroom',
						position: "-8.10 -0.75 4.833",
						rotation: "0 -57.8 0",
						src: "./assets/panos/bedroomOneBathroom.jpg"
					},
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "-15.9 0.232 1.012",
						rotation: "0 -80.3 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'bedRoomOneBathroom',
			pano:'#bedroom_one_bathroom',
			hotspots: [
					{
						id:'bedroomOne_H',
						connected: 'bedRoomOne',
						position: "6.363 0.055 -6.06",
						rotation: "0 126.2 0",
						src: "./assets/panos/bedroomOne.jpg"
					}
				],
            download: false
			},
			{
			name:'guestRoom',
			pano:'#guest_room',
			hotspots: [
					{
						id:'corridorView_H',
						connected: 'CorridorView',
						position: "11.61 -0.27 2.413",
						rotation: "0 104 0",
						src: "./assets/panos/CorridorView.jpg"
					}
				],
            download: false
			},
			{
			name:'commonBathRoom',
			pano:'#common_bathroom',
			hotspots: [
					{
						id:'diningRoom_H',
						connected: 'diningRoom',
						position: "-0.01 -1.92 -10.7",
						rotation: "0 -180 0",
						src: "./assets/panos/diningRoom.jpg"
					}
				],
            download: false
			},
			{
			name:'CorridorView',
			pano:'#corridor_view',
			hotspots: [
					{
						id:'guestRoom_H',
                        connected : 'guestRoom',
						position:'-4.85 -0.83 -6.33',
						rotation: '0.0 -147.0 0.0',
                        src: "./assets/panos/guestRoom.jpg"
					},{
						id:'commonBathRoom_H',
                        connected : 'commonBathRoom',
						position:'5.95 0.812 8.691',
						rotation: '0 35.06 0',
                        src: "./assets/panos/commonBathroom.jpg"
					},{
						id:'bedRoomTwo_H',
                        connected : "bedRoomTwo",
						position:"11.29 -1.33 -18.2",
						rotation:"0 156.3 0",
                        src: "./assets/panos/bedroomTwo.jpg"
					},{
						id:'bedRoomOne_H',
                        connected : "bedRoomOne",
						position:"14.43 1.48 -11.3",
						rotation:"0 137.6 0",
                        src: "./assets/panos/bedroomOne.jpg"
					},{
						id:'hall',
                        connected : "hall",
						position:"-10.7 -1.57 9.476",
						rotation:"0 -50.3 0",
                        src: "./assets/panos/hall.jpg"
					}
				],
            download: false
			}
		];


var sceneArray = [];

/**
 * finds scene in SCENES json array
 * @param  {[String]} sceneName [name of scene]
 */
var findScene = function(sceneName) {
    var count = 0;
    var countFinal = 0;
    SCENES.map(function(scene){
        if(scene.name !== sceneName){
            count = count + 1;
        } else {
            countFinal = count;
        }
    });
    return countFinal;
}


/**
 * Search for hotspots from currentScene
 * get ID and src for each hotspot
 * add the images to <a-assets>
 * set download flag as true to prevent re-download
 */
var preloadImage = function(hotspot) {
    var num = findScene(hotspot.connected);
    if(SCENES[num].download == false) {
        var img = new Image();
        var newSceneId = hotspot.connected;
        var newSceneImgUrl = hotspot.src;

        img.src = newSceneImgUrl;
        img.id = newSceneId;
        document.querySelector('a-assets').appendChild(img);
        SCENES[num].download = true;
        // console.log(document.querySelectorAll('a-assets'));
    }
}

/**
 * renders a hotspot on current scene
 * adds the hotspots to <a-scene />
 * @param  {[String]} hotspot [hotspot to be rendered]
 */
var renderHotspot = function(hotspot){
	var entity = document.createElement('a-entity');
	entity.setAttribute('template','src: #link');
	entity.setAttribute('data-thumb','#hotspot');
	entity.setAttribute('data-src',hotspot.connected);
	entity.setAttribute('data-title',hotspot.connected);
	entity.setAttribute('position',hotspot.position);
	entity.setAttribute('rotation',hotspot.rotation);
	entity.setAttribute('class','hotspotClass');
	document.querySelector('a-scene').append(entity);
}


/**
 * loads a new scene by replacing old scene and replacing hotspots
 * @param  {[String]} sceneName  [new scene]
 * @param  {[String]} loadedFrom [old scene]
 */
var loadScene = function(sceneName,loadedFrom){
	sceneArray.push(sceneName);
	SCENES.map(function(scene){
		if(scene.name === sceneName){
            setTimeout(function() {
                removeHotspots();
                console.log("hotspots removed.");
            }, 50);

            var sky = document.querySelector('a-sky');
            var sky_image = document.getElementById(scene.name);
            var loader = document.querySelector("#loader_entity");

            $(sky_image).load(function() {
                // remove loader after all assets are loaded
                loader.setAttribute('visible', false);
                console.log("loader made false.");

                // set new sky
                sky.removeAttribute("src");
                sky.setAttribute('src',"#" + scene.name);
                sky.setAttribute('color','');
                console.log("sky changed.");
            });

            // load new hotspots and new scene's images
            setTimeout(function() {
                scene.hotspots.map(function(hotspot){
                    preloadImage(hotspot);
                    renderHotspot(hotspot);
                });
                console.log("images preloaded and hotspots rendered.");
            }, 50);
		}
	});
}

/**
 * removes all hotspots of old scene
{'fraction_non_alphanumeric': 0.1545669969840586, 'fraction_numerical': 0.04690866006031883, 'mean_word_length': 1.8780223186608804, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2678669', 'n_tokens_mistral': 8489, 'n_tokens_neox': 6132, 'n_words': 1160}