Code coverage report for ./src/client/app/main/main.controller.js

Statements: 15.6% (17 / 109)      Branches: 0% (0 / 22)      Functions: 4.55% (1 / 22)      Lines: 15.6% (17 / 109)      Ignored: none     

All files » ./src/client/app/main/ » main.controller.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 1781     1       1     1                                                                                                           1                 1             1                               1               1             1                           1         1           1           1           1                   1                     1                
(function () {
    'use strict';
 
    angular
        .module('app.main')
        .controller('MainController', MainController);
 
    MainController.$inject = ['$rootScope', '$scope', 'playerService', 'mainService', '$timeout', '$compile', 'levelService', 'shopService', 'messageService', 'templateService', 'dialogueService', 'resourcesService', 'progressService', 'savingService'];
 
    /* @ngInject */
    function MainController($rootScope, $scope, playerService, mainService, $timeout, $compile, levelService, shopService, messageService, templateService, dialogueService, resourcesService, progressService, savingService) {
        var vm = this;
        vm.count = 0;
        vm.player = playerService.player;
        vm.progress = progressService.progress;
        vm.currentLocation = mainService.currentLocation;
        vm.locationDictionary = mainService.locationDictionary;
        vm.levelDictionary = levelService.levelDictionary;
        vm.currentLocation.specFunc();
        vm.reset = '';
        vm.switchLocation = function(location) {
            var check = mainService.switchLocation(location);
            if (check) {
                vm.currentLocation = mainService.switchLocation(location);
                removeAscii();
                if (location === 'treeShop') {
                    console.log('shop init')
                    initShop();
                }
            }
        };
        vm.switchLevel = function(level) {
            var check = mainService.switchLevel(level);
            if (check) {
                vm.currentLocation = mainService.switchLevel(level);
            }
        };
 
        vm.switchTemplate = function(template) {
            mainService.switchTemplate(template);
        };
 
        vm.buyItem = function(item) {
            shopService.initPurchase(item);
            vm.money = resourcesService.resources.money;
            $timeout(function() {
                vm.itemList = [shopService.shopList];
            }, 50);
        };
 
        vm.calculateTotlMoneyRate = function() {
            return resourcesService.calculateTotlMoneyRate();
        }
 
        vm.resetGame = function() {
            vm.reset = vm.reset.toUpperCase();
            if (vm.reset === 'RESET') {
                savingService.resetGame();
            }
            else {
                messageService.updateMainMessage('You must send "RESET" to delete your save!', true);
            }
        }
 
        function initShop() {
            shopService.initShop();
            vm.itemDictionary = shopService.grabItemDictionary();
            vm.itemList = [shopService.shopList];
            console.log(vm.itemList[0]);
        }
 
 
        //if ascii isnt deleted before, can cause issues with different size ascii
        function removeAscii() {
            var elements = angular.element('#locationwrap').children();
            elements.remove();
            sanitizeAscii();
        }
 
        //add pre tags and $compile to angular code so ng-click works
        function sanitizeAscii() {
            //dont run twice, adds double pre tags
            if (!vm.currentLocation.formatted) {
                vm.currentLocation.initClicks();
            }
            for (var i = 0; i < vm.currentLocation.ascii.length; i++) {
                if (!vm.currentLocation.formatted) {
                    vm.currentLocation.ascii[i] = '<pre>' + vm.currentLocation.ascii[i] + '</pre>';
                }
                vm.currentLocation.ascii[i] = $compile(vm.currentLocation.ascii[i])($scope);
            }
            vm.currentLocation.formatted = true;
            appendAscii();
            verifyAscii();
        }
 
        function appendAscii() {
            for (var i = 0; i < vm.currentLocation.ascii.length; i++) {
                angular.element('#locationwrap').append(vm.currentLocation.ascii[i]);
            }
            $timeout(verifyAscii, 10);
        }
 
        //ascii append check, if it didnt work lengths wont matchup, rerun append
        function verifyAscii() {
            var length = angular.element('#locationwrap').children().length;
            if (length !== vm.currentLocation.ascii.length) {
                appendAscii();
            }
        }
 
        function wizardCheck() {
            if (vm.currentLocation.slug === 'wizard') {
                var asciiCheck = vm.currentLocation.asciiCheck();
                if  (asciiCheck !== vm.currentLocation.currentAscii) {
                    vm.currentLocation.currentAscii = asciiCheck;
                    vm.currentLocation.ascii = vm.currentLocation[asciiCheck];
                    vm.currentLocation.formatted = false;
                    removeAscii();
                    sanitizeAscii();
                } 
            }
        }
 
        //all resource info here
        function increaseResources() {
            vm.money = resourcesService.moneyTick();
            vm.resources = resourcesService.resources;
        }
 
        function updatePlayer() {
            vm.player.damage = vm.player.calculateTotalDamage();
            vm.player.armorValue = vm.player.calculateTotalArmor();
            vm.player.maxHealth = vm.player.calculateTotalHealth();
        }
 
        function lichCheck() {
            if (vm.player.lichKilled) {
                vm.player.lichKilled = false;
                vm.switchLocation('ending');
            }
        }
        function saveCheck() {
            if (vm.count % 15 === 0) {
                savingService.saveGame();
            }
        }
        //1s loop
        function mainLoop() {
            vm.count = vm.count + 1;
            vm.player.healthRegen();
            increaseResources();
            updatePlayer();
            lichCheck();
            saveCheck();
            $timeout(mainLoop, 1000);
        }
        //quicker loop
        function quickLoop() {
            vm.player.healthBarUpdate();
            vm.activeTemplate = templateService.activeTemplate;
            vm.messageError = messageService.messageError;
            vm.mainMessage = messageService.mainMessage;
            wizardCheck();
            $timeout(quickLoop, 125);
        }
 
        ////////////////////
 
        function activate() {
            sanitizeAscii();
            mainLoop();
            quickLoop();
        }
 
        activate();
    }
})();