tqw

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tqw has functions for loading game data using the TQW (TunaQuest Worlds) game data file format, a TOML-based format that is used to define game worlds for the engine to run.

Index

Constants

View Source
const MaxManifestRecursionDepth = 32

Variables

View Source
var (
	// ErrManifestEmpty is the error returned when a manifest file is read
	// successfully but specifies no additional files to load.
	ErrManifestEmpty = errors.New("does not list any valid files to include")

	// ErrManifestStackOverflow is the error returned when the recusion level of
	// MaxManifestRecrusionDepth is reached and an additional Manifest is then
	// specified, which would cause recursion to go deeper.
	ErrManifestStackOverflow = errors.New("too many manifests deep")

	// ErrManifestCircularRef is the error returned when a manifest specifies any
	// series of files that with their own manifests refer back to the original
	// manifest, and therefore cannot be followed.
	ErrManifestCircularRef = errors.New("manifest inclusion chain refers back to itself")
)

Functions

This section is empty.

Types

type FileInfo

type FileInfo struct {
	Format string `toml:"format"`
	Type   string `toml:"type"`
}

FileInfo contains the essential information all TQW format files must contain. It can be obtained from a file by reading it into memory and calling ParseFileInfo on the bytes.

func ScanFileInfo

func ScanFileInfo(data []byte) (FileInfo, error)

ScanFileInfo takes the given data bytes of bytes and attempts to read the TQW format common header info from it. The bytes are read up to the first instance of a table definition header and those bytes are parsed for the info. If there is an error reading the info, returns a non-nil error.

type Manifest

type Manifest struct {
	Files []string
}

Manifest contains data loaded from one or more TQW Manifest files.

func LoadManifestFile

func LoadManifestFile(path string) (manif Manifest, err error)

LoadManifestFile loads manifest data from a TQW file.

type WorldData

type WorldData struct {
	// Rooms has every room in the World, pre-loaded with NPCs and Items and
	// ready for immediate use.
	Rooms map[string]*game.Room

	// Start is the room the character starts in.
	Start string

	// Flags is the flags that the game starts with.
	Flags map[string]string
}

WorldData contains data loaded from one or more TQW World Data files.

func LoadResourceBundle

func LoadResourceBundle(path string) (WorldData, error)

LoadResourceBundle loads a world up from the given TQW file. The file's type is auto-detected and decoding is handled appropriately; the type can either be "DATA" type or "MANIFEST" type; if it's manifest type, the files listed in it relative to it will also be loaded. All files included will be combined into one single set of data before being checked, and if a manifest is encountered, all files in it are recursively included.

In the future, once 'resource packs' are available (honestly just tarball or zip files containing at least one manifest file at the root), setting path to it will result in reading the entire archive starting with the root manifest.

func LoadWorldDataFile

func LoadWorldDataFile(path string) (world WorldData, err error)

LoadWorldDataFile loads a world from a world definition

Jump to

Keyboard shortcuts

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