2016-02-06 01:48:29 +01:00
|
|
|
package data // code.bitsetter.de/fun/gosl/data
|
|
|
|
|
2016-02-07 00:16:30 +01:00
|
|
|
import (
|
|
|
|
"encoding/gob"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type directionType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
DIR_NULL directionType = iota // Undefined direction: NO Motion
|
|
|
|
DIR_SW //
|
|
|
|
DIR_S // NW N NE
|
|
|
|
DIR_SE // 7 8 9
|
|
|
|
DIR_W // W 4 5 6 E
|
|
|
|
DIR_NONE // 1 2 3
|
|
|
|
DIR_E // SW S SE
|
|
|
|
DIR_NW
|
|
|
|
DIR_N
|
|
|
|
DIR_NE
|
|
|
|
)
|
|
|
|
|
|
|
|
type Direction interface {
|
|
|
|
Base() directionType
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i directionType) Base() directionType { return i }
|
|
|
|
|
2016-02-06 01:48:29 +01:00
|
|
|
type Layer struct {
|
2016-02-07 00:16:30 +01:00
|
|
|
Z int `json:"Z-Index"`
|
|
|
|
D directionType `json:"Direction"`
|
|
|
|
S int `json:"Speed"`
|
|
|
|
T string `json:"Transparent"`
|
|
|
|
Repeat bool
|
|
|
|
Frames map[int]([][]rune)
|
2016-02-06 01:48:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type Level struct {
|
2016-02-07 00:16:30 +01:00
|
|
|
Name string
|
|
|
|
FPS int
|
|
|
|
Layers map[string]*Layer
|
2016-02-06 01:48:29 +01:00
|
|
|
}
|
|
|
|
|
2016-02-07 00:16:30 +01:00
|
|
|
//func (lvl *Level) AddLayer(z int, l *Layer) {
|
|
|
|
// lvl.Layers[z] = l
|
|
|
|
//}
|
2016-02-06 13:26:01 +01:00
|
|
|
|
2016-02-06 14:42:38 +01:00
|
|
|
func LoadLevel(filename string) *Level {
|
2016-02-07 00:16:30 +01:00
|
|
|
log.Println("Loading lvl ", filename)
|
|
|
|
ret := &Level{}
|
|
|
|
file, err := os.Open(filename)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Error reading lvl: ", err)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dec := gob.NewDecoder(file)
|
|
|
|
dec.Decode(ret)
|
|
|
|
//log.Println(ret.Layers["locomotive"])
|
|
|
|
return ret
|
2016-02-06 14:42:38 +01:00
|
|
|
}
|