datatable

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package datatable reads UE5 DataTable exports — the canonical designer-authored tabular format. Supports both JSON exports (one object per row, keyed by row name) and CSV exports (header row + body).

Callers declare a Go struct matching the DataTable's row schema; the parser unmarshals each row into a typed Table[T]. The optional Watcher reloads on file changes for hot-reload during dev.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedJSON = errors.New("datatable: malformed JSON export")
	ErrMalformedCSV  = errors.New("datatable: malformed CSV export")
	ErrMissingRowKey = errors.New("datatable: row missing key column")
)

Errors surfaced by the parsers.

Functions

This section is empty.

Types

type Table

type Table[T any] struct {
	Rows map[string]T
	// contains filtered or unexported fields
}

Table is a typed view over a DataTable export.

func ParseCSV

func ParseCSV[T any](r io.Reader) (*Table[T], error)

ParseCSV decodes the CSV variant of a DataTable export. The first column is the row key; remaining columns map to fields on T by header name (respecting `csv:"FieldName"` tag, then `json:"…"` tag, then exported field name).

func ParseJSON

func ParseJSON[T any](r io.Reader) (*Table[T], error)

ParseJSON decodes UE5's JSON DataTable export. UE5 emits an array of objects where each object's `Name` field is the row key (when "Export As: JSON" is used from the editor). To stay compatible with our own export pipeline (§71), the parser also accepts the simpler `{ "RowName": { ...row fields... } }` map shape.

func (*Table[T]) Each

func (t *Table[T]) Each(fn func(name string, row T) bool)

Each iterates rows in insertion order, invoking fn until it returns false.

func (*Table[T]) Get

func (t *Table[T]) Get(name string) (T, bool)

Get returns the row by name plus whether it existed.

func (*Table[T]) Len

func (t *Table[T]) Len() int

Len is the row count.

type Watcher

type Watcher[T any] struct {
	// contains filtered or unexported fields
}

Watcher polls a file for modification-time changes and reparses on change. Suited for dev hot-reload, not production: production should rely on §46 kit/content packs (immutable + hashed).

func Watch

func Watch[T any](path string, parser func(io.Reader) (*Table[T], error), interval time.Duration) (*Watcher[T], error)

Watch starts a Watcher on `path`. The file is parsed eagerly; the returned Watcher polls every `interval` for changes (defaults to 500ms when zero). Call Close to stop polling.

func (*Watcher[T]) Close

func (w *Watcher[T]) Close()

Close stops the watcher goroutine.

func (*Watcher[T]) Current

func (w *Watcher[T]) Current() *Table[T]

Current returns the most recently parsed Table.

func (*Watcher[T]) OnChange

func (w *Watcher[T]) OnChange(fn func(*Table[T]))

OnChange registers fn to be invoked on every successful reload.

Jump to

Keyboard shortcuts

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