Passed
Push — depfu/update/npm/lodash-4.17.1... ( c1263d )
by
unknown
04:21
created

src/app/data/savefile-expanded/fragments/MapConnData.ts   A

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 53
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 3
mnd 1
bc 1
fnc 2
bpm 0.5
cpm 1.5
noi 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A MapConnData.load 0 14 2
A MapConnData.save 0 13 1
1
import { SaveFileService } from './../../savefile.service';
2
3
export class MapConnData {
4
    constructor(saveFile?: SaveFileService, offset?: number) {
5
        if (saveFile !== undefined)
6
            this.load(saveFile as SaveFileService, offset as number);
7
    }
8
9
    public load(saveFile: SaveFileService, offset: number) {
10
        const it = saveFile.iterator.offsetTo(offset);
11
12
        const mapPtr = it.getByte();
13
        this.stripSrc = it.getWord();
14
        this.stripDest = it.getWord();
15
        this.stripWidth = it.getByte();
16
        const width = it.getByte();
17
        this.yAlign = it.getByte();
18
        this.xAlign = it.getByte();
19
        this.viewPtr = it.getWord(0, true);
20
21
        this.map = `${mapPtr.toString(16).padStart(2, "0").toUpperCase()}_${width}`;
22
    }
23
24
    public save(saveFile: SaveFileService, offset: number) {
25
        const it = saveFile.iterator.offsetTo(offset);
26
        const map = this.map.split("_");
27
28
        it.setByte(parseInt(map[0], 16));
29
        it.setWord(this.stripSrc);
30
        it.setWord(this.stripDest);
31
        it.setByte(this.stripWidth);
32
        it.setByte(parseInt(map[1]));
33
        it.setByte(this.yAlign);
34
        it.setByte(this.xAlign);
35
        it.setWord(this.viewPtr, 0, true);
36
    }
37
38
    // Connected Map
39
    public map: string = "";
40
41
    // Pointer to upper left corner of map without adjustment for X position
42
    public viewPtr: number = 0;
43
44
    // Strip
45
    public stripSrc: number = 0;
46
    public stripDest: number = 0;
47
    public stripWidth: number = 0;
48
49
    // Strip Alignment
50
    public yAlign: number = 0;
51
    public xAlign: number = 0;
52
}
53