Passed
Pull Request — master (#22)
by
unknown
08:10 queued 04:20
created

src/app/fragments/select-map-width/select-map-width.component.ts   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 122
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 89
dl 0
loc 122
rs 10
c 0
b 0
f 0
wmc 5
mnd 3
bc 3
fnc 2
bpm 1.5
cpm 2.5
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A SelectMapWidthComponent.ngOnInit 0 2 1
A SelectMapWidthComponent.trackByFn 0 3 4
1
import { Map } from './../../../assets/data/maps.d';
2
import { ValueAccessorBase } from './../abstract/ValueAccessorBase';
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
declare var window: {
20
    require: any;
21
}
22
23
import { Component, OnInit, Input } from '@angular/core';
24
import { GameDataService } from './../../data/gameData.service';
25
26
import {
27
    NG_VALUE_ACCESSOR,
28
} from '@angular/forms';
29
30
const _: any = window.require("lodash");
31
32
@Component({
33
    selector: 'select-map-width',
34
    templateUrl: './select-map-width.component.pug',
35
    styleUrls: ['./select-map-width.component.scss'],
36
    providers: [
37
        { provide: NG_VALUE_ACCESSOR, useExisting: SelectMapWidthComponent, multi: true }
38
    ],
39
})
40
export class SelectMapWidthComponent extends ValueAccessorBase<string> implements OnInit {
41
42
    constructor(
43
        public gd: GameDataService
44
    ) {
45
        super();
46
    }
47
48
    ngOnInit() {
49
50
    }
51
52
    @Input()
53
    public disabled: boolean = false;
54
55
    @Input()
56
    public noneSelectable: boolean = false;
57
58
    @Input()
59
    public label: string = "Select Map";
60
61
    get mapList() {
62
63
        const maps: Map[] = this.gd.file("maps").data;
64
65
        const b = (val: number | any) => {
66
            return val.toString(16).padStart(2, "0").toUpperCase();
67
        }
68
69
        const a = (val: number | any) => {
70
            return val.toString().padStart(2, "0");
71
        }
72
73
        let _maps: {
74
            name: string,
75
            glitch: boolean | undefined,
76
            special: boolean | undefined,
77
            value: string
78
        }[] = [];
79
80
        maps.forEach((el: Map) => {
81
            if (el.special === true)
82
                return;
83
84
            _maps.push({
85
                name: el.name,
86
                glitch: el.glitch,
87
                special: el.special,
88
                value: `${b(el.ind)}_${a(el.width)}`,
89
            });
90
        });
91
92
        let mapListNormal: Map[] = _.filter(_maps, (value: Map) => {
93
            if (!value.glitch && !value.special)
94
                return true;
95
96
            return false;
97
        });
98
99
        mapListNormal = _.sortBy(mapListNormal, ['name']);
100
101
        let mapListGlitch: Map[] = _.filter(_maps, (value: Map) => {
102
            if (value.glitch && !value.special)
103
                return true;
104
105
            return false;
106
        });
107
108
        mapListGlitch = _.sortBy(mapListGlitch, ['name']);
109
110
        return [
111
            { name: "--- Normal Maps ---", ind: 0x100, disable: true },
112
            ...mapListNormal,
113
            { name: "--- Glitch Maps ---", ind: 0x100, disable: true },
114
            ...mapListGlitch
115
        ];
116
    }
117
118
    trackByFn(index: number) {
119
        return index;
120
    }
121
}
122