mcskin

package
v0.0.0-...-fdc8e6b Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: Unlicense Imports: 15 Imported by: 0

Documentation

Overview

The problem that is sovled by using the handlers is that you can pass in the minecraft.Skin and it does the rest - vs. requiring a switch logic based on the route for which method to use.

mcskin has the logic for constructing the skin into the desired shape It also will detect width/image type and can be used as an http.Handler to then deliver this to a client

Index

Constants

View Source
const (
	HeadX      = 8
	HeadY      = 8
	HeadWidth  = 8
	HeadHeight = 8

	HelmX = 40
	HelmY = 8

	TorsoX      = 20
	TorsoY      = 20
	TorsoWidth  = 8
	TorsoHeight = 12

	Torso2X = 20
	Torso2Y = 36

	RaX      = 44
	RaY      = 20
	RaWidth  = 4
	RaHeight = 12

	Ra2X = 44
	Ra2Y = 36

	RlX      = 4
	RlY      = 20
	RlWidth  = 4
	RlHeight = 12

	Rl2X = 4
	Rl2Y = 36

	LaX      = 36
	LaY      = 52
	LaWidth  = 4
	LaHeight = 12

	La2X = 52
	La2Y = 52

	LlX      = 20
	LlY      = 52
	LlWidth  = 4
	LlHeight = 12

	Ll2X = 4
	Ll2Y = 52

	// The height of the 'bust' relative to the width of the body (16)
	BustHeight = 16
)
View Source
const (
	DefaultWidth = int(180)
	MinWidth     = int(8)
	MaxWidth     = int(300)
)

Set the default, min and max width to resize processed images to

Variables

This section is empty.

Functions

func GetWidth

func GetWidth(inp string) int

GetWidth converts and sanitizes the string for the avatar width.

func HandlerArmorBody

func HandlerArmorBody(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver a Body with Armor when ServeHTTP is called

func HandlerArmorBust

func HandlerArmorBust(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver a Bust with Armor when ServeHTTP is called

func HandlerBody

func HandlerBody(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver a Body when ServeHTTP is called

func HandlerBust

func HandlerBust(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver a Bust when ServeHTTP is called

func HandlerCube

func HandlerCube(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver an isometric "Cube" avatar when ServeHTTP is called

func HandlerCubeHelm

func HandlerCubeHelm(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver an isometric "Cube" with Helm when ServeHTTP is called

func HandlerHead

func HandlerHead(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver an avatar Head when ServeHTTP is called

func HandlerHelm

func HandlerHelm(logger log.Logger, skinIO mcuser.TextureIO) http.HandlerFunc

Will deliver a head with Helm when ServeHTTP is called

Types

type ImageType

type ImageType string
const (
	ImageTypePNG ImageType = "image/png"
	ImageTypeSVG ImageType = "image/svg+xml"
)

func GetImageType

func GetImageType(ext string) ImageType

GetImageType checks for specific extensions, otherwise uses PNG

func GetWidthType

func GetWidthType(r *http.Request) (width int, imageType ImageType)

Based on *http.Request, read the Gorilla Mux vars for "width" and "extension"

type McSkin

type McSkin struct {
	minecraft.Skin
	Processed image.Image
	Processor func() error
	Type      ImageType
	Width     int
}

func NewMcSkinFromRequest

func NewMcSkinFromRequest(r *http.Request, skin minecraft.Skin) *McSkin

Create a McSkin for manual usage (vs. using the Handlers)

func (*McSkin) GetArmorBody

func (skin *McSkin) GetArmorBody() error

Sets skin.Processed to a front render of the body but with any armor which the user has.

func (*McSkin) GetArmorBust

func (skin *McSkin) GetArmorBust() error

Sets skin.Processed to the upper portion of the body (slightly higher cutoff than waist) but with any armor which the user has.

func (*McSkin) GetBody

func (skin *McSkin) GetBody() error

Sets skin.Processed to a front render of the body.

func (*McSkin) GetBust

func (skin *McSkin) GetBust() error

Sets skin.Processed to the upper portion of the body (slightly higher cutoff than waist).

func (*McSkin) GetCube

func (skin *McSkin) GetCube() error

Sets skin.Processed to an isometric render of the head from a top-left angle (showing 3 sides).

func (*McSkin) GetCubeHelm

func (skin *McSkin) GetCubeHelm() error

Sets skin.Processed to an isometric render of the head from a top-left angle (showing 3 sides).

func (*McSkin) GetHead

func (skin *McSkin) GetHead() error

Sets skin.Processed to the face of the user.

func (*McSkin) GetHelm

func (skin *McSkin) GetHelm() error

Sets skin.Processed to the face of the user overlaid with their helmet.

func (*McSkin) ServeHTTP

func (skin *McSkin) ServeHTTP(w http.ResponseWriter, r *http.Request)

The

func (*McSkin) WritePNG

func (skin *McSkin) WritePNG(w io.Writer) error

Writes the *processed* image as a PNG to the given writer.

func (*McSkin) WriteSVG

func (skin *McSkin) WriteSVG(w io.Writer) error

Writes the processed image as an svg.

func (*McSkin) WriteSkin

func (skin *McSkin) WriteSkin(w io.Writer) error

Writes the *original* skin image as a png to the given writer.

Jump to

Keyboard shortcuts

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