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

Statements: 20% (5 / 25)      Branches: 100% (0 / 0)      Functions: 20% (1 / 5)      Lines: 20% (5 / 25)      Ignored: none     

All files » ./src/client/app/saving/ » saving.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 411     1       1     1             1                                              
(function() {
    'use strict';
 
    angular
        .module('app.saving')
        .service('savingService', savingService);
 
    savingService.$inject = ['progressService', 'playerService', 'inventoryService', 'resourcesService', '$window'];
 
    /* @ngInject */
    function savingService(progressService, playerService, inventoryService, resourcesService, $window) {
        var vm = this;
        vm.player = playerService.player;
        vm.progress = progressService.progress;        
        vm.resources = resourcesService.resources
        vm.itemDictionary = inventoryService.itemDictionary;
 
        function saveItems() {
            var keys = inventoryService.keys;
            var items = [];
            for (var i = 0; i < keys.length; i++) {
                var val = [keys[i], vm.itemDictionary[keys[i]][1][1]];
                items.push(val);
            }
            return items;
        }
 
        vm.saveGame = function() {
            console.log('saving...');
            localStorage['playerSave'] = btoa(JSON.stringify(vm.player));
            localStorage['progressSave'] = btoa(JSON.stringify(vm.progress));
            localStorage['resourcesSave'] = btoa(JSON.stringify(vm.resources));
            localStorage['itemSave'] = btoa(JSON.stringify(saveItems()));
        };
 
        vm.resetGame = function() {
            localStorage.clear();
            document.location.reload();
        }
    }
})();