1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-06 18:27:20 -05:00
OpenDiablo2/Common/LevelPresets.go

90 lines
2.3 KiB
Go
Raw Normal View History

package Common
import (
"log"
"strings"
"github.com/OpenDiablo2/OpenDiablo2/ResourcePaths"
)
type LevelPresetRecord struct {
Name string
DefinitionId int
LevelId int
Populate bool
Logicals bool
Outdoors bool
Animate bool
KillEdge bool
FillBlanks bool
SizeX int
SizeY int
AutoMap bool
Scan bool
Pops int
PopPad int
FileCount int
Files [6]string
Dt1Mask uint
Beta bool
Expansion bool
}
// CreateLevelPresetRecord parses a row from lvlprest.txt into a LevelPresetRecord
func createLevelPresetRecord(props []string) LevelPresetRecord {
i := -1
inc := func() int {
i++
return i
}
result := LevelPresetRecord{
Name: props[inc()],
DefinitionId: StringToInt(props[inc()]),
LevelId: StringToInt(props[inc()]),
Populate: StringToUint8(props[inc()]) == 1,
Logicals: StringToUint8(props[inc()]) == 1,
Outdoors: StringToUint8(props[inc()]) == 1,
Animate: StringToUint8(props[inc()]) == 1,
KillEdge: StringToUint8(props[inc()]) == 1,
FillBlanks: StringToUint8(props[inc()]) == 1,
SizeX: StringToInt(props[inc()]),
SizeY: StringToInt(props[inc()]),
AutoMap: StringToUint8(props[inc()]) == 1,
Scan: StringToUint8(props[inc()]) == 1,
Pops: StringToInt(props[inc()]),
PopPad: StringToInt(props[inc()]),
FileCount: StringToInt(props[inc()]),
Files: [6]string{
props[inc()],
props[inc()],
props[inc()],
props[inc()],
props[inc()],
props[inc()],
},
Dt1Mask: StringToUint(props[inc()]),
Beta: StringToUint8(props[inc()]) == 1,
Expansion: StringToUint8(props[inc()]) == 1,
}
return result
}
2019-11-01 16:51:50 -04:00
var LevelPresets map[int]*LevelPresetRecord
func LoadLevelPresets(fileProvider FileProvider) {
2019-11-01 16:51:50 -04:00
LevelPresets = make(map[int]*LevelPresetRecord)
data := strings.Split(string(fileProvider.LoadFile(ResourcePaths.LevelPreset)), "\r\n")[1:]
for _, line := range data {
if len(line) == 0 {
continue
}
props := strings.Split(line, "\t")
if props[1] == "" {
continue // any line without a definition id is skipped (e.g. the "Expansion" line)
}
rec := createLevelPresetRecord(props)
LevelPresets[rec.DefinitionId] = &rec
}
log.Printf("Loaded %d level presets", len(LevelPresets))
}