models

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package models defines all the types that Porytiles understands.

Index

Examples

Constants

View Source
const Opaque uint8 = 255

Opaque represents an 8-bit alpha value of 255, indicating full opacity for a Rgba32 Alpha channel.

View Source
const PalSize int = 16

PalSize defines the size of a palette. On the GBA, palettes contain 16 colors.

TilePixCount is the total number of pixels in a Pokémon decomps GBA tile. In this case, it will be 8x8 = 64.

View Source
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.

View Source
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

func TilesPerMetatile(tripleLayer bool) int

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

func RGBAToBGR(rgba RGBA32) BGR15

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

func (bgr BGR15) Blue() uint8

Blue returns the blue channel value of the given BGR15, scaled up to an 8-bit value.

func (BGR15) Green

func (bgr BGR15) Green() uint8

Green returns the green channel value of the given BGR15, scaled up to an 8-bit value.

func (BGR15) Red

func (bgr BGR15) Red() uint8

Red returns the red 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

func UniformGBATile(value uint8) GBATile

UniformGBATile generates a GBATile with all pixels set to the given value.

func (*GBATile) PixelAt

func (t *GBATile) PixelAt(row, col int) uint8

PixelAt retrieves the color index pixel at the specified row and column in the tile.

type InsertRGBAOpts

type InsertRGBAOpts struct {
	Transparent     RGBA32
	SourceRGB       *map[BGR15]RGBA32
	Engine          *diagnostics.DiagnosticEngine
	PixelRow        int
	PixelCol        int
	EmitDiagnostics bool
}

type LayerType

type LayerType int
const (
	LayerNormal LayerType = iota
	LayerCovered
	LayerSplit
	LayerTriple
)

type Metatile

type Metatile struct {
	Subtiles []MetatileEntry
	Attr     Attributes
}

type MetatileEntry

type MetatileEntry struct {
	TileIndex int
	PalIndex  int
	HFlip     bool
	VFlip     bool
}

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 PorymapAnimFrame struct {
	Tiles []GBATile
	Name  string
}

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

type PorytilesAnimFrame struct {
	Tiles []RGBATile
	Name  string
}

func (*PorytilesAnimFrame) Size

func (p *PorytilesAnimFrame) Size() int

Size returns the size of the Tiles slice for this PorytilesAnimFrame.

type PorytilesTileset

type PorytilesTileset struct {
	Tiles       []RGBATile
	TripleLayer bool
}

A PorytilesTileset is a tileset in Porytiles format.

type RGBA32

type RGBA32 struct {
	Red   uint8
	Green uint8
	Blue  uint8
	Alpha uint8
}

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

func BGRToRGBA(bgr BGR15) RGBA32

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

func (RGBA32) ToJasc

func (rgba RGBA32) ToJasc() string

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

func (t *RGBATile) IsBGREquivalentTo(other *RGBATile) bool

IsBGREquivalentTo checks if two RGBATiles are equivalent after conversion to BGR15 format.

func (*RGBATile) PixelAt

func (t *RGBATile) PixelAt(row, col int) RGBA32

PixelAt retrieves the RGBA32 pixel at the specified row and column in the tile.

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
)

Jump to

Keyboard shortcuts

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