1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-10-31 08:17:21 -04:00
OpenDiablo2/Common/LevelPresets.go
ndechiara 07b0724575 Fix MPQ load, add Missiles.txt load, switch LvlPrest.bin to LvlPrest.txt, fix sound loading (#80)
* fix mpqs, add missiles.txt, fix lvlprest
* fix sound loading issue
2019-11-03 22:03:22 -05:00

89 lines
2.2 KiB
Go

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
}
var LevelPresets map[int]*LevelPresetRecord
func LoadLevelPresets(fileProvider FileProvider) {
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))
}