2019-11-06 22:12:15 -05:00
|
|
|
package common
|
2019-10-28 17:51:17 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
|
2019-11-06 22:12:15 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/resourcepaths"
|
2019-10-28 17:51:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type LevelPresetRecord struct {
|
2019-11-05 20:46:52 -05:00
|
|
|
Name string
|
2019-11-03 22:03:22 -05:00
|
|
|
DefinitionId int
|
|
|
|
LevelId int
|
2019-10-28 17:51:17 -04:00
|
|
|
Populate bool
|
|
|
|
Logicals bool
|
|
|
|
Outdoors bool
|
|
|
|
Animate bool
|
|
|
|
KillEdge bool
|
|
|
|
FillBlanks bool
|
2019-11-03 22:03:22 -05:00
|
|
|
SizeX int
|
|
|
|
SizeY int
|
2019-10-28 17:51:17 -04:00
|
|
|
AutoMap bool
|
|
|
|
Scan bool
|
2019-11-03 22:03:22 -05:00
|
|
|
Pops int
|
|
|
|
PopPad int
|
|
|
|
FileCount int
|
2019-10-28 17:51:17 -04:00
|
|
|
Files [6]string
|
2019-11-03 22:03:22 -05:00
|
|
|
Dt1Mask uint
|
2019-11-05 20:46:52 -05:00
|
|
|
Beta bool
|
2019-11-03 22:03:22 -05:00
|
|
|
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{
|
2019-11-05 20:46:52 -05:00
|
|
|
Name: props[inc()],
|
2019-11-03 22:03:22 -05:00
|
|
|
DefinitionId: StringToInt(props[inc()]),
|
2019-11-05 20:46:52 -05:00
|
|
|
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()]),
|
2019-11-03 22:03:22 -05:00
|
|
|
Files: [6]string{
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
props[inc()],
|
|
|
|
},
|
2019-11-05 20:46:52 -05:00
|
|
|
Dt1Mask: StringToUint(props[inc()]),
|
|
|
|
Beta: StringToUint8(props[inc()]) == 1,
|
2019-11-03 22:03:22 -05:00
|
|
|
Expansion: StringToUint8(props[inc()]) == 1,
|
|
|
|
}
|
|
|
|
return result
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
|
|
|
|
2019-11-01 16:51:50 -04:00
|
|
|
var LevelPresets map[int]*LevelPresetRecord
|
2019-10-28 17:51:17 -04:00
|
|
|
|
|
|
|
func LoadLevelPresets(fileProvider FileProvider) {
|
2019-11-01 16:51:50 -04:00
|
|
|
LevelPresets = make(map[int]*LevelPresetRecord)
|
2019-11-06 22:12:15 -05:00
|
|
|
data := strings.Split(string(fileProvider.LoadFile(resourcepaths.LevelPreset)), "\r\n")[1:]
|
2019-11-03 22:03:22 -05:00
|
|
|
for _, line := range data {
|
|
|
|
if len(line) == 0 {
|
|
|
|
continue
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
2019-11-03 22:03:22 -05:00
|
|
|
props := strings.Split(line, "\t")
|
2019-11-05 20:46:52 -05:00
|
|
|
if props[1] == "" {
|
2019-11-03 22:03:22 -05:00
|
|
|
continue // any line without a definition id is skipped (e.g. the "Expansion" line)
|
|
|
|
}
|
|
|
|
rec := createLevelPresetRecord(props)
|
|
|
|
LevelPresets[rec.DefinitionId] = &rec
|
2019-10-28 17:51:17 -04:00
|
|
|
}
|
2019-11-03 22:03:22 -05:00
|
|
|
log.Printf("Loaded %d level presets", len(LevelPresets))
|
2019-11-05 20:46:52 -05:00
|
|
|
}
|