levelpack

package
v0.0.0-...-79996cc Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2023 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package levelpack handles ZIP archives for level packs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListFiles

func ListFiles() ([]string, error)

ListFiles lists all the discoverable levelpack files, starting from the game's built-ins all the way to user levelpacks.

func LoadAllAvailable

func LoadAllAvailable() ([]string, map[string]*LevelPack, error)

LoadAllAvailable loads every levelpack visible to the game. Returns the sorted list of filenames as from ListFiles, plus a deeply loaded hash map associating the filenames with their data.

Types

type Level

type Level struct {
	UUID     string `json:"uuid"`
	Title    string `json:"title"`
	Author   string `json:"author"`
	Filename string `json:"filename"`
}

Level holds metadata about the levels in the levelpack.

type LevelPack

type LevelPack struct {
	Title       string    `json:"title"`
	Description string    `json:"description"`
	Author      string    `json:"author"`
	Created     time.Time `json:"created"`

	// Cached metadata about the (displayed) levels.
	Levels []Level `json:"levels"`

	// Number of levels unlocked by default.
	// 0 = all levels unlocked
	FreeLevels int `json:"freeLevels"`

	// The loaded zip file for reading an existing levelpack.
	Zipfile *zip.Reader `json:"-"`

	// A reference to the original filename, not stored in json.
	Filename string `json:"-"`

	// Signature to allow free versions of the game to load embedded
	// custom doodads inside this levelpack for its levels.
	Signature []byte `json:"signature,omitempty"`
}

LevelPack describes the contents of a levelpack file.

func LoadFile

func LoadFile(filename string) (*LevelPack, error)

LoadFile reads a .levelpack zip file.

func (LevelPack) GetFile

func (l LevelPack) GetFile(filename string) ([]byte, error)

GetFile returns file data from inside the loaded zipfile of a levelpack.

This also implements the Embeddable interface.

func (LevelPack) GetJSON

func (l LevelPack) GetJSON(v interface{}, filename string) error

GetJSON loads a JSON file from the zipfile and marshals it into your struct.

func (LevelPack) GetLevel

func (l LevelPack) GetLevel(filename string) (*level.Level, error)

GetLevel returns a parsed Level object from a file inside the zipfile.

func (LevelPack) ListFiles

func (l LevelPack) ListFiles(prefix string) []string

ListFiles returns the files in the zipfile that match the prefix given.

func (LevelPack) WriteFile

func (l LevelPack) WriteFile(filename string) error

WriteFile saves the metadata to a .json file on disk.

func (LevelPack) WriteZipfile

func (l LevelPack) WriteZipfile(filename string) error

WriteZipfile saves a levelpack back into a zip file.

Jump to

Keyboard shortcuts

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