Skip to content

Commit

Permalink
DBC reader rework.
Browse files Browse the repository at this point in the history
 The DBC files can be readed into structs directly with the new dbc.Reader
 - You can tag the struct fields with dbc tag to instruct the reader
 - The new DBC reader can read string, localized string fields too
  • Loading branch information
paalgyula committed May 31, 2023
1 parent 5bece02 commit 67a3102
Show file tree
Hide file tree
Showing 8 changed files with 449 additions and 85 deletions.
85 changes: 0 additions & 85 deletions pkg/summit/tools/datagen.go

This file was deleted.

50 changes: 50 additions & 0 deletions pkg/summit/tools/dbc/datagen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package dbc

import (
"fmt"
"os"
"path"

"github.com/paalgyula/summit/pkg/summit/tools/dbc/wotlk"
)

func LoadMaps(dbcDirectoryPath string) ([]wotlk.MapEntry, error) {
filename := "Map.dbc"
f, err := os.Open(path.Join(filename))
if err != nil {
panic(err)
}

r, err := NewReader[wotlk.MapEntry](f)
if err != nil {
return nil, err
}
if err := r.ReadAll(); err != nil {
return nil, err
}

fmt.Println(r.Records[0].MapName.Value())

// fmt.Println(string(r.Strings()))
return r.Records, nil
}

func LoadCharacter(dbcDirectoryPath string) ([]wotlk.CharStartOutfitEntry, error) {
filename := "CharStartOutfit.dbc"
f, err := os.Open(path.Join(dbcDirectoryPath, filename))
if err != nil {
return nil, fmt.Errorf("cannot load CharStartOutfit.dbc: %w", err)
}

r, err := NewReader[wotlk.CharStartOutfitEntry](f)
if err != nil {
return nil, err
}
if err := r.ReadAll(); err != nil {
return nil, err
}

fmt.Println("Loaded", len(r.Records), "records")

return r.Records, nil
}
37 changes: 37 additions & 0 deletions pkg/summit/tools/dbc/datagen_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dbc

import (
"fmt"
"os"
"testing"

"github.com/paalgyula/summit/pkg/summit/tools/dbc/wotlk"
"github.com/stretchr/testify/assert"
)

func TestGenerate(t *testing.T) {
// LoadCharacterRaces()
// LoadClassInfo()

f, err := os.Open("../../../../dbc/ChrClasses.dbc")
assert.NoError(t, err)

dr, err := NewReader[wotlk.ChrClassesEntry](f)
assert.NoError(t, err)
assert.EqualValues(t, 0xa, dr.Header.RecordCount)

dr.ReadAll()

fmt.Println(dr.Records[1].Name.Value())

// fmt.Printf("%+v\n\n", dr.Header)
}

func TestLoadMap(t *testing.T) {
LoadMaps("../../../../dbc")
}

func TestLoadCharacters(t *testing.T) {
_, err := LoadCharacter("../../../../dbc")
assert.NoError(t, err)
}
Loading

0 comments on commit 67a3102

Please sign in to comment.