skin

package
v0.9.15 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 3 Imported by: 24

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Animation

type Animation struct {

	// Pix holds skin data for every frame of the animation. This is an RGBA byte slice, meaning that every
	// first byte is a Red value, the second a Green value, the third a Blue value and the fourth an Alpha
	// value.
	Pix []uint8

	// FrameCount is the amount of frames that the animation plays for. Exactly this amount of frames should
	// be present in the Pix animation data.
	FrameCount int

	// AnimationExpression is the player's animation expression.
	AnimationExpression int
	// contains filtered or unexported fields
}

Animation represents an animation that plays over the skin every so often. It is assigned to a particular part of the skin, which is represented by one of the constants above.

func NewAnimation

func NewAnimation(width, height int, expression int, animationType AnimationType) Animation

NewAnimation returns a new animation using the width and height passed, with the type specifying what part of the body to display it on. NewAnimation fills out the Pix field adequately and sets FrameCount to 1 by default.

func (Animation) At

func (a Animation) At(x, y int) color.Color

At returns the colour at a given position in the animation data, provided the X and Y are within the bounds of the animation passed during construction. The concrete type returned by At is a color.RGBA value.

func (Animation) Bounds

func (a Animation) Bounds() image.Rectangle

Bounds ...

func (Animation) ColorModel

func (a Animation) ColorModel() color.Model

ColorModel ...

func (Animation) Type

func (a Animation) Type() AnimationType

Type returns the type of the animation, which is one of the constants above.

type AnimationType

type AnimationType int

AnimationType represents a type of the animation. It is one of the constants above, and specifies to what part of the body it is assigned.

const (
	// AnimationHead is an animation that is played over the head part of the skin.
	AnimationHead AnimationType = iota
	// AnimationBody32x32 is an animation that is played over the body of a skin with a 32x32(/64) size. This
	// is the usual animation type for body animations.
	AnimationBody32x32
	// AnimationBody128x128 is an animation that is played over a body of a skin with a 128x128 size. This is
	// the animation type for body animations with high resolution.
	AnimationBody128x128
)

type Cape

type Cape struct {

	// Pix holds the colour data of the cape in an RGBA byte array, similarly to the way that the pixels of
	// a Skin are stored.
	// The size of Pix is always 32 * 64 * 4 bytes.
	Pix []uint8
	// contains filtered or unexported fields
}

Cape represents the cape that a skin may additionally have. A skin is of a fixed size (always 32x64 bytes) and may be either empty or of that size.

func NewCape

func NewCape(width, height int) Cape

NewCape initialises a new Cape using the width and height passed. The pixels are pre-allocated so that the Cape may be used immediately.

func (Cape) At

func (c Cape) At(x, y int) color.Color

At returns the colour at a given position in the cape, provided the X and Y are within the bounds of the cape passed during construction. The concrete type returned by At is a color.RGBA value.

func (Cape) Bounds

func (c Cape) Bounds() image.Rectangle

Bounds returns the bounds of the cape, which is always 32x64 or 0x0, depending on if the cape has any data in it.

func (Cape) ColorModel

func (c Cape) ColorModel() color.Model

ColorModel ...

type ModelConfig

type ModelConfig struct {
	// Default is the 'default' model to use. This model is essentially the model of the skin that will be
	// used at all times, when nothing special is being done. (For example, an animation)
	// The field holds the name of one of the models present in the JSON of the skin's model.
	// This field should always be filled out.
	Default string `json:"default"`
	// AnimatedFace is the model of an animation played over the face. This field should be set if the model
	// contains the model of an animation, in which case this field should hold the name of that model.
	AnimatedFace string `json:"animated_face,omitempty"`
}

ModelConfig specifies the way that the model (geometry data) is used to form the complete skin. It does this by setting model names for specific keys found in the struct.

func DecodeModelConfig

func DecodeModelConfig(b []byte) (ModelConfig, error)

DecodeModelConfig attempts to decode a ModelConfig from the JSON data passed. If not successful, an error is returned.

func (ModelConfig) Encode

func (cfg ModelConfig) Encode() []byte

Encode encodes a ModelConfig into its JSON representation.

type Skin

type Skin struct {

	// Persona specifies if the skin uses the persona skin system.
	Persona   bool
	PlayFabID string

	// Pix holds the raw pixel data of the skin. This is an RGBA byte slice, meaning that every first byte is
	// a Red value, the second a Green value, the third a Blue value and the fourth an Alpha value.
	Pix []uint8

	// ModelConfig specifies how the Model field below should be used to form the total skin.
	ModelConfig ModelConfig
	// Model holds the raw JSON data that represents the model of the skin. If empty, it means the skin holds
	// the standard skin data (geometry.humanoid).
	// TODO: Write a full API for this. The model should be able to be easily modified or created runtime.
	Model []byte

	// Cape holds the cape of the skin. By default, an empty cape is set in the skin. Cape.Exists() may be
	// called to check if the cape actually has any data.
	Cape Cape

	// Animations holds a list of all animations that the skin has. These animations must be pointed to in the
	// ModelConfig, in order to display them on the skin.
	Animations []Animation
	// contains filtered or unexported fields
}

Skin holds the data of a skin that a player has equipped. It includes geometry data, the texture and the cape, if one is present. Skin implements the image.Image interface to ease working with the value as an image.

func New

func New(width, height int) Skin

New creates a new skin using the width and height passed. The dimensions passed must be either 64x32, 64x64 or 128x128. An error is returned if other dimensions are used. The skin pixels are initialised for the skin, and a random skin ID is picked. The model name and model is left empty.

func (Skin) At

func (s Skin) At(x, y int) color.Color

At returns the colour at a given position in the skin. The concrete value of the colour returned is a color.RGBA value. If the x or y values exceed the bounds of the skin, At will panic.

func (Skin) Bounds

func (s Skin) Bounds() image.Rectangle

Bounds returns the bounds of the skin. These are either 64x32, 64x64 or 128, depending on the bounds of the skin of the player.

func (Skin) ColorModel

func (s Skin) ColorModel() color.Model

ColorModel returns color.RGBAModel.

Jump to

Keyboard shortcuts

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