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

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

Complexity

Total Complexity 3
Complexity/F 1.5

Size

Lines of Code 49
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 49
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 HoFPokemon.load 0 17 2
A HoFPokemon.save 0 7 1
1
import { SaveFileService } from '../../savefile.service';
2
3
export class HoFPokemon {
4
    constructor(saveFile?: SaveFileService, recordOffset?: number, index?: number) {
5
        if (saveFile !== undefined)
6
            this.load(
7
                saveFile as SaveFileService,
8
                recordOffset as number,
9
                index as number
10
            );
11
    }
12
13
    public load(saveFile: SaveFileService, recordOffset: number, index: number) {
14
15
        // Calculate Pokemon Offset in the record
16
        // Records are 0x10 in size
17
        // Multiply record number with 0x10 (Record Size) and add to offset
18
        // record start
19
        const pokemonOffset = (0x10 * index) + recordOffset;
20
21
        /**
22
         * Record Data
23
         */
24
25
        // Extract Pokemon Data
26
        this.species = saveFile.getByte(pokemonOffset + 0);
27
        this.level = saveFile.getByte(pokemonOffset + 1);
28
        this.name = saveFile.getStr(pokemonOffset + 2, 0xB, 10);
29
    }
30
31
    public save(saveFile: SaveFileService, recordOffset: number, index: number) {
32
        const pokemonOffset = (0x10 * index) + recordOffset;
33
34
        saveFile.setByte(pokemonOffset + 0, this.species);
35
        saveFile.setByte(pokemonOffset + 1, this.level);
36
        saveFile.setStr(pokemonOffset + 2, 0xB, 10, this.name);
37
38
        // Normally the Gameboy will actively zero out padding bytes
39
        // but we don't set padding bytes per the strict "Only touch whats needed" rule
40
    }
41
42
    /**
43
     * Record Data
44
     */
45
    public species: number = 0;
46
    public level: number = 0;
47
    public name: string = "";
48
}
49