<commit_before>'use strict';
//Not yet implemented into html file
angular.module('gameApp')
    .controller("MapController", ["$rootScope", '$http', function ($rootScope, $http) {

        //Make an SVG Container
        $rootScope.svgMap = d3.select("#svgMap").append("svg")
            .attr("width", 900)
            .attr("height", 900);


        $rootScope.mapList = {};
        $http.get('json/mapPaths.json').success(function (mapData){


            //Add Countries to SVG Container
            angular.forEach(mapData.Map, function(index) {
                $rootScope.mapList[String(index.id)] = $rootScope.svgMap.append("path")
                    .attr("id", index.id)
                    .attr("d", index.d)
                    .attr("stroke", index.stroke)
                    .attr("fill", index.fill);
            });

        });

        console.log($rootScope.mapList);

        angular.forEach($rootScope.mapList, function (index) {

            index[0].addEventListener("mouseover", function () {
                $rootScope.thisCountryID = index.node.id;
                angular.forEach($rootScope.board, function (index) {
                    if ($rootScope.thisCountryID === index.CountryID) {
                        $rootScope.countryName = index.CountryName;
                        $rootScope.owner = index.Owner;
                        $rootScope.troops = index.Troops;
                    }
                    angular.forEach($rootScope.players, function (player) {
                        if ($rootScope.owner === player.PlayerOrder) {
                            $rootScope.playerName = player.DisplayName;
                        }
                    });
                });
                angular.forEach($rootScope.board, function (index){
                    if ($rootScope.thisCountryID === index.CountryID) {
                        if($rootScope.currentPlayer!==index.Owner){
                            $rootScope.defendCountryName = index.CountryName;
                            $rootScope.defendOwner = index.Owner;
                            $rootScope.defendTroops = index.Troops;
                        }else{
                            $rootScope.attackCountryName = index.CountryName;
                            $rootScope.attackOwner = index.Owner;
                            $rootScope.attackTroops = index.Troops;
                        }}
                    angular.forEach($rootScope.players, function (player) {
                        if ($rootScope.attackOwner === player.PlayerOrder) {
                            $rootScope.attackOwner = player.DisplayName;
                        };
                        if($rootScope.defendOwner === player.PlayerOrder){
                            $rootScope.defendOwner = player.DisplayName;
                        }

                    });
                });

            }, true);

            index[0].addEventListener("mouseout", function () {
            }, true);

            index[0].addEventListener("click", function () {
                $rootScope.thisCountryID = index.node.id;

                if ($rootScope.currentPlayer === $rootScope.thisUserNumber) {
                    index.animate(defaultCountry, animationSpeed);
                    if ($rootScope.phase === "Setup") {
                        var send = JSON.stringify({Command: "Setup", Data: {CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                        postData(send);
                    }
                    if ($rootScope.phase === "Deploy") {
                        var send = JSON.stringify({Command: "Deploy", Data: {CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                        postData(send);
                    }
                    if ($rootScope.phase === "Attack") {
                        angular.forEach($rootScope.board, function (index){
                            if ($rootScope.thisCountryID === index.CountryID) {
                                if($rootScope.currentPlayer === index.Owner){
                                    $rootScope.attackCountryID = $rootScope.thisCountryID;
                                    console.log("attack");
                                }
                                if($rootScope.currentPlayer !== index.Owner){
                                    $rootScope.defendCountryID = $rootScope.thisCountryID;
                                    console.log("defend");
                                }
                            }
                        });


                    }
                    if ($rootScope.phase === "Move") {
                        var send = JSON.stringify({Command: "Move", Data: {SourceCountry: $rootScope.prevCountryID, CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                        postData(send);
                    }
                    $rootScope.prevCountryID = index.node.id;

                }
                else {
                    console.log("Not your turn");
                }
            }, true);
        });

        function postData(data) {
            $http({
                method: 'POST',
                url: 'GameServlet',
                headers: {'Content-Type': 'application/json'},
                data: data
            }).error();
        }

        }]);<commit_msg>moved adding event listeners into get request success function<commit_after>'use strict';
//Not yet implemented into html file
angular.module('gameApp')
        .controller("MapController", ["$rootScope", '$http', function ($rootScope, $http) {

                //Make an SVG Container
                $rootScope.svgMap = d3.select("#svgMap").append("svg")
                        .attr("width", 900)
                        .attr("height", 900);


                $rootScope.mapList = {};
                $http.get('json/mapPaths.json').success(function (mapData) {

                    //Add Countries to SVG Container
                    angular.forEach(mapData.Map, function (index) {
                        $rootScope.mapList[String(index.id)] = $rootScope.svgMap.append("path")
                                .attr("id", index.id)
                                .attr("d", index.d)
                                .attr("stroke", index.stroke)
                                .attr("fill", index.fill);
                    });


                    angular.forEach($rootScope.mapList, function (index) {

                        index[0][0].addEventListener("mouseover", function () {
                            $rootScope.thisCountryID = index.node.id;
                            
                            angular.forEach($rootScope.board, function (index) {
                                if ($rootScope.thisCountryID === index.CountryID) {
                                    $rootScope.countryName = index.CountryName;
                                    $rootScope.owner = index.Owner;
                                    $rootScope.troops = index.Troops;
                                }
                                angular.forEach($rootScope.players, function (player) {
                                    if ($rootScope.owner === player.PlayerOrder) {
                                        $rootScope.playerName = player.DisplayName;
                                    }
                                });
                            });
                            
                            angular.forEach($rootScope.board, function (index) {
                                if ($rootScope.thisCountryID === index.CountryID) {
                                    if ($rootScope.currentPlayer !== index.Owner) {
                                        $rootScope.defendCountryName = index.CountryName;
                                        $rootScope.defendOwner = index.Owner;
                                        $rootScope.defendTroops = index.Troops;
                                    } else {
                                        $rootScope.attackCountryName = index.CountryName;
                                        $rootScope.attackOwner = index.Owner;
                                        $rootScope.attackTroops = index.Troops;
                                    }
                                }
                                
                                angular.forEach($rootScope.players, function (player) {
                                    if ($rootScope.attackOwner === player.PlayerOrder) {
                                        $rootScope.attackOwner = player.DisplayName;
                                    }
                                    ;
                                    if ($rootScope.defendOwner === player.PlayerOrder) {
                                        $rootScope.defendOwner = player.DisplayName;
                                    }

                                });
                            });

                        }, true);

                        index[0][0].addEventListener("mouseout", function () {
                        }, true);

                        index[0][0].addEventListener("click", function () {
                            $rootScope.thisCountryID = index.node.id;

                            if ($rootScope.currentPlayer === $rootScope.thisUserNumber) {
                                index.animate(defaultCountry, animationSpeed);
                                if ($rootScope.phase === "Setup") {
                                    var send = JSON.stringify({Command: "Setup", Data: {CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                                    postData(send);
                                }
                                if ($rootScope.phase === "Deploy") {
                                    var send = JSON.stringify({Command: "Deploy", Data: {CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                                    postData(send);
                                }
                                if ($rootScope.phase === "Attack") {
                                    angular.forEach($rootScope.board, function (index) {
                                        if ($rootScope.thisCountryID === index.CountryID) {
                                            if ($rootScope.currentPlayer === index.Owner) {
                                                $rootScope.attackCountryID = $rootScope.thisCountryID;
                                                console.log("attack");
                                            }
                                            if ($rootScope.currentPlayer !== index.Owner) {
                                                $rootScope.defendCountryID = $rootScope.thisCountryID;
                                                console.log("defend");
                                            }
                                        }
                                    });


                                }
                                if ($rootScope.phase === "Move") {
                                    var send = JSON.stringify({Command: "Move", Data: {SourceCountry: $rootScope.prevCountryID, CountryClicked: $rootScope.thisCountryID, CurrentPlayer: $rootScope.currentPlayer}});
                                    postData(send);
                                }
                                $rootScope.prevCountryID = index.node.id;

                            }
                            else {
                                console.log("Not your turn");
                            }
                        }, true);
                    });
                });

                function postData(data) {
                    $http({
                        method: 'POST',
                        url: 'GameServlet',
                        headers: {'Content-Type': 'application/json'},
                        data: data
                    }).error();
                }

            }]);
{'fraction_non_alphanumeric': 0.10360138135175136, 'fraction_numerical': 0.0018911363262621279, 'mean_word_length': 0.9851477068712258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930747', 'n_tokens_mistral': 2671, 'n_tokens_neox': 2468, 'n_words': 409}