app

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package app provides the engine's top-level App, which implements ebiten.Game so games do not have to. An App owns the window, the run loop, frame timing, the debug watchdog, screenshot capture, and exit handling, and embeds a scene.Manager. Games register scenes and, optionally, set OnUpdate for global per-frame logic.

Index

Constants

This section is empty.

Variables

View Source
var ErrExit = errors.New("application exit requested")

ErrExit is returned from Run when the application exits normally, either because a game requested exit or the configured run-for duration elapsed.

Functions

func SaveScreenshot

func SaveScreenshot(img *ebiten.Image, filePath string) error

SaveScreenshot encodes img as a PNG at filePath, creating parent directories.

Types

type App

type App struct {

	// OnUpdate, when set, runs once per frame before scenes update. Games use
	// it for global input and logic (menus, pause, hotkeys) without
	// implementing ebiten.Game. Returning a non-nil error stops the loop.
	OnUpdate func(duration time.Duration) error
	// contains filtered or unexported fields
}

App is the engine's top-level game object. It implements ebiten.Game so that games never have to: games register scenes on the Manager and optionally set OnUpdate for global per-frame logic.

func New

func New(settings *Settings) *App

New returns an App driven by the given settings, with an empty scene Manager.

func (*App) Draw

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

Draw implements ebiten.Game.

func (*App) Layout

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

Layout implements ebiten.Game.

func (*App) Manager

func (a *App) Manager() *scene.Manager

Manager returns the App's scene Manager for registering and controlling scenes.

func (*App) RequestExit

func (a *App) RequestExit()

RequestExit asks the app to exit cleanly at the end of the current frame.

func (*App) Run

func (a *App) Run() error

Run applies settings, sets up the window, initializes scenes, and runs the Ebiten loop. It returns nil on a clean exit.

func (*App) Update

func (a *App) Update() error

Update implements ebiten.Game.

type CameraSettings

type CameraSettings struct {
	MoveSpeed float64 `toml:"move_speed"`
	ZoomSpeed float64 `toml:"zoom_speed"`
}

CameraSettings holds default pan/zoom speeds for the camera controller. The engine does not consume these directly; a game applies them to its CameraController.

type DebugSettings

type DebugSettings struct {
	Enabled     bool `toml:"enabled"`
	HTTPEnabled bool `toml:"http_enabled"`
	HTTPPort    int  `toml:"http_port"`
}

DebugSettings configures debug mode and the debug HTTP server.

type LogSettings

type LogSettings struct {
	Level string `toml:"level"`
}

LogSettings configures logging. Consumed by a game at startup.

type RenderSettings

type RenderSettings struct {
	UsePlaceholderSpriteImages bool `toml:"use_placeholder_sprite_images"`
}

RenderSettings holds render toggles.

type RunSettings

type RunSettings struct {
	For config.Duration `toml:"for"`
}

RunSettings configures run duration. A zero For means run until closed.

type ScreenshotSettings

type ScreenshotSettings struct {
	Path      string          `toml:"path"`
	Delay     config.Duration `toml:"delay"`
	Frequency config.Duration `toml:"frequency"`
}

ScreenshotSettings configures automatic screenshot capture.

type Settings

type Settings struct {
	Window     WindowSettings     `toml:"window"`
	Camera     CameraSettings     `toml:"camera"`
	Debug      DebugSettings      `toml:"debug"`
	Screenshot ScreenshotSettings `toml:"screenshot"`
	Run        RunSettings        `toml:"run"`
	Log        LogSettings        `toml:"log"`
	Render     RenderSettings     `toml:"render"`
}

Settings is the engine's configuration, loaded from layered TOML and flags.

func LoadSettings

func LoadSettings(localPath string, overrides []string) (*Settings, error)

LoadSettings loads engine settings from the embedded defaults, an optional local TOML file, and section.key=value overrides.

func (*Settings) Apply

func (s *Settings) Apply()

Apply applies the settings that control engine-global toggles.

func (*Settings) RegisterFlags

func (s *Settings) RegisterFlags(fs *flag.FlagSet)

RegisterFlags binds the engine's command-line flags to the settings, using the current values as defaults. Call this after LoadSettings and before parsing, so an explicitly-set flag overrides the loaded value.

type WindowSettings

type WindowSettings struct {
	Title      string `toml:"title"`
	Width      int    `toml:"width"`
	Height     int    `toml:"height"`
	Fullscreen bool   `toml:"fullscreen"`
}

WindowSettings configures the OS window. A zero Width or Height means the engine uses the monitor size and goes fullscreen.

Jump to

Keyboard shortcuts

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