Skip to content

Commit

Permalink
add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dingdongg committed May 28, 2024
1 parent 14388df commit fb83a05
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions parser.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
package parser

import (
"fmt"
"errors"

"github.com/dingdongg/pkmn-rom-parser/v2/rom_reader"
"github.com/dingdongg/pkmn-rom-parser/v2/validator"
)

const PERSONALITY_OFFSET = 0xA0

func Parse(savefile []byte) []rom_reader.Pokemon {
func Parse(savefile []byte) ([]rom_reader.Pokemon, error) {
valid := validator.Validate(savefile)
var res []rom_reader.Pokemon

if valid {
fmt.Println("SAVEFILE IS VALID")
if !valid {
return res, errors.New("invalid file")
}

// TODO: only read from/edit the most recent savefiel
var res []rom_reader.Pokemon

for i := uint(0); i < 6; i++ {
res = append(res, rom_reader.GetPokemon(savefile[PERSONALITY_OFFSET:], i))
}

return res
return res, nil
}

0 comments on commit fb83a05

Please sign in to comment.