2019-10-28 17:51:17 -04:00
|
|
|
package Common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2019-11-02 17:38:39 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/ResourcePaths"
|
2019-10-28 17:51:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type LevelTypeRecord struct {
|
2019-11-04 17:39:59 -05:00
|
|
|
Name string
|
|
|
|
Id int
|
|
|
|
Files [32]string
|
|
|
|
Beta bool
|
|
|
|
Act int
|
|
|
|
Expansion bool
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var LevelTypes []LevelTypeRecord
|
|
|
|
|
|
|
|
func LoadLevelTypes(fileProvider FileProvider) {
|
2019-11-04 17:39:59 -05:00
|
|
|
data := strings.Split(string(fileProvider.LoadFile(ResourcePaths.LevelType)), "\r\n")[1:]
|
|
|
|
LevelTypes = make([]LevelTypeRecord, len(data))
|
|
|
|
for i, line := range data {
|
|
|
|
idx := -1
|
|
|
|
inc := func() int {
|
|
|
|
idx++
|
|
|
|
return idx
|
|
|
|
}
|
|
|
|
if len(line) == 0 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
parts := strings.Split(line, "\t")
|
|
|
|
if parts[0] == "Expansion" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
LevelTypes[i].Name = parts[inc()]
|
|
|
|
LevelTypes[i].Id = StringToInt(parts[inc()])
|
|
|
|
for fileIdx := range LevelTypes[i].Files {
|
|
|
|
LevelTypes[i].Files[fileIdx] = parts[inc()]
|
|
|
|
if LevelTypes[i].Files[fileIdx] == "0" {
|
2019-10-28 17:51:17 -04:00
|
|
|
LevelTypes[i].Files[fileIdx] = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-11-04 17:39:59 -05:00
|
|
|
LevelTypes[i].Beta = parts[inc()] != "1"
|
|
|
|
LevelTypes[i].Act = StringToInt(parts[inc()])
|
|
|
|
LevelTypes[i].Expansion = parts[inc()] != "1"
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
2019-11-04 17:39:59 -05:00
|
|
|
log.Printf("Loaded %d LevelType records", len(LevelTypes))
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|