Passed
Push — depfu/update/npm/lodash-4.17.1... ( 152c97 )
by
unknown
04:58
created

src/app/screens/player-pokedex/player-pokedex.component.ts   A

Complexity

Total Complexity 16
Complexity/F 1.6

Size

Lines of Code 109
Function Count 10

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 75
dl 0
loc 109
rs 10
c 0
b 0
f 0
wmc 16
mnd 6
bc 6
fnc 10
bpm 0.6
cpm 1.6
noi 0

10 Functions

Rating   Name   Duplication   Size   Complexity  
A PlayerPokedexComponent.toggleAllSeen 0 8 2
A PlayerPokedexComponent.getOwn 0 3 1
A PlayerPokedexComponent.toggleSeen 0 3 1
A PlayerPokedexComponent.setSeen 0 3 1
A PlayerPokedexComponent.ngOnInit 0 8 2
A PlayerPokedexComponent.toggleOwn 0 3 1
A PlayerPokedexComponent.setOwn 0 3 1
A PlayerPokedexComponent.toggleAllOwn 0 8 2
A PlayerPokedexComponent.getSeen 0 3 1
A PlayerPokedexComponent.nameFilter 0 9 4
1
import { Pokemon } from './../../../assets/data/pokemon.d';
2
import { GameDataService } from './../../data/gameData.service';
3
/**
4
   Copyright 2018 June Hanabi
5
6
   Licensed under the Apache License, Version 2.0 (the "License");
7
   you may not use this file except in compliance with the License.
8
   You may obtain a copy of the License at
9
10
       http://www.apache.org/licenses/LICENSE-2.0
11
12
   Unless required by applicable law or agreed to in writing, software
13
   distributed under the License is distributed on an "AS IS" BASIS,
14
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
   See the License for the specific language governing permissions and
16
   limitations under the License.
17
 */
18
19
import { Component, OnInit } from '@angular/core';
20
import { SaveFileService } from "../../data/savefile.service";
21
22
declare var window: {
23
    require: any;
24
};
25
26
const _ = window.require("lodash");
27
28
@Component({
29
    selector: 'screen-pokedex',
30
    templateUrl: './player-pokedex.component.pug',
31
    styleUrls: ['./player-pokedex.component.scss'],
32
})
33
export class PlayerPokedexComponent implements OnInit {
34
35
    constructor(
36
        public fileService: SaveFileService,
37
        public gd: GameDataService
38
    ) { }
39
40
    ngOnInit() {
41
        this.gd.file("pokemon").data.forEach((el: Pokemon) => {
42
            if (!isNaN(el.pokedex as number))
43
                this.pokedexPokemon.push(el);
44
        });
45
46
        this.pokedexPokemon = _.sortBy(this.pokedexPokemon, ["pokedex"]);
47
    }
48
49
    get entries() {
50
        return this.pokedexPokemon;
51
    }
52
53
    nameFilter(name: string) {
54
        if(name == "Nidoran<f>")
55
            return "Nidoran F";
56
        else if(name == "Nidoran<m>")
57
            return "Nidoran M";
58
        else if(name == "Mr.Mime")
59
            return "Mr. Mime";
60
        else return name;
61
    }
62
63
    getSeen(index: number): boolean {
64
        return this.fileService.fileDataExpanded.player.pokedex.pokedexSeen[index];
65
    }
66
67
    setSeen(index: number, value: boolean) {
68
        this.fileService.fileDataExpanded.player.pokedex.pokedexSeen[index] = value;
69
    }
70
71
    toggleSeen(index: number) {
72
        this.setSeen(index, !this.getSeen(index));
73
    }
74
75
    getOwn(index: number): boolean {
76
        return this.fileService.fileDataExpanded.player.pokedex.pokedexOwned[index];
77
    }
78
79
    setOwn(index: number, value: boolean) {
80
        this.fileService.fileDataExpanded.player.pokedex.pokedexOwned[index] = value;
81
    }
82
83
    toggleOwn(index: number) {
84
        this.setOwn(index, !this.getOwn(index));
85
    }
86
87
    toggleAllSeen() {
88
        const item0 = this.getSeen(0);
89
90
        const count = this.gd.file("pokemon").data.length;
91
92
        for (let i = 0; i < count; i++) {
93
            this.setSeen(i, !item0);
94
        }
95
    }
96
97
    toggleAllOwn() {
98
        const item0 = this.getOwn(0);
99
100
        const count = this.gd.file("pokemon").data.length;
101
102
        for (let i = 0; i < count; i++) {
103
            this.setOwn(i, !item0);
104
        }
105
    }
106
107
    public pokedexPokemon: Pokemon[] = [];
108
}
109