mods

package
v0.0.0-...-e5098e4 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package mods contains helpers for working with Factorio mods.

Index

Constants

View Source
const (
	NoCategory    Category = "no-category"
	Content                = "content"       // Mods introducing new content into the game.
	Overhaul               = "overhaul"      // Large total conversion mods.
	Tweaks                 = "tweaks"        // Small changes concerning balance, gameplay, or graphics.
	Utilities              = "utilities"     // Providing the player with new tools or adjusting the game interface, without fundamentally changing gameplay.
	Scenarios              = "scenarios"     // Scenarios, maps, puzzles.
	ModPacks               = "mod-packs"     // Collections of mods with tweaks to make them work together.
	Localizations          = "localizations" // Translations for other mods.
	Internal               = "internal"      // Lua libraries for use by other mods and submods that are parts of a larger mod.
)

Variables

This section is empty.

Functions

func Categories

func Categories() []string

Categories returns a list of all available categories.

Types

type Cache

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

Cache is a local database that is used for caching information about Factorio mods.

func OpenCache

func OpenCache(dir string) (*Cache, error)

func (*Cache) Clean

func (c *Cache) Clean() error

Clean removes all temporary mod list pulls from the cache directory.

func (*Cache) Close

func (c *Cache) Close() error

func (*Cache) DisableProgressBar

func (c *Cache) DisableProgressBar()

func (*Cache) EnableProgressBar

func (c *Cache) EnableProgressBar()

EnableProgressBar prints a progress bar to STDERR for methods like Cache.Pull, and Cache.Update.

func (*Cache) Pull

func (c *Cache) Pull(ctx context.Context) error

Pull retrieves the mod list from the [Mods portal API], and caches the results, returning the path to the file holding the partially-processed results. The file holding the results contains a stream of mod entries, with each entry being its own JSON object. Use encoding/json.Decoder to read this file.

To update the cache database, call Cache.Update afterwards.

func (*Cache) Search

func (c *Cache) Search(ctx context.Context, searchTerm string, options ...SearchOption) ([]M, error)

Search returns a list of mods matching the search term, with zero or more of the given options applied.

Search will return a non-nil error if the search term is an empty string, or if there is an error with any of the provided options.

func (*Cache) Update

func (c *Cache) Update(ctx context.Context) error

type Category

type Category string

Category is used to describe a mod. Mods can only belong to a single category.

type M

type M struct {
	Name    string `json:"name"`
	Enabled bool   `json:"enabled"`

	// All of the currently-installed versions of the mod, sorted in
	// ascending order so the latest version is the last element in the
	// slice.
	Versions []Version `json:"-"`

	// The time at which the latest version was released.
	ReleasedAt time.Time `json:"-"`

	// A brief summary of the mod.
	Summary string `json:"-"`

	// The mod's category.
	Category string `json:"-"`
}

func Load

func Load(installationDir string) ([]M, error)

Load collects all of the mods currently installed to the installation directory.

type SearchOption

type SearchOption func(*searchOptions) error

SearchOption is a functional option that can be passed to Cache.Search to adjust how searching is handled.

func NameOnly

func NameOnly() SearchOption

NameOnly restricts the mod search to only match on a mod's name. By default, a mod's name and summary will be considered.

func RegexpTerm

func RegexpTerm() SearchOption

RegexpTerm tells Cache.Search to treat the search term as a regular expression. When this option is provided, the search term will be compiled by regexp.Compile to ensure it is valid.

func SortByDate

func SortByDate() SearchOption

SortByDate sorts the results by the date the latest version of the mod was released, in descending order (most-recently-released mod first).

func WithCategories

func WithCategories(categories ...Category) SearchOption

WithCategories limits the results of a search to only return mods with the specified categories.

type Version

type Version struct {
	Major, Minor, Patch int
}

func (Version) IsZero

func (v Version) IsZero() bool

func (Version) String

func (v Version) String() string

Jump to

Keyboard shortcuts

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