Skip to content

Commit

Permalink
Use animated pokemon
Browse files Browse the repository at this point in the history
  • Loading branch information
CrosleyZack committed Oct 13, 2024
1 parent 8487594 commit 825d129
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 54 deletions.
36 changes: 14 additions & 22 deletions README.base.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<img src="landscape.gif" width="100%" height="100%">
<!-- Credit to W00kieetreiber @ https://www.reddit.com/r/Firewatch/comments/s9m7b1/i_made_this/ for gif -->

<!-- Credit to alexandresanlim @ https://github.com/alexandresanlim/Badges4-README.md-Profile for badges -->
<p align='center'>

<!-- Credit to alexandresanlim @ https://github.com/alexandresanlim/Badges4-README.md-Profile as inspiration for badges -->
<div align='center'>
<a href="https://www.linkedin.com/in/crosleyzack/">
<img src="https://img.shields.io/badge/linkedin-%230077B5.svg?&style=for-the-badge&logo=linkedin&logoColor=white" />
</a>
Expand All @@ -12,17 +11,18 @@
<img src="https://img.shields.io/badge/website-222222?style=for-the-badge&logo=githubpages&logoColor=white" />
</a>
&nbsp;&nbsp;
<!-- TODO update with proper URI later -->
<a href="https://signal.me/#eu/19hMy6iGDXwaBMNL0wdNbtf5alA5P9j3JkJSp//lHrHXtawqWEROWK1MatAWsUz1">
<img src="https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white" />
</a>
<!--<img src="https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white" onmouseover="this.src='https://img.shields.io/badge/crosleyzack.01-3A76F0?style=for-the-badge&logo=signal&logoColor=white'" onmouseout="this.src='https://img.shields.io/badge/signal-3A76F0?style=for-the-badge&logo=signal&logoColor=white'" />-->
</p>
&nbsp;&nbsp;
<a href="mailto:[email protected]">
<img src="https://img.shields.io/badge/email-EA4335?style=for-the-badge&logo=gmail&logoColor=white" />
</a>
</div>

---


<p align='center'>
<div align='center'>
<img src="https://img.shields.io/badge/go-00ADD8?style=for-the-badge&logo=go&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/python-3776AB?style=for-the-badge&logo=python&logoColor=white" />
Expand All @@ -46,13 +46,6 @@
<img src="https://img.shields.io/badge/docker-2CA5E0?style=for-the-badge&logo=docker&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/kubernetes-326CE5?style=for-the-badge&logo=kubernetes&logoColor=white" />
<!-- <img src="https://img.shields.io/badge/django-092E20?style=for-the-badge&logo=django&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/latex-008080?style=for-the-badge&logo=latex&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/yubico-84BD80?style=for-the-badge&logo=yubico&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/wappalyzer-4608AD?style=for-the-badge&logo=wappalyzer&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/redis-DC382D?style=for-the-badge&logo=redis&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/scala-DC322F?style=for-the-badge&logo=scala&logoColor=white" /> -->


<br >

Expand All @@ -67,11 +60,8 @@
<img src="https://img.shields.io/badge/tmux-1BB915?style=for-the-badge&logo=tmux&logoColor=white" />
&nbsp;
<img src="https://img.shields.io/badge/linux-E0B020?style=for-the-badge&logo=linux&logoColor=white" />
<!-- <img src="https://img.shields.io/badge/xorg-F28834?style=for-the-badge&logo=xdotorg&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/wayland-F0B000?style=for-the-badge&logo=wayland&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/Debian-A81D33?style=for-the-badge&logo=debian&logoColor=white" /> -->
<!-- <img src="https://img.shields.io/badge/fedora-51A2DA?style=for-the-badge&logo=fedora&logoColor=white" /> -->
</p>
</div>

<!-- [Public Key](key.pub) -->

Expand All @@ -92,7 +82,9 @@ https://img.shields.io/badge/with%20a%20logo-8A2BE2?style=for-the-badge&logo=dat
### Random Encounter

<details>
<p align="center">
<img src="{{pokemon}}" alt="Random Pokemon" height="100" width="100" />
</p>
<div align="center">
<img src="{{link}}" alt="Random Pokemon" height="100" width="100" />
<br >
<b>{{name}}</b>
</div>
</details>
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module github.com/crosleyzack/crosleyzack

go 1.22.7

require (
github.com/samber/lo v1.47.0 // indirect
golang.org/x/text v0.16.0 // indirect
)
81 changes: 49 additions & 32 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"net/http"
"os"
"strings"

"github.com/samber/lo"
)

//go:embed README.base.md
Expand All @@ -33,33 +35,48 @@ type Sprites struct {
FrontShinyFemale string `json:"front_shiny_female"`
}

func (s Sprites) hasGenderedForm() bool {
return s.FrontFemale != "" && s.FrontShinyFemale != ""
type GameSprites struct {
Sprites
Animated Sprites `json:"animated"`
}

func (s Sprites) getSprite(male bool, shiny bool) (uri string) {
if shiny {
switch male {
case true:
uri = s.FrontShiny
default:
uri = s.FrontShinyFemale
}
} else {
switch male {
case true:
uri = s.FrontDefault
default:
uri = s.FrontFemale
}
}
return uri
type Generation struct {
BlackWhite GameSprites `json:"black-white"`
}

type Versions struct {
// only grabbing fifth gen as it has gifs
Fifth Generation `json:"generation-v"`
}

type TopLevelSprites struct {
// default sprites
Sprites
// Various versions of the sprite
Versions Versions `json:"versions"`
}

// Pokemon is a struct that contains the name and sprites of a pokemon
type Pokemon struct {
Name string `json:"name"`
Sprites Sprites `json:"sprites"`
Name string `json:"name"`
Sprites TopLevelSprites `json:"sprites"`
}

func (p Pokemon) hasGenderedForm() bool {
return p.Sprites.FrontFemale != "" && p.Sprites.FrontShinyFemale != ""
}

func (p Pokemon) getSprite(male bool, shiny bool) (uri string) {
if shiny && male {
uri = lo.CoalesceOrEmpty(p.Sprites.Versions.Fifth.BlackWhite.Animated.FrontShiny, p.Sprites.FrontShiny)
} else if male && !shiny {
uri = lo.CoalesceOrEmpty(p.Sprites.Versions.Fifth.BlackWhite.Animated.FrontDefault, p.Sprites.FrontDefault)
} else if !male && shiny {
uri = lo.CoalesceOrEmpty(p.Sprites.Versions.Fifth.BlackWhite.Animated.FrontShinyFemale, p.Sprites.FrontShinyFemale)
} else {
uri = lo.CoalesceOrEmpty(p.Sprites.Versions.Fifth.BlackWhite.Animated.FrontFemale, p.Sprites.FrontFemale)
}
return uri
}

func getPokemon(number int) (*Pokemon, error) {
Expand All @@ -86,32 +103,32 @@ func getPokemon(number int) (*Pokemon, error) {

func getSprite(pokemon *Pokemon) string {
male := true
if pokemon.Sprites.hasGenderedForm() {
if pokemon.hasGenderedForm() {
male = rand.Float32() < 0.5
}
return pokemon.Sprites.getSprite(male, isShiny())
return pokemon.getSprite(male, isShiny())
}

func getRandomEncounter() (string, error) {
pokemon, err := getPokemon(getPokemonNumber())
if err != nil {
return "", fmt.Errorf("error getting pokemon: %w", err)
}
return getSprite(pokemon), nil
func newReadme(readme string, pokemon *Pokemon) string {
// update link and name
readme = strings.Replace(string(readme), "{{link}}", getSprite(pokemon), 1)
readme = strings.Replace(readme, "{{name}}", strings.Title(pokemon.Name), 1)
return readme
}

// main loads root command from cmds package and executes it
func main() {
encounter, err := getRandomEncounter()
pokemon, err := getPokemon(getPokemonNumber())
if err != nil {
log.Fatal(err)
}
log.Printf("Got pokemon: %v", pokemon)
readme, err := fs.ReadFile("README.base.md")
if err != nil {
log.Fatal(err)
}
newREADME := strings.Replace(string(readme), "{{pokemon}}", encounter, 1)
if err := os.WriteFile("README.md", []byte(newREADME), 0666); err != nil {
new := newReadme(string(readme), pokemon)
if err := os.WriteFile("README.md", []byte(new), 0666); err != nil {
log.Fatal(err)
}
return
Expand Down

0 comments on commit 825d129

Please sign in to comment.