koffing

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2021 License: Unlicense Imports: 5 Imported by: 0

README

Koffing Go

This package is Go implementation of Koffing.

Koffing-Go is a Pokemon Showdown Team parser that converts your Showdown-formatted text team to machine-readable JSON code.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pokemon

type Pokemon struct {
	Name      string `json:"name"`
	Nickname  string `json:"nickname"`
	Gender    string `json:"gender"`
	Item      string `json:"item"`
	Ability   string `json:"ability"`
	Level     int    `json:"level"`
	Shiny     bool   `json:"shiny"`
	Happiness int    `json:"happiness"`
	Nature    string `json:"nature"`
	Evs       struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	} `json:"evs"`
	Ivs struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	} `json:"ivs"`
	Moves []string `json:"moves"`
}

Pokemon contains all properties of a Pokémon you can set in Teambuilder on Pokémon Showdown.

func (*Pokemon) FromJson

func (p *Pokemon) FromJson(j string) error

FromJson parses the JSON-encoded Pokémon data and stores the result in the pointer receiver.

Example
p := &Pokemon{}
paste := `{
          "name": "Koffing",
          "nickname": "Smogon",
          "gender": "F",
          "item": "Eviolite",
          "ability": "Neutralizing Gas",
          "level": 5,
          "shiny": true,
          "happiness": 255,
          "nature": "Bold",
          "evs": {
            "hp": 36,
            "def": 236,
            "spd": 236
          },
          "ivs": {
            "hp": 31,
            "atk": 30,
            "spa": 31,
            "spd": 30
          },
          "moves": [
            "Will-O-Wisp",
            "Pain Split",
            "Sludge Bomb",
            "Fire Blast"
          ]
	}`
_ = p.FromJson(paste)
fmt.Printf("%+v", p)
Output:

&{Name:Koffing Nickname:Smogon Gender:F Item:Eviolite Ability:Neutralizing Gas Level:5 Shiny:true Happiness:255 Nature:Bold Evs:{Hp:36 Atk:0 Def:236 Spa:0 Spd:236 Spe:0} Ivs:{Hp:31 Atk:30 Def:0 Spa:31 Spd:30 Spe:0} Moves:[Will-O-Wisp Pain Split Sludge Bomb Fire Blast]}

func (*Pokemon) FromShowdown

func (p *Pokemon) FromShowdown(s string) error

FromShowdown parses the Showdown-formatted Pokémon data and stores the result in the pointer receiver.

Example
s := `Smogon (Koffing) (F) @ Eviolite
		Level: 100
		Ability: Neutralizing Gas
		Shiny: Yes
		Happiness: 255
		EVs: 36 HP / 236 Def / 236 SpD
		Bold Nature
		IVs: 31 HP / 30 SpD / 0 Spe
		- Will-O-Wisp
		- Pain Split
		- Sludge Bomb
		- Fire Blast`
p := &Pokemon{}
_ = p.FromShowdown(s)
fmt.Printf("%+v", p)
Output:

&{Name:Koffing Nickname:Smogon Gender:F Item:Eviolite Ability:Neutralizing Gas Level:100 Shiny:true Happiness:255 Nature:Bold Evs:{Hp:36 Atk:0 Def:236 Spa:0 Spd:236 Spe:0} Ivs:{Hp:31 Atk:31 Def:31 Spa:31 Spd:30 Spe:0} Moves:[Will-O-Wisp Pain Split Sludge Bomb Fire Blast]}

func (Pokemon) ToJson

func (p Pokemon) ToJson() (string, error)

ToJson returns the JSON encoding of the receiver.

Example
p := Pokemon{
	Name:      "Koffing",
	Nickname:  "Smogon",
	Gender:    "F",
	Item:      "Eviolite",
	Ability:   "Neutralizing Gas",
	Level:     5,
	Shiny:     true,
	Happiness: 255,
	Nature:    "Bold",
	Evs: struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	}{Hp: 36, Def: 236, Spd: 236},
	Ivs: struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	}{Hp: 31, Atk: 30, Spa: 31, Spd: 30, Spe: 31},
	Moves: []string{"Will-O-Wisp", "Pain Split", "Sludge Bomb", "Fire Blast"},
}
j, _ := p.ToJson()
fmt.Print(j)
Output:

{"name":"Koffing","nickname":"Smogon","gender":"F","item":"Eviolite","ability":"Neutralizing Gas","level":5,"shiny":true,"happiness":255,"nature":"Bold","evs":{"hp":36,"atk":0,"def":236,"spa":0,"spd":236,"spe":0},"ivs":{"hp":31,"atk":30,"def":0,"spa":31,"spd":30,"spe":31},"moves":["Will-O-Wisp","Pain Split","Sludge Bomb","Fire Blast"]}

func (Pokemon) ToShowdown

func (p Pokemon) ToShowdown() (string, error)

ToShowdown returns the Showdown-formatted text of the receiver.

Example
p := Pokemon{
	Name:      "Koffing",
	Nickname:  "Smogon",
	Gender:    "F",
	Item:      "Eviolite",
	Ability:   "Neutralizing Gas",
	Level:     100,
	Shiny:     true,
	Happiness: 255,
	Nature:    "Bold",
	Evs: struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	}{Hp: 36, Def: 236, Spd: 236},
	Ivs: struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	}{Hp: 31, Atk: 30, Spa: 31, Spd: 30, Spe: 31},
	Moves: []string{"Will-O-Wisp", "Pain Split", "Sludge Bomb", "Fire Blast"},
}
s, _ := p.ToShowdown()
fmt.Print(s)
Output:

Smogon (Koffing) (F) @ Eviolite
Level: 100
Ability: Neutralizing Gas
Shiny: Yes
Happiness: 255
EVs: 36 HP / 236 Def / 236 SpD
Bold Nature
IVs: 30 Atk / 0 Def / 30 SpD
- Will-O-Wisp
- Pain Split
- Sludge Bomb
- Fire Blast

func (Pokemon) Validate

func (p Pokemon) Validate() error

Validate verify the legitimation of this Pokemon with some basic rules, most of which are empty and range checking.

Example
p := Pokemon{}
err := p.Validate()
fmt.Print(err.Error())
Output:

name is required

type Team

type Team struct {
	Name    string    `json:"name,omitempty"`
	Format  string    `json:"format,omitempty"`
	Folder  string    `json:"folder,omitempty"`
	Pokemon []Pokemon `json:"pokemon,omitempty"`
}

Team contains not only a list of Pokemon, but also Name, Format and Folder information.

func (*Team) FromJson

func (t *Team) FromJson(j string) error

FromJson parses the JSON-encoded Showdown paste/text data and stores the result in the pointer receiver.

Example
team := &Team{}
j := `{"name":"Example Team","format":"gen7","folder":"Folder 1","pokemon":[{"name":"Koffing","nickname":"Smogon","gender":"F","item":"Eviolite","ability":"Levitate","level":5,"shiny":true,"happiness":255,"nature":"Bold","evs":{"hp":36,"def":236,"spd":236},"ivs":{"hp":31,"atk":30,"spa":31,"spd":30,"spe":31},"moves":["Will-O-Wisp","Pain Split","Sludge Bomb","Fire Blast"]},{"name":"Weezing","item":"Black Sludge","ability":"Levitate","nature":"Bold","evs":{"hp":252,"def":160,"spe":96},"moves":["Sludge Bomb","Will-O-Wisp","Toxic Spikes","Taunt"]}]}`
_ = team.FromJson(j)
fmt.Printf("%+v", team)
Output:

&{Name:Example Team Format:gen7 Folder:Folder 1 Pokemon:[{Name:Koffing Nickname:Smogon Gender:F Item:Eviolite Ability:Levitate Level:5 Shiny:true Happiness:255 Nature:Bold Evs:{Hp:36 Atk:0 Def:236 Spa:0 Spd:236 Spe:0} Ivs:{Hp:31 Atk:30 Def:0 Spa:31 Spd:30 Spe:31} Moves:[Will-O-Wisp Pain Split Sludge Bomb Fire Blast]} {Name:Weezing Nickname: Gender: Item:Black Sludge Ability:Levitate Level:0 Shiny:false Happiness:0 Nature:Bold Evs:{Hp:252 Atk:0 Def:160 Spa:0 Spd:0 Spe:96} Ivs:{Hp:0 Atk:0 Def:0 Spa:0 Spd:0 Spe:0} Moves:[Sludge Bomb Will-O-Wisp Toxic Spikes Taunt]}]}

func (*Team) FromShowdown

func (t *Team) FromShowdown(s string) error

FromShowdown parses the Showdown paste/text and stores the result in the pointer receiver.

Example
s := `=== [gen7] Folder 1/Example Team ===

		Smogon (Koffing) (F) @ Eviolite
		Level: 5
		Ability: Levitate
		Shiny: Yes
		Happiness: 255
		EVs: 36 HP / 236 Def / 236 SpD
		IVs: 31 HP / 30 Atk / 31 SpA / 30 SpD / 31 Spe
		Bold Nature
		- Will-O-Wisp
		- Pain Split
		- Sludge Bomb
		- Fire Blast
		
		Venusaur-Gmax @ Coba Berry  
		Ability: Chlorophyll  
		Level: 50  
		EVs: 156 HP / 4 Def / 252 SpA / 4 SpD / 92 Spe  
		Modest Nature  
		IVs: 0 Atk  
		- Frenzy Plant  
		- Sludge Bomb  
		- Earth Power  
		- Sleep Powder  
		`
team := new(Team)
_ = team.FromShowdown(s)
fmt.Printf("%+v", team)
Output:

&{Name:Example Team Format:gen7 Folder:Folder 1 Pokemon:[{Name:Koffing Nickname:Smogon Gender:F Item:Eviolite Ability:Levitate Level:5 Shiny:true Happiness:255 Nature:Bold Evs:{Hp:36 Atk:0 Def:236 Spa:0 Spd:236 Spe:0} Ivs:{Hp:31 Atk:30 Def:31 Spa:31 Spd:30 Spe:31} Moves:[Will-O-Wisp Pain Split Sludge Bomb Fire Blast]} {Name:Venusaur-Gmax Nickname: Gender: Item:Coba Berry Ability:Chlorophyll Level:50 Shiny:false Happiness:255 Nature:Modest Evs:{Hp:156 Atk:0 Def:4 Spa:252 Spd:4 Spe:92} Ivs:{Hp:31 Atk:0 Def:31 Spa:31 Spd:31 Spe:31} Moves:[Frenzy Plant Sludge Bomb Earth Power Sleep Powder]}]}

func (Team) ToJson

func (t Team) ToJson() (string, error)

ToJson returns the JSON encoding of the receiver.

Example
team := Team{
	Name:    "Test",
	Format:  "gen8",
	Folder:  "Folder 0",
	Pokemon: []Pokemon{{Name: "Koffing", Ability: "Neutralizing Gas", Nature: "Bold", Moves: []string{"Haze"}}},
}
j, _ := team.ToJson()
fmt.Print(j)
Output:

{"name":"Test","format":"gen8","folder":"Folder 0","pokemon":[{"name":"Koffing","nickname":"","gender":"","item":"","ability":"Neutralizing Gas","level":0,"shiny":false,"happiness":0,"nature":"Bold","evs":{"hp":0,"atk":0,"def":0,"spa":0,"spd":0,"spe":0},"ivs":{"hp":0,"atk":0,"def":0,"spa":0,"spd":0,"spe":0},"moves":["Haze"]}]}

func (Team) ToShowdown

func (t Team) ToShowdown() (string, error)

ToShowdown returns the Showdown paste/text of the receiver.

Example
team := Team{
	Name:   "Test",
	Format: "gen8",
	Folder: "Folder 0",
	Pokemon: []Pokemon{{Name: "Koffing", Ability: "Neutralizing Gas", Nature: "Bold", Moves: []string{"Haze"}, Ivs: struct {
		Hp  int `json:"hp"`
		Atk int `json:"atk"`
		Def int `json:"def"`
		Spa int `json:"spa"`
		Spd int `json:"spd"`
		Spe int `json:"spe"`
	}{Hp: 31, Def: 31, Spd: 31}}},
}
s, _ := team.ToShowdown()
fmt.Print(s)
Output:

=== [gen8] Folder 0/Test ===

Koffing
Ability: Neutralizing Gas
Bold Nature
IVs: 0 Atk / 0 SpA / 0 Spe
- Haze

func (Team) Validate

func (t Team) Validate() error

Validate essentially validates each Pokemon in this Team.

Example
team := Team{
	Name:    "Test",
	Format:  "gen8",
	Folder:  "Folder 0",
	Pokemon: []Pokemon{}, // empty Pokemon is not allowed
}
err := team.Validate()
fmt.Print(err.Error())
Output:

empty team members

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL