Ejemplo n.º 1
0
func exportTileset(filename string, tmpl *template.Template) {
	fmt.Printf("Processing %s\n", filename)

	file, err := os.Open(filename)

	if err != nil {
		log.Fatal(err)
	}

	tileset, err := tmx.Read(file)

	if err != nil {
		log.Fatal(err)
	}

	luaFilename := strings.Replace(filepath.Base(filename), filepath.Ext(filename), ".lua", 1)
	outputPath := filepath.Join(filepath.Dir(filename), luaFilename)

	output, err := os.Create(outputPath)

	if err != nil {
		log.Fatal(err)
	}

	err = tmpl.Execute(output, tileset)

	if err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 2
0
func (this *TmxTileMap) Load(file string) {
	chk := func(err error) {
		if err != nil {
			log.Fatal("[TmxTileMap] Load(): ", err)
		}
	}

	fd, err := os.Open(file)
	defer fd.Close()
	chk(err)

	this.tmxMap, err = tmx.Read(fd)
	chk(err)

	// pretty.Printf("tmx: %# v\n", this.tmxMap)
	// log.Printf("================\ntmx: %+v\n", m.Version)

	for _, tileset := range this.tmxMap.Tilesets {
		this.renderManager.LoadMapSpriteSet(
			tileset.Image.Source,
			uint(tileset.TileWidth),
			uint(tileset.TileHeight),
		)
	}

	this.width = uint(this.tmxMap.Width)
	this.height = uint(this.tmxMap.Height)
	this.tileWidth = uint(this.tmxMap.TileWidth)
	this.tileHeight = uint(this.tmxMap.TileHeight)
}