export Layer structs to data

This commit is contained in:
tkarrass 2016-02-07 00:16:30 +01:00
parent f29cb4f8db
commit 8ff339f700
4 changed files with 56 additions and 45 deletions

2
.gitignore vendored
View File

@ -29,4 +29,6 @@ _testmain.go
*.pem
*.crt
*.lvl
/gosl

View File

@ -12,44 +12,10 @@ import (
"path"
"strconv"
"strings"
"code.bitsetter.de/fun/gosl/data"
)
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 }
type LayerManifest struct {
Z int `json:"Z-Index"`
D directionType `json:"Direction"`
S int `json:"Speed"`
T string `json:"Transparent"`
Repeat bool
Frames map[int]([][]rune)
}
type LevelManifest struct {
Name string
FPS int
Layers map[string]*LayerManifest
}
var (
levelDir string
levelFile string
@ -79,7 +45,7 @@ func compile(cmd *cobra.Command, args []string) {
}
log.Println("will compile to", levelFile)
lvlMan := &LevelManifest{}
lvlMan := &data.Level{}
buf, err := ioutil.ReadFile(levelDir + "/Manifest.json")
if err != nil {
log.Fatal("Error reading file: ", err)
@ -125,6 +91,7 @@ func compile(cmd *cobra.Command, args []string) {
enc := gob.NewEncoder(obuf)
enc.Encode(&lvlMan)
ioutil.WriteFile(levelFile, obuf.Bytes(), 0644)
log.Println("done.")
}
func init() {

View File

@ -1,18 +1,61 @@
package data // code.bitsetter.de/fun/gosl/data
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 }
type Layer struct {
data []byte
w, h int
Z int `json:"Z-Index"`
D directionType `json:"Direction"`
S int `json:"Speed"`
T string `json:"Transparent"`
Repeat bool
Frames map[int]([][]rune)
}
type Level struct {
Layers map[int]*Layer
Name string
FPS int
Layers map[string]*Layer
}
func (lvl *Level) AddLayer(z int, l *Layer) {
lvl.Layers[z] = l
}
//func (lvl *Level) AddLayer(z int, l *Layer) {
// lvl.Layers[z] = l
//}
func LoadLevel(filename string) *Level {
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
}

View File

@ -23,7 +23,6 @@
LevelDir
+-- Manifest :)
+-- Layer 1
| +-- Manifest << layer dimension, orientation and speed, transparency char
| +-- 1.frame << text, unix style lf
| +-- 2.frame
| | …