agp

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2021 License: GPL-3.0 Imports: 8 Imported by: 3

README

agp

Go project version GoDoc

Package agp is a gene parsing package for Axie Infinity.

The name agp stands for "Axie Gene Parser" which decodes the hex representation of an Axie's gene into a human readable format.

Now supports both 256 and 512 bit hex genes



Install

With a correctly configured Go toolchain:

go get -u github.com/shanemaglangit/agp

Usage

Starting on v1.0.3, ParseHexDecode was introduced which combines both ParseHex and Decode into a single function.

Use ParseHex512(), Decode512(), and ParseHexDecode512() for 512 bits respectively.

To get started, you'll first need to get the gene of an Axie in hex. You may use the Axie Infinity GraphQL endpoint to get this detail. For this example, let's use the hex 0x11c642400a028ca14a428c20cc011080c61180a0820180604233082

Let us first parse this hex into a GeneBinGroup object. ParseHex() first converts the given hex into its binary format. It thens divides these binary bits into their own respective groups, each representing a certain attribute of the Axie's gene.

gbg, err := agp.ParseHex("0x11c642400a028ca14a428c20cc011080c61180a0820180604233082")

Once we generated the GeneBinGroup, we can then use decode this object into human readable format using Decode()

genes, err := agp.Decode(gbg)

The generated output should look like this

&Genes{
  Class:    Beast,
  Region:   Global,
  Tag:      NoTag,
  BodySkin: DefBodySkin,
  Pattern:  PatternGene{"000001", "000111", "000110"},
  Color:    ColorGene{"f0c66e", "ffec51", "f0c66e"},
  Eyes: Part{
    D:  PartGene{"eyes-chubby", Beast, "", Eyes, "Chubby"},
    R1: PartGene{"eyes-chubby", Beast, "", Eyes, "Chubby"},
    R2: PartGene{"eyes-blossom", Plant, "", Eyes, "Blossom"},
  },
  Ears: Part{
    D:  PartGene{"ears-lotus", Plant, "", Ears, "Lotus"},
    R1: PartGene{"ears-nut-cracker", Beast, "", Ears, "Nut Cracker"},
    R2: PartGene{"ears-inkling", Aquatic, "", Ears, "Inkling"},
  },
  Horn: Part{
    D:  PartGene{"horn-rose-bud", Plant, "", Horn, "Rose Bud"},
    R1: PartGene{"horn-caterpillars", Bug, "", Horn, "Caterpillars"},
    R2: PartGene{"horn-dual-blade", Beast, "", Horn, "Dual Blade"},
  },
  Mouth: Part{
    D:  PartGene{"mouth-tiny-turtle", Reptile, "", Mouth, "Tiny Turtle"},
    R1: PartGene{"mouth-piranha", Aquatic, "", Mouth, "Piranha"},
    R2: PartGene{"mouth-serious", Plant, "", Mouth, "Serious"},
  },
  Back: Part{
    D:  PartGene{"back-balloon", Bird, "", Back, "Balloon"},
    R1: PartGene{"back-jaguar", Beast, "", Back, "Jaguar"},
    R2: PartGene{"back-jaguar", Beast, "", Back, "Jaguar"},
  },
  Tail: Part{
    D:  PartGene{"tail-ant", Bug, "", Tail, "Ant"},
    R1: PartGene{"tail-hot-butt", Plant, "", Tail, "Hot Butt"},
    R2: PartGene{"tail-swallow", Bird, "", Tail, "Swallow"},
  },
}

NPM Support

I also released a similar package for NPM. Do check it out!

Support the Author

Love this module? Feel free to buy me a coffee and motivate me to work on more stuffs like this!

Ronin Address: ronin:789c9b253eba265f0079e3ebcaaea2503eb31bb3
ETH Address: 0x9F50E3606caf22ff5E0E03F0eb02DE3Fa2786535
Paypal: paypal.me/shanemaglangit

Support does not need to have any monetary value. I would also appreciate if you leave a star!

Documentation

Index

Constants

View Source
const (
	Eyes  PartType = "eyes"
	Ears           = "ears"
	Mouth          = "mouth"
	Horn           = "horn"
	Back           = "back"
	Tail           = "tail"
)
View Source
const (
	Beast   Class = "beast"
	Bug           = "bug"
	Bird          = "bird"
	Plant         = "plant"
	Aquatic       = "aquatic"
	Reptile       = "reptile"
	Mech          = "mech"
	Dusk          = "dusk"
	Dawn          = "dawn"
)
View Source
const (
	NoTag        Tag = ""
	Agamogenesis     = "agamogenesis"
	Origin           = "origin"
	Meo1             = "meo1"
	Meo2             = "meo2"
)
View Source
const (
	GlobalSkin PartSkin = "global"
	JapanSkin           = "japan"
	Xmas1               = "xmas1"
	Xmas2               = "xmas2"
	Mystic              = "mystic"
	Bionic              = "bionic"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BodySkin

type BodySkin string

BodySkin represents the special skin of an Axie's body. This can either be none (default) or Frosty.

const (
	DefBodySkin BodySkin = ""
	Frosty               = "frosty"
)

type Class

type Class string

Class represents the class of a given Axie. A class is among these values: Beast, Bug, Bird, Plant, Aquatic, Reptile, Mech, Dusk, Dawn.

type ColorGene

type ColorGene struct {
	D  string `json:"d,omitempty"`
	R1 string `json:"r1,omitempty"`
	R2 string `json:"r2,omitempty"`
}

ColorGene stores the dominant and recessive genes of an Axie's color.

type GeneBinGroup

type GeneBinGroup struct {
	Class    string
	Region   string
	Tag      string
	BodySkin string
	Xmas     string
	Pattern  string
	Color    string
	Eyes     string
	Ears     string
	Horn     string
	Mouth    string
	Back     string
	Tail     string
}

GeneBinGroup collectively stores each part of the parsed binary representation of the genes.

func ParseHex

func ParseHex(hex string) (GeneBinGroup, error)

ParseHex divide bits from the 256 hex representation of the string into their respective groups.

func ParseHex512 added in v1.1.0

func ParseHex512(hex string) (GeneBinGroup, error)

ParseHex512 divide bits from the 512 hex representation of the string into their respective groups.

type Genes

type Genes struct {
	Class       Class       `json:"class,omitempty"`
	Region      Region      `json:"region,omitempty"`
	Tag         Tag         `json:"tag,omitempty"`
	BodySkin    BodySkin    `json:"bodySkin,omitempty"`
	Pattern     PatternGene `json:"pattern,omitempty"`
	Color       ColorGene   `json:"color,omitempty"`
	Eyes        Part        `json:"eyes,omitempty"`
	Mouth       Part        `json:"mouth,omitempty"`
	Ears        Part        `json:"ears,omitempty"`
	Horn        Part        `json:"horn,omitempty"`
	Back        Part        `json:"back,omitempty"`
	Tail        Part        `json:"tail,omitempty"`
	GeneQuality float64     `json:"geneQuality,omitempty"`
}

Genes contains the overall data about the Axie's gene.

func Decode

func Decode(gbg *GeneBinGroup) (Genes, error)

Decode parses the grouped binary and extracts the Axie information into a Gene object.

func Decode512 added in v1.1.0

func Decode512(gbg *GeneBinGroup) (Genes, error)

Decode512 parses the grouped binary and extracts the Axie information into a Gene object.

func ParseHexDecode added in v1.0.7

func ParseHexDecode(hex string) (Genes, error)

ParseHexDecode parses a given 256 hex into a Gene object. This combines ParseHex and Decode into a single function.

func ParseHexDecode512 added in v1.1.0

func ParseHexDecode512(hex string) (Genes, error)

ParseHexDecode512 parses a given 512 hex into a Gene object. This combines ParseHex512 and Decode512 into a single function.

type Part

type Part struct {
	D      PartGene `json:"d1,omitempty"`
	R1     PartGene `json:"r1,omitempty"`
	R2     PartGene `json:"r2,omitempty"`
	Mystic bool     `json:"mystic,omitempty"`
}

Part stores the dominant and recessive genes of an Axie's part.

type PartGene

type PartGene struct {
	PartId       string   `json:"partId,omitempty"`
	Class        Class    `json:"class,omitempty"`
	SpecialGenes string   `json:"specialGenes,omitempty"`
	Type         PartType `json:"type,omitempty"`
	Name         string   `json:"name,omitempty"`
}

PartGene holds the data for a single gene of an Axie's part.

type PartSkin added in v1.0.7

type PartSkin string

PartSkin represents the special skin of an Axie's part. This can be Global, Japan, Xmas, Mystic, Bionic (Agamogenesis)

type PartType

type PartType string

PartType represents each of an Axies body parts including: Eeyes, Ears, Mouth, Horn, Back, Tail.

type PatternGene

type PatternGene struct {
	D  string `json:"d,omitempty"`
	R1 string `json:"r1,omitempty"`
	R2 string `json:"r2,omitempty"`
}

PatternGene stores the dominant and recessive genes of an Axie's skin pattern.

type Region

type Region string

Region represents the region origin of a given Axie. A region can either be Global or Japan.

const (
	Global Region = "global"
	Japan         = "japan"
)

type Tag

type Tag string

Tag represents the tag attached to a given Axie. Special Axies may have the title Origin, Meo1, or Meo2 tag.

Jump to

Keyboard shortcuts

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