-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
58 lines (45 loc) · 1.76 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"flag"
"fmt"
"math/rand"
"strings"
"github.com/charmbracelet/lipgloss"
)
func main() {
pokemonID := flag.Int("id", 0, "Pokémon ID to fetch. If not provided, a random ID will be used.")
pokemonName := flag.String("name", "", "Pokémon name to fetch. If not provided, a random Pokémon will be used.")
shinyFlag := flag.Float64("shiny", 0.5, "Odds of the Pokémon being shiny. Default is 0.5.")
flag.Parse()
dexId := *pokemonID
pokeName := *pokemonName
shinyOdds := *shinyFlag
if dexId == 0 {
if pokeName == "" || !isValidPokemonName(pokeName) {
dexId = rand.Intn(898) + 1
} else {
dexId = fetchPokemonData(pokeName).Id
}
}
dexIdStr := fmt.Sprintf("%d", dexId)
pokemonData := fetchPokemonData(dexIdStr)
pokemonSpeciesData := fetchPokemonSpeciesData(dexIdStr)
name := getEnglishName(pokemonSpeciesData.Names)
weight := fmt.Sprintf("%dkg", pokemonData.Weight)
height := fmt.Sprintf("%.1fm", float32(pokemonData.Height)/10)
genus := getEnglishGenus(pokemonSpeciesData.Genera)
flavorText := getEnglishFlavorText(pokemonSpeciesData.FlavorTextEntries)
typeBadges := getTypeBadges(pokemonData.Types)
isShiny := rollShiny(shinyOdds)
mainColor := getShinyOrRegularColor(isShiny)
dexBadge := createTextBadge(fmt.Sprintf("No.%03d", dexId), mainColor, true)
pokemonImageURL := fmt.Sprintf("https://gitlab.com/phoneybadger/pokemon-colorscripts/-/raw/main/colorscripts/small/%s/%s", getShinyOrRegular(isShiny), strings.ToLower(name))
pokemonImage := fetchPokemonImage(pokemonImageURL)
pokemonInfo := formatPokemonInfo(dexBadge, name, genus, typeBadges, height, weight, flavorText, mainColor)
output := lipgloss.JoinHorizontal(
lipgloss.Top,
lipgloss.NewStyle().MarginRight(4).Render(pokemonImage),
pokemonInfo,
)
println(output)
}