Esempio n. 1
0
func ripSingle() error {
	f, err := os.Open(flag.Arg(0))
	if err != nil {
		return err
	}
	defer f.Close()

	rip, err := sprites.NewRipper(f)
	if err != nil {
		return err
	}

	if trainerFlag {
		m, err := rip.Trainer(number)
		if err != nil {
			return err
		}
		return write(m, outname)
	} else if animFlag && rip.HasAnimations() {
		g, err := rip.PokemonAnimation(number)
		if err != nil {
			return err
		}
		return write(g, outname)
	} else if framesFlag && rip.HasAnimations() {
		frames, err := rip.PokemonFrames(number)
		if err != nil {
			return err
		}

		w, h := frames[0].Rect.Dx(), frames[0].Rect.Dy()
		m := image.NewPaletted(image.Rect(0, 0, w*len(frames), h), frames[0].Palette)
		for i := 0; i < len(frames); i++ {
			r := frames[i].Rect.Add(image.Pt(w*i, 0))
			draw.Draw(m, r, frames[i], image.ZP, draw.Src)
		}

		return write(m, outname)
	} else {
		m, err := rip.Pokemon(number)
		if err != nil {
			return err
		}
		return write(m, outname)
	}
}
Esempio n. 2
0
func ripBatchFilename(filename string) error {
	f, err := os.Open(filename)
	if err != nil {
		return err
	}
	defer f.Close()
	rip, err := sprites.NewRipper(f)
	if err != nil {
		return err
	}
	version := rip.Version()
	outdir := filepath.Join(outname, version)
	var things = []struct {
		fn      func(rip *sprites.Ripper, n int, form string, outname string) error
		dirname string
		ext     string
		enabled bool
	}{
		{ripPokemon, "", ".png", true},
		{ripPokemonBack, "back", ".png", true},
		{ripShinyPokemon, "shiny", ".png", true},
		{ripShinyPokemonBack, "back/shiny", ".png", true},
		{ripAnimation, "animated", ".gif", rip.HasAnimations()},
		{ripShinyAnimation, "animated/shiny", ".gif", rip.HasAnimations()},
	}
	for _, t := range things {
		if t.enabled {
			err = os.MkdirAll(filepath.Join(outdir, filepath.FromSlash(t.dirname)), 0777)
			if err != nil && !os.IsExist(err) {
				return err
			}
		}
	}
	for n := 1; n <= sprites.MaxPokemon; n++ {
		for _, t := range things {
			if !t.enabled {
				continue
			}
			name := filepath.Join(filepath.FromSlash(t.dirname), strconv.Itoa(n))
			err := t.fn(rip, n, "", filepath.Join(outdir, name+t.ext))
			if err != nil {
				log.Printf("%s: %s", name, err)
			}
		}
	}
	for _, form := range sprites.UnownForms {
		for _, t := range things {
			if !t.enabled {
				continue
			}
			name := filepath.Join(filepath.FromSlash(t.dirname), "201-"+form)
			err := t.fn(rip, 201, form, filepath.Join(outdir, name+t.ext))
			if err != nil {
				log.Printf("%s: %s", name, err)
			}
		}
	}
	os.MkdirAll(filepath.Join(outdir, "trainers"), 0777)
	for n := 1; n <= sprites.MaxTrainer; n++ {
		name := filepath.Join("trainers", strconv.Itoa(n))
		m, err := rip.Trainer(n)
		if err != nil {
			log.Printf("%s: %s", name, err)
			continue
		}
		err = write(m, filepath.Join(outdir, name+".png"))
		if err != nil {
			log.Printf("%s: %s", name, err)
		}
	}
	return nil
}