pck

package
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DetectSpritesheet

func DetectSpritesheet(path, root string) (name string, w, h int, ok bool)

DetectSpritesheet parses name of texture into spritesheet if name is in format:

name_width_height.ext

where width hight are parameters of one sheet cell

func Pack

func Pack(data Data) (width, height int)

Pack packs rectangles in reasonable way, it tries to achieve size efficiency not speed

Types

type Data

type Data []PicData

Data is a standard Vector type with utility methods

func (*Data) AddImages

func (d *Data) AddImages(paths ...string) error

NPicData creates Slice of PicData from texture paths, it flips the textures so they are not upside down

func (*Data) AddMarkdown

func (v *Data) AddMarkdown(m *txt.Markdown)

AddMarkdown adds markdown font textures into Data

func (*Data) BiInsert

func (v *Data) BiInsert(value PicData, cmp func(a, b PicData) uint8)

BiInsert inserts inserts value in a way that keeps vec sorted, binary search is used to determinate where to insert

func (Data) BiSearch

func (v Data) BiSearch(value PicData, cmp func(a, b PicData) uint8) (int, bool)

BiSearch performs a binary search on Ves assuming it is sorted. cmp consumer should return 0 if a == b equal, 1 if a > b and 2 if b > a, even if value wos not found it returns it returns closest index and false. If Data is empty -1 and false is returned

func (*Data) Clear

func (v *Data) Clear()

Clear is equivalent to Truncate(0)

func (Data) Clone

func (v Data) Clone() Data

Clone creates new Data copies content of v to it and returns it

func (*Data) Extend

func (v *Data) Extend(amount int)

Extend extends vec size by amount so then len(Data) = len(Data) + amount

func (*Data) Filter

func (v *Data) Filter(filter func(e PicData) bool)

Filter leaves only elements for with filter returns true

func (Data) Find

func (v Data) Find(find func(e PicData) bool) (idx int, res PicData)

Find returns first element for which find returns true along with index, if there is none, index equals -1

func (Data) ForEach

func (v Data) ForEach(con func(i int, e PicData) PicData)

ForEach is a standard foreach method. Its shortcut for modifying all elements

func (*Data) Insert

func (v *Data) Insert(idx int, val PicData)

Insert inserts value to given index

func (*Data) InsertSlice

func (v *Data) InsertSlice(idx int, val []PicData)

InsertSlice inserts slice to given index

func (Data) Last

func (v Data) Last() PicData

Last returns last element of slice

func (Data) Len

func (v Data) Len() int

Len implements VertexData interface

func (Data) Move

func (v Data) Move(old, new int)

Move moves value from old to new shifting elements in between

func (*Data) Pop

func (v *Data) Pop() PicData

Pop removes last element

func (*Data) PopFront

func (v *Data) PopFront() PicData

PopFront removes first element and returns it

func (*Data) Remove

func (v *Data) Remove(idx int) (val PicData)

Remove removes element and returns it

func (*Data) RemoveSlice

func (v *Data) RemoveSlice(start, end int)

RemoveSlice removes sequence of slice

func (Data) Reverse

func (v Data) Reverse()

Reverse reverses content of slice

func (Data) Rewrite

func (v Data) Rewrite(o Data, idx int)

Rewrite revrites elements from index to o values

func (Data) Sort

func (v Data) Sort(comp func(a, b PicData) bool)

Sort is quicksort for Data, because this is part of a template comp function is necessary

func (Data) Swap

func (v Data) Swap(a, b int)

Swap swaps two elements

func (*Data) Truncate

func (v *Data) Truncate(l int)

Truncate in comparison to truncating by bracket operator also sets all forgoten elements to default value, witch is useful if this is slice of pointers Data will have length you specify

func (*Data) UClear

func (v *Data) UClear()

UClear does not care about memory leaks, it just sets length to 0

type PicData

type PicData struct {
	Name string

	Img draw.Image
	// contains filtered or unexported fields
}

PicData is data related to picture

type Sheet

type Sheet struct {
	Data

	Root    string
	Pic     *image.NRGBA
	Regions map[string]mat.AABB
}

Sheet contains sprite sheet and Regions

func NSheet

func NSheet(root string, paths ...string) (sh *Sheet, err error)

NSheet creates new sheet containing textures from given paths

func (*Sheet) Batch added in v0.2.8

func (s *Sheet) Batch() ggl.Batch

Batch returns batch for this sheet that can be used with sprites

func (*Sheet) Pack

func (s *Sheet) Pack()

Pack takes all Data in sheet and translates it into one packed image and regions, regarding the current Root the names will be modified, for example if root is "root" then "something/root/anything.png" will be saved under kay with value "anything" into s.Regions

func (*Sheet) Sprite added in v0.2.8

func (s *Sheet) Sprite(name string) (ggl.Sprite, bool)

Sprite returns sprite for region of given name

Jump to

Keyboard shortcuts

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