github.com/df-mc/dragonfly@v0.9.13/server/player/skin/skin.go (about) 1 package skin 2 3 import ( 4 "image" 5 "image/color" 6 ) 7 8 // Skin holds the data of a skin that a player has equipped. It includes geometry data, the texture and the 9 // cape, if one is present. 10 // Skin implements the image.Image interface to ease working with the value as an image. 11 type Skin struct { 12 w, h int 13 // Persona specifies if the skin uses the persona skin system. 14 Persona bool 15 PlayFabID string 16 17 // Pix holds the raw pixel data of the skin. This is an RGBA byte slice, meaning that every first byte is 18 // a Red value, the second a Green value, the third a Blue value and the fourth an Alpha value. 19 Pix []uint8 20 21 // ModelConfig specifies how the Model field below should be used to form the total skin. 22 ModelConfig ModelConfig 23 // Model holds the raw JSON data that represents the model of the skin. If empty, it means the skin holds 24 // the standard skin data (geometry.humanoid). 25 // TODO: Write a full API for this. The model should be able to be easily modified or created runtime. 26 Model []byte 27 28 // Cape holds the cape of the skin. By default, an empty cape is set in the skin. Cape.Exists() may be 29 // called to check if the cape actually has any data. 30 Cape Cape 31 32 // Animations holds a list of all animations that the skin has. These animations must be pointed to in the 33 // ModelConfig, in order to display them on the skin. 34 Animations []Animation 35 } 36 37 // New creates a new skin using the width and height passed. The dimensions passed must be either 64x32, 38 // 64x64 or 128x128. An error is returned if other dimensions are used. 39 // The skin pixels are initialised for the skin, and a random skin ID is picked. The model name and model is 40 // left empty. 41 func New(width, height int) Skin { 42 return Skin{ 43 w: width, 44 h: height, 45 Pix: make([]uint8, width*height*4), 46 } 47 } 48 49 // Bounds returns the bounds of the skin. These are either 64x32, 64x64 or 128, depending on the bounds of the 50 // skin of the player. 51 func (s Skin) Bounds() image.Rectangle { 52 return image.Rectangle{ 53 Max: image.Point{X: s.w, Y: s.h}, 54 } 55 } 56 57 // ColorModel returns color.RGBAModel. 58 func (s Skin) ColorModel() color.Model { 59 return color.RGBAModel 60 } 61 62 // At returns the colour at a given position in the skin. The concrete value of the colour returned is a color.RGBA 63 // value. 64 // If the x or y values exceed the bounds of the skin, At will panic. 65 func (s Skin) At(x, y int) color.Color { 66 if x < 0 || y < 0 || x >= s.w || y >= s.h { 67 panic("pixel coordinates out of bounds") 68 } 69 offset := x*4 + s.w*y*4 70 return color.RGBA{ 71 R: s.Pix[offset], 72 G: s.Pix[offset+1], 73 B: s.Pix[offset+2], 74 A: s.Pix[offset+3], 75 } 76 }