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

src/scripts/component/options.js   A

Complexity

Total Complexity 7
Complexity/F 2.33

Size

Lines of Code 39
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 7
c 1
b 0
f 0
nc 1
mnd 2
bc 9
fnc 3
dl 0
loc 39
rs 10
bpm 3
cpm 2.3333
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B options.js ➔ options 0 31 1
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