Code coverage report for ./src/client/app/resources/resources.service.js

Statements: 17.65% (6 / 34)      Branches: 0% (0 / 4)      Functions: 12.5% (1 / 8)      Lines: 17.65% (6 / 34)      Ignored: none     

All files » ./src/client/app/resources/ » resources.service.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 651     1       1   1                                                     1                                             1          
(function() {
    'use strict';
 
    angular
        .module('app.resources')
        .service('resourcesService', resourcesService);
 
    resourcesService.$inject = ['messageService', 'inventoryService', 'progressService'];
 
    function resourcesService(messageService, inventoryService, progressService) {
    	var vm = this;
        vm.itemDictionary = inventoryService.itemDictionary;
        vm.progress = progressService.progress;
 
        vm.canBuyMilk = function() {
            if (vm.resources.money > vm.resources.milkPrice) {
                return true;
            }
            else {
                return false;
            }
        };
 
        vm.raiseMilkPrice = function() {
            var price = vm.resources.milkPrice;
            price = price + price/2;
            price = Math.floor(price);
            vm.resources.milkPrice = price;
        };
 
    	vm.defaultResources = {
    		money: 0,
    		moneyRate: 1,
            milkPrice: 500
        };
 
        function loadResources() {
            var resources;
            if (localStorage['resourcesSave']) {
                resources = JSON.parse(atob(localStorage['resourcesSave']));
            }
            else {
                resources = vm.defaultResources;
            }
            console.log(resources);
            return resources;
        }
        vm.resources = loadResources();
 
        vm.calculateTotlMoneyRate = function() {
            var rate = totalMoneyRate();
            return rate;
        };  
 
        vm.moneyTick = function() {
            vm.resources.money = vm.resources.money + vm.calculateTotlMoneyRate();
            return vm.resources.money;
        };
 
        function totalMoneyRate() {
            var moneyRate = 1 + inventoryService.stats.money;
            return moneyRate;
        }
    }
})();