finch

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2025 License: Apache-2.0 Imports: 17 Imported by: 6

Documentation

Index

Constants

View Source
const (
	PngAssetType  = "png"
	JpgAssetType  = "jpg"
	JpegAssetType = "jpeg"
	BmpAssetType  = "bmp"
)
View Source
const MaxFixedFrames = 5

Variables

View Source
var (
	ErrAssetManagerNotFound    = errors.New("asset manager not found")
	ErrAssetManagerConflict    = errors.New("asset manager conflict")
	ErrAssetManagerNil         = errors.New("asset manager is nil")
	ErrAssetFilesystemConflict = errors.New("asset filesystem conflict")
	ErrAssetFilesystemNil      = errors.New("asset filesystem is nil")
	ErrAssetInvalidType        = errors.New("asset has invalid type")
	ErrAssetTypeMismatch       = errors.New("asset type mismatch")
	ErrAssetNotLoaded          = errors.New("asset not loaded")
	ErrAssetIsLoaded           = errors.New("asset is already loaded")
	ErrAssetIsLoading          = errors.New("asset is currently loading")
	ErrAssetTypeEmpty          = errors.New("asset type is empty")
	ErrAssetRootEmpty          = errors.New("asset root is empty")
)

Functions

func Exit

func Exit()

func GetAsset

func GetAsset[T any](file AssetFile) (T, error)

func GetImage added in v0.0.6

func GetImage(file AssetFile) (*ebiten.Image, error)

func HasAssetTypeSupport added in v0.0.2

func HasAssetTypeSupport(t AssetType) bool

func LoadAssets

func LoadAssets(files ...AssetFile) error

func MustGetAsset

func MustGetAsset[T any](file AssetFile) T

func MustGetImage added in v0.0.6

func MustGetImage(file AssetFile) *ebiten.Image

func MustLoadAssets

func MustLoadAssets(files ...AssetFile)

func MustUnloadAssets

func MustUnloadAssets(files ...AssetFile)

func RegisterAssetFilesystem

func RegisterAssetFilesystem(root AssetRoot, filesystem fs.FS) error

func RegisterAssetImporter added in v0.0.7

func RegisterAssetImporter(manager *AssetImporter) error

func RegisterImageAssetImport added in v0.0.8

func RegisterImageAssetImport()

func Run

func Run(a *App) error

func UnloadAssets

func UnloadAssets(files ...AssetFile) error

Types

type App

type App struct {
	DrawFn        DrawFunc
	LayoutFn      LayoutFunc
	UpdateFn      UpdateFunc
	FixedUpdateFn UpdateFunc
	LateUpdateFn  UpdateFunc
	StartupFn     StartupFunc
	ShutdownFn    ShutdownFunc
	// contains filtered or unexported fields
}

func NewApp

func NewApp() *App

func NewAppWithContext

func NewAppWithContext(ctx context.Context) *App

func (*App) Context

func (a *App) Context() Context

func (*App) Draw

func (a *App) Draw(screen *ebiten.Image)

func (*App) Layout

func (a *App) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

func (*App) Update

func (a *App) Update() error

func (*App) WithDraw

func (a *App) WithDraw(drawFunc DrawFunc) *App

func (*App) WithFixedUpdate

func (a *App) WithFixedUpdate(fixedUpdateFunc UpdateFunc) *App

func (*App) WithLateUpdate

func (a *App) WithLateUpdate(lateUpdateFunc UpdateFunc) *App

func (*App) WithLayout

func (a *App) WithLayout(layoutFunc LayoutFunc) *App

func (*App) WithLogger

func (a *App) WithLogger(logger *slog.Logger) *App

func (*App) WithShutdown

func (a *App) WithShutdown(shutdownFunc ShutdownFunc) *App

func (*App) WithStartup

func (a *App) WithStartup(startupFunc StartupFunc) *App

func (*App) WithUpdate

func (a *App) WithUpdate(updateFunc UpdateFunc) *App

func (*App) WithWindow

func (a *App) WithWindow(window *Window) *App

type AssetAllocator

type AssetAllocator func(file AssetFile, filedata []byte) (any, error)

AssetAllocator is a function that takes raw asset data and converts it into a usable form.

type AssetDeallocator

type AssetDeallocator func(file AssetFile, data any) error

AssetDeallocator is a function that takes a loaded asset and frees its resources.

type AssetFile

type AssetFile string

AssetFile is a handle to an asset file and its associated type and data.

func (AssetFile) Get

func (f AssetFile) Get() (any, error)

func (AssetFile) Load

func (f AssetFile) Load() error

func (AssetFile) MustGet

func (f AssetFile) MustGet() any

func (AssetFile) MustLoad

func (f AssetFile) MustLoad()

func (AssetFile) MustUnload

func (f AssetFile) MustUnload()

func (AssetFile) Path

func (f AssetFile) Path() string

Path returns the file path of the asset.

func (AssetFile) Root

func (f AssetFile) Root() AssetRoot

Root returns the root directory of the asset file.

func (AssetFile) Type

func (f AssetFile) Type() AssetType

Type returns the asset type based on the file extension.

func (AssetFile) Unload

func (f AssetFile) Unload() error

type AssetImporter added in v0.0.8

type AssetImporter struct {
	ProcessAssetFile AssetAllocator
	CleanupAssetFile AssetDeallocator
	AssetTypes       []AssetType
}

AssetImporter manages allocation and deallocation of a specific asset types.

type AssetRoot

type AssetRoot string

AssetRoot represents the root directory of an asset file.

func (AssetRoot) IsValid

func (r AssetRoot) IsValid() error

func (AssetRoot) String

func (r AssetRoot) String() string

type AssetType

type AssetType string

AssetType represents the type of an asset, typically derived from its file extension.

func (AssetType) IsValid

func (t AssetType) IsValid() error

func (AssetType) String

func (t AssetType) String() string

type Context

type Context interface {
	Context() context.Context
	Screen() *Screen
	Time() *Time
	Logger() *slog.Logger
	SetLogger(logger *slog.Logger) Context
	Get(key ContextKey) any
	Set(key ContextKey, value any) Context
}

func NewContext

func NewContext(ctx context.Context, logger *slog.Logger, screen *Screen, time *Time) Context

type ContextKey

type ContextKey string

type DrawFunc

type DrawFunc func(ctx Context, screen *ebiten.Image)

type LayoutFunc

type LayoutFunc func(ctx Context, outsideWidth, outsideHeight int) (screenWidth, screenHeight int)

type Screen

type Screen struct {
	// contains filtered or unexported fields
}

Screen represents the game's screen with width and height.

Game logic should reference this to get the current screen dimensions.

func NewScreen

func NewScreen(width, height int, scale float64, fullscreen bool) *Screen

func (*Screen) Height

func (s *Screen) Height() int

func (*Screen) IsFullscreen

func (s *Screen) IsFullscreen() bool

func (*Screen) RenderScale

func (s *Screen) RenderScale() float64

func (*Screen) SetSize

func (s *Screen) SetSize(width, height int)

func (*Screen) TargetHeight

func (s *Screen) TargetHeight() int

func (*Screen) TargetWidth

func (s *Screen) TargetWidth() int

func (*Screen) Width

func (s *Screen) Width() int

type ShutdownFunc

type ShutdownFunc func(ctx Context)

type StartupFunc

type StartupFunc func(ctx Context)

type Time

type Time struct {
	// contains filtered or unexported fields
}

func NewTime

func NewTime(targetFPS float64) *Time

func (*Time) DeltaMilli

func (t *Time) DeltaMilli() float64

func (*Time) DeltaSeconds

func (t *Time) DeltaSeconds() float64

func (*Time) FixedFrames

func (t *Time) FixedFrames() int

func (*Time) FixedMilli

func (t *Time) FixedMilli() float64

func (*Time) FixedSeconds

func (t *Time) FixedSeconds() float64

type UpdateFunc

type UpdateFunc func(ctx Context)

type Window

type Window struct {
	Title        string
	ResizingMode ebiten.WindowResizingModeType
	Width        int
	Height       int
	Fullscreen   bool
	RenderScale  float64
}

Jump to

Keyboard shortcuts

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