Completed
Push — master ( 1b4532...54964d )
by Andres
01:14
created

options.js ➔ options   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 31
rs 8.8571
nop 4

2 Functions

Rating   Name   Duplication   Size   Complexity  
A options.js ➔ ... ➔ ct.importExportSave 0 14 3
A options.js ➔ ... ➔ ct.reset 0 11 3
1
'use strict';
2
3
angular.module('game').component('options', {
4
  templateUrl: 'views/options.html',
5
  controller: ['$timeout', '$state', 'state', 'savegame', options],
6
  controllerAs: 'ct'
7
});
8
9
function options($timeout, $state, state, savegame) {
10
  let ct = this;
11
  ct.state = state;
12
13
  ct.reset = function (ask) {
14
    let confirmation = true;
15
    if (ask) {
16
      confirmation = confirm('Are you sure you want to reset? This will permanently erase your progress.');
17
    }
18
19
    if (confirmation === true) {
20
      localStorage.removeItem('playerStoredITE');
21
      savegame.initSave();
22
    }
23
  };
24
25
  ct.importExportSave = function () {
26
    if (state.export) {
27
      try {
28
        state.player = JSON.parse(atob(state.export));
29
        savegame.versionControl();
30
      } catch (error) {
31
        alert('Invalid save file.');
32
      }
33
    } else {
34
      let exportText = btoa(JSON.stringify(state.player));
35
36
      state.export = exportText;
37
    }
38
  };
39
}
40