mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-10 13:34:36 -04:00
* refactored logging in d2config, d2record, and d2asset * asset manager, record manager, and file loader now utilitize d2util.Logger * added colored logging to d2util.Logger (excluding windows platforms) * removed mpq file verification from d2config; d2loader handles this * record loaders now use the record manager's logger for printing info * added command line argument for setting log level (`--loglevel 4`, `-l4`, or `-l 4` * added `LogLevel` parameter to config file * default log level will show errors, warnings, and info log messages * specifying log level as an argument overrides setting from config file * fixed log level tests
96 lines
2.3 KiB
Go
96 lines
2.3 KiB
Go
package d2records
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2fileformats/d2txt"
|
|
)
|
|
|
|
const (
|
|
numRunewordTypeInclude = 6
|
|
numRunewordTypeExclude = 3
|
|
numRunewordMaxSockets = 6
|
|
numRunewordProperties = 7
|
|
)
|
|
|
|
// format strings
|
|
const (
|
|
fmtTypeInclude = "itype%d"
|
|
fmtTypeExclude = "etype%d"
|
|
fmtRuneStr = "Rune%d"
|
|
fmtRunewordPropCode = "T1Code%d"
|
|
fmtRunewordPropParam = "T1Param%d"
|
|
fmtRunewordPropMin = "T1Min%d"
|
|
fmtRunewordPropMax = "T1Max%d"
|
|
)
|
|
|
|
// Loadrecords loads runes records into a map[string]*RunesRecord
|
|
func runewordLoader(r *RecordManager, d *d2txt.DataDictionary) error {
|
|
records := make(map[string]*RunesRecord)
|
|
|
|
for d.Next() {
|
|
record := &RunesRecord{
|
|
Name: d.String("name"),
|
|
RuneName: d.String("Rune Name"),
|
|
Complete: d.Bool("complete"),
|
|
Server: d.Bool("server"),
|
|
ItemTypes: struct {
|
|
Include []string
|
|
Exclude []string
|
|
}{
|
|
Include: make([]string, 0),
|
|
Exclude: make([]string, 0),
|
|
},
|
|
Runes: make([]string, 0),
|
|
Properties: make([]*RunewordProperty, 0),
|
|
}
|
|
|
|
for idx := 0; idx < numRunewordTypeInclude; idx++ {
|
|
column := fmt.Sprintf(fmtTypeInclude, idx+1)
|
|
if code := d.String(column); code != "" {
|
|
record.ItemTypes.Include = append(record.ItemTypes.Include, code)
|
|
}
|
|
}
|
|
|
|
for idx := 0; idx < numRunewordTypeExclude; idx++ {
|
|
column := fmt.Sprintf(fmtTypeExclude, idx+1)
|
|
if code := d.String(column); code != "" {
|
|
record.ItemTypes.Exclude = append(record.ItemTypes.Exclude, code)
|
|
}
|
|
}
|
|
|
|
for idx := 0; idx < numRunewordMaxSockets; idx++ {
|
|
column := fmt.Sprintf(fmtRuneStr, idx+1)
|
|
if code := d.String(column); code != "" {
|
|
record.Runes = append(record.Runes, code)
|
|
}
|
|
}
|
|
|
|
for idx := 0; idx < numRunewordProperties; idx++ {
|
|
codeColumn := fmt.Sprintf(fmtRunewordPropCode, idx+1)
|
|
if code := codeColumn; code != "" {
|
|
prop := &RunewordProperty{
|
|
code,
|
|
d.String(fmt.Sprintf(fmtRunewordPropParam, idx+1)),
|
|
d.Number(fmt.Sprintf(fmtRunewordPropMin, idx+1)),
|
|
d.Number(fmt.Sprintf(fmtRunewordPropMax, idx+1)),
|
|
}
|
|
|
|
record.Properties = append(record.Properties, prop)
|
|
}
|
|
}
|
|
|
|
records[record.Name] = record
|
|
}
|
|
|
|
if d.Err != nil {
|
|
return d.Err
|
|
}
|
|
|
|
r.Item.Runewords = records
|
|
|
|
r.Logger.Infof("Loaded %d records records", len(records))
|
|
|
|
return nil
|
|
}
|