示例#1
0
文件: main.go 项目: RobWC/godragon
func main() {
	newchamp := "Teemo"

	c, err := godragon.StaticChampion(newchamp, currentVersion)
	if err != nil {
		fmt.Printf("Error getting infor for champion %s, ignoring champ\n", newchamp)
		os.Exit(1)
	}

	img, err := c.Image.Fetch(currentVersion)
	if err != nil {
		fmt.Printf("Error fetching image for champion %s, ignoring champ\n", newchamp)
		os.Exit(1)
	}

	imgWidth := img.Bounds().Max.X
	imgHeight := img.Bounds().Max.Y

	// create filler image for blank spaces
	blackFill := image.NewRGBA(image.Rect(0, 0, imgWidth, imgHeight))
	draw.Draw(blackFill, blackFill.Bounds(), &image.Uniform{color.RGBA{0, 0, 0, 0}}, image.ZP, draw.Src)

	// calculate the size of the image
	// calculate the width of the image
	newImgWidthPx := len(newchamp) * (8 * imgWidth)
	newImgHeightPx := len(newchamp) * (8 * imgHeight)

	m := image.NewRGBA(image.Rect(0, 0, newImgWidthPx, newImgHeightPx))
	widthStartPx, heightStartPx := 0, 0

	for l := range newchamp {

		if v, ok := Letters[string(newchamp[l])]; !ok {
			log.Printf("Letter %s not available\n", string(newchamp[l]))
			os.Exit(1)
		} else {

			for i := 0; len(v) > i; i++ {
				for j := 0; len(v[i]) > j; j++ {
					log.Println(widthStartPx, heightStartPx, i, j, LetterA[i][j])
					if v[i][j] == 1 {
						draw.Draw(m, m.Bounds(), img, image.Point{X: widthStartPx, Y: heightStartPx}, draw.Src)
					}
					widthStartPx = widthStartPx - img.Bounds().Max.X

					if widthStartPx < -(newImgWidthPx) {
						break
					}

				}

				heightStartPx = heightStartPx - img.Bounds().Max.Y
				widthStartPx = 0
			}

		}
		widthStartPx = 0
		heightStartPx = heightStartPx + -((8 * imgHeight) + imgHeight)

	}
	godragon.WriteWallpaperFile(m, newchamp, *output)

}
示例#2
0
文件: main.go 项目: RobWC/godragon
func main() {

	// split champnames
	champList := strings.Split(*champname, ",")

	if *all {
		fmt.Printf("Creating wallpapers for all champions at %dx%d\n", *width, *height)

		champs, err := godragon.StaticChampions(currentVersion)
		if err != nil {
			fmt.Printf("Error fetching champion data : %s\n", err)
			os.Exit(1)
		}
		for k := range champs {
			fmt.Printf("Creating wallpaper for %s at %dx%d\n", k, *width, *height)
			img, err := godragon.CreateWallpaper(k, currentVersion, *width, *height)
			if err != nil {
				fmt.Printf("Error creating wallpaper : %s\n", err)
				wg.Wait()
				os.Exit(1)
			}
			wg.Add(1)
			go func(name string) {
				godragon.WriteWallpaperFile(img, name, *output)
				wg.Done()
			}(k)
		}
	} else if len(champList) > 1 {

		type Champ struct {
			Name     string
			ID       int
			Champion godragon.Champion
			Img      image.Image
		}

		var champs []Champ

		for i := range champList {

			c, err := godragon.StaticChampion(champList[i], currentVersion)
			if err != nil {
				fmt.Printf("Error getting infor for champion %s, ignoring champ\n", champList[i])
				continue
			}

			img, err := c.Image.Fetch(currentVersion)
			if err != nil {
				fmt.Printf("Error fetching image for champion %s, ignoring champ\n", champList[i])
				continue
			}

			nc := Champ{
				Name:     champList[i],
				ID:       i,
				Champion: c,
				Img:      img,
			}

			champs = append(champs, nc)
		}

		maxWidth := *width
		maxHeight := *height

		m := image.NewRGBA(image.Rect(0, 0, maxWidth, maxHeight))
		widthStart, heightStart := 0, 0

		x := 0
		for {

			draw.Draw(m, m.Bounds(), champs[x].Img, image.Point{X: widthStart, Y: heightStart}, draw.Src)
			widthStart = widthStart - champs[x].Img.Bounds().Max.X

			if widthStart < -(maxWidth) {
				if (widthStart < -(maxWidth)) && (heightStart < -(maxHeight)) {
					break
				}
				heightStart = heightStart - champs[x].Img.Bounds().Max.Y
				widthStart = 0
			}

			x++
			// reset champ index
			if x == len(champs) {
				x = 0
			}

		}

		champFinalList := []string{}
		for y := range champs {
			champFinalList = append(champFinalList, champs[y].Name)
		}

		wg.Add(1)
		go func() {
			godragon.WriteWallpaperFile(m, strings.Join(champFinalList, ","), *output)
			wg.Done()
		}()
	} else if len(champList) == 1 && champList[0] != "" {
		fmt.Printf("Creating wallpaper for %s at %dx%d\n", *champname, *width, *height)
		img, err := godragon.CreateWallpaper(*champname, currentVersion, *width, *height)
		if err != nil {
			fmt.Printf("Error creating wallpaper : %s\n", err)
			wg.Wait()
			os.Exit(1)
		}
		wg.Add(1)
		go func() {
			godragon.WriteWallpaperFile(img, *champname, *output)
			wg.Done()
		}()
	}
	wg.Wait()
	os.Exit(0)
}