Documentation
¶
Overview ¶
Package models defines all the types that Porytiles understands.
Index ¶
- Constants
- func TilesPerMetatile(tripleLayer bool) int
- type Attributes
- type BGR15
- type EncounterType
- type GBAPalette
- type GBATile
- type InsertRGBAOpts
- type LayerType
- type Metatile
- type MetatileEntry
- type NormalizedPalette
- type NormalizedPixels
- type NormalizedTile
- type Normalizer
- type PorymapAnim
- type PorymapAnimFrame
- type PorymapTileset
- type PorytilesAnim
- type PorytilesAnimFrame
- type PorytilesTileset
- type RGBA32
- type RGBATile
- type TerrainType
- type TileType
Examples ¶
Constants ¶
const Opaque uint8 = 255
Opaque represents an 8-bit alpha value of 255, indicating full opacity for a Rgba32 Alpha channel.
const PalSize int = 16
PalSize defines the size of a palette. On the GBA, palettes contain 16 colors.
const TilePixCount = TileSideLengthPix * TileSideLengthPix
TilePixCount is the total number of pixels in a Pokémon decomps GBA tile. In this case, it will be 8x8 = 64.
const TileSideLengthPix int = 8
TileSideLengthPix defines the length of a tile side in pixels. Since tiles are always squares, the side length can also be used to compute the pixel count. On the GBA, in tile modes relevant to the Pokémon decomps, tiles are 8x8 pixels.
const Transparent uint8 = 0
Transparent represents an 8-bit alpha value of 0, indicating full transparency for a Rgba32 Alpha channel
Variables ¶
This section is empty.
Functions ¶
func TilesPerMetatile ¶
TilesPerMetatile returns the number of tiles per metatile depending on the prescribed layer configuration. There are four subtiles per metatile layer, so triple-layer metatiles contain 12 total tiles, while traditional dual-layer tiles contain 8.
Types ¶
type Attributes ¶
type Attributes struct { LayerType LayerType EncounterType EncounterType TerrainType TerrainType Behavior uint16 }
type BGR15 ¶
type BGR15 struct {
Bgr uint16
}
A BGR15 is a color in BGR15 format. Each color channel has five bits of precision. GBA colors are represented in BGR15. Implementation requires that the most significant bit go unused, followed by five bits for blue, then green, then red, respectively.
Example ¶
package main import ( "fmt" "github.com/grunt-lucas/porytiles/pkg/models" ) func main() { bgr := models.BGR15{Bgr: 0b0_01010_00001_11101} fmt.Println(bgr.Blue(), bgr.Green(), bgr.Red()) }
Output: 80 8 232
func RGBAToBGR ¶
RGBAToBGR converts a color from RGBA32 format to BGR15 format.
Example ¶
package main import ( "fmt" "strconv" "github.com/grunt-lucas/porytiles/pkg/models" ) func main() { rgba := models.RGBA32{Red: 235, Green: 12, Blue: 81, Alpha: models.Opaque} fmt.Println(strconv.FormatUint(uint64(models.RGBAToBGR(rgba).Bgr), 2)) }
Output: 10100000111101
func (BGR15) Blue ¶
Blue returns the blue channel value of the given BGR15, scaled up to an 8-bit value.
type EncounterType ¶
type EncounterType int
const ( EncounterNone EncounterType = iota EncounterLand EncounterWater )
type GBAPalette ¶
type GBAPalette struct { // LogicalSize represents the "logical" size of the palette, since the true // size is fixed at 16, the GBA hardware palette size. LogicalSize int Colors [PalSize]BGR15 }
GBAPalette is a palette of PalSize (16) BGR15-format colors. A GBAPalette has a fixed size of PalSize, which is the hardware size of a GBA palette.
type GBATile ¶
type GBATile struct {
ColorIndexes [TilePixCount]uint8
}
GBATile represents a tile in GBA VRAM format. Each pixel is an index into a 16 color palette. A GBATile does not specify palette or flip information. That is specified at the Metatile level.
func UniformGBATile ¶
UniformGBATile generates a GBATile with all pixels set to the given value.
type InsertRGBAOpts ¶
type InsertRGBAOpts struct { Transparent RGBA32 SourceRGB *map[BGR15]RGBA32 Engine *diagnostics.DiagnosticEngine PixelRow int PixelCol int EmitDiagnostics bool }
type Metatile ¶
type Metatile struct { Subtiles []MetatileEntry Attr Attributes }
type NormalizedPalette ¶
type NormalizedPalette struct {
Colors []BGR15
}
NormalizedPalette is a wrapper type for a slice of BGR15 colors. NormalizedPalette is a logical representation, unlike GBAPalette, so it does not have a fixed size.
func (*NormalizedPalette) InsertRGBA ¶
func (p *NormalizedPalette) InsertRGBA(rgba RGBA32, diagCtx *InsertRGBAOpts)
type NormalizedPixels ¶
type NormalizedPixels struct {
ColorIndexes [TilePixCount]uint8
}
NormalizedPixels is a wrapper type for an array of 8-bit index pixels in normal form.
type NormalizedTile ¶
type NormalizedTile struct { Source *RGBATile Frames []NormalizedPixels Palette NormalizedPalette HFlip bool VFlip bool }
A NormalizedTile is an individual 8x8 tile in normal form. This is the canonical intermediate tile representation for Porytiles.
func NewNormalizedTile ¶
func NewNormalizedTile(transparentColor RGBA32) *NormalizedTile
NewNormalizedTile creates and returns a new instance of a NormalizedTile. The NormalizedTile palette will contain the given transparent color in the first slot.
func (*NormalizedTile) IsTransparent ¶
func (n *NormalizedTile) IsTransparent() bool
IsTransparent reports whether the given NormalizedTile is an entirely transparent tile.
type Normalizer ¶
type Normalizer struct {
// contains filtered or unexported fields
}
The Normalizer provides functionality to transform an RGBATile into a canonical normal form. Normalizer must be configured with an RGBA32 to treat as transparent.
func NewNormalizer ¶
func NewNormalizer(transparentColor RGBA32, diagEngine *diagnostics.DiagnosticEngine) *Normalizer
NewNormalizer creates and returns a new instance of Normalizer with the given transparent color configuration and diagnostics.DiagnosticEngine pointer.
type PorymapAnim ¶
type PorymapAnim struct { Key []GBATile Frames []PorymapAnimFrame Name string }
type PorymapAnimFrame ¶
type PorymapTileset ¶
type PorymapTileset struct { Tiles []GBATile Metatiles []Metatile PalIndexOfTile []int Pals []GBAPalette ColorIndexMap map[BGR15]int TileIndexMap map[GBATile]int }
A PorymapTileset is a tileset in Porymap format.
type PorytilesAnim ¶
type PorytilesAnim struct { Key []RGBATile Frames []PorytilesAnimFrame Name string }
type PorytilesAnimFrame ¶
func (*PorytilesAnimFrame) Size ¶
func (p *PorytilesAnimFrame) Size() int
Size returns the size of the Tiles slice for this PorytilesAnimFrame.
type PorytilesTileset ¶
A PorytilesTileset is a tileset in Porytiles format.
type RGBA32 ¶
A RGBA32 is a color in RGBA32 format. The type is 4 bytes long: 1 byte for each color channel (red, green, blue) and 1 byte for the alpha channel.
func BGRToRGBA ¶
BGRToRGBA converts a color from BGR15 format to RGBA32 format. The converted RGBA32 will always have an alpha channel set to full opacity.
Example ¶
package main import ( "fmt" "github.com/grunt-lucas/porytiles/pkg/models" ) func main() { bgr := models.BGR15{Bgr: 0b0_01010_00001_11101} fmt.Println(models.BGRToRGBA(bgr).ToJasc()) }
Output: 232 8 80
type RGBATile ¶
type RGBATile struct { Type TileType Pixels [TilePixCount]RGBA32 }
RGBATile represents a tile with pixels in RGBA32 format. Each pixel is stored as a value of type RGBA32.
func (*RGBATile) IsBGREquivalentTo ¶
IsBGREquivalentTo checks if two RGBATiles are equivalent after conversion to BGR15 format.
type TerrainType ¶
type TerrainType int
const ( TerrainNormal TerrainType = iota TerrainGrass TerrainWater TerrainWaterfall )
type TileType ¶
type TileType int
TileType describes the different variants of a tile. These types are general and can apply to any kind of tile.
const ( // A Layered tile is the standard tile type for a tile from one of the layer // sheets in 'compile tileset' mode. Layered tiles are the building blocks // of a Metatile. Layered TileType = iota // A Free tile is a non-layered tile from one of the spritesheets in // 'compile spritesheet' mode. Free // An Anim tile is an animated tile (from the 'anim' folder). Anim // A Primer tile is a special kind of tile that isn't actually present in // any of the input PNGs. Rather, it's constructed from one of the palette // primer files, if present. Primer )