mods

package
v0.0.0-...-f1ee3f2 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2025 License: MPL-2.0 Imports: 22 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) DownloadURL

func (c *Cache) DownloadURL(ctx context.Context, name string) (*url.URL, error)

DownloadURL returns the URL for retrieving a mod. The mod's name must be an exact match.

If no mods can be found by name, the cache can be updated by calling Cache.Update.

func (*Cache) EnableProgressBar

func (c *Cache) EnableProgressBar()

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

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, name, username, token string) (cachedPath string, err error)

Get downloads the latest version of a mod to the cache, and returns the absolute path to the cached mod file.

If the mod needs to be downloaded from the Factorio Mod Portal, the user's username and token must be provided. The username and token can be retrieved with github.com/nesv/factorio-tools/userdata.LoadPlayerData.

func (*Cache) LatestVersion

func (c *Cache) LatestVersion(ctx context.Context, name string) (*semver.Version, error)

LatestVersion returns the latest released version of a mod. The mod name must be an exact match.

func (*Cache) ModDir

func (c *Cache) ModDir() (string, error)

ModDir returns the directory where mods should be downloaded to. The directory will be created before ModDir returns.

func (*Cache) Mods

func (c *Cache) Mods() ([]M, error)

Mods returns a listing of all mods that are saved in the cache.

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 Dependencies

type Dependencies struct {
	Required  []Dependency
	Optional  []Dependency
	Conflicts []Dependency
}

type Dependency

type Dependency struct {
	Name    string
	Version *DependencyVersion
	Mode    DependencyMode
}

func ParseDependency

func ParseDependency(s string) (Dependency, error)

func (Dependency) String

func (d Dependency) String() string

type DependencyMode

type DependencyMode uint

Mode indicates a mod dependency's "mode".

const (
	ModeRequired          DependencyMode = 1 << iota // Required dependency.
	ModeOptional                                     // Optional dependency.
	ModeHidden                                       // Hidden, optional dependency.
	ModeConflict                                     // This dependency conflicts with the mod.
	ModeNoAffectLoadOrder                            // Dependency does not affect load order.
)

func (DependencyMode) String

func (d DependencyMode) String() string

type DependencyVersion

type DependencyVersion struct {
	// Op is the equality operator indicating how Version should be
	// interpreted.
	Op string

	// Version of the dependency.
	Version *semver.Version
}

func (DependencyVersion) String

func (d DependencyVersion) String() string

type Info

type Info struct {
	Name            string   `json:"name"`
	RawVersion      string   `json:"version"`
	Title           string   `json:"title"`
	Description     string   `json:"description"`
	Author          string   `json:"author"`
	Contact         string   `json:"contact"`
	Homepage        string   `json:"homepage"`
	FactorioVersion string   `json:"factorio_version"`
	RawDependencies []string `json:"dependencies"`
}

Info holds the data loaded from a mod's info.json file.

func LoadInfo

func LoadInfo(zipPath string) (Info, error)

LoadInfo loads mod information from the "info.json" file from a ZIP archive containing a mod.

func (Info) Dependencies

func (i Info) Dependencies() (Dependencies, error)

func (Info) Version

func (i Info) Version() (*semver.Version, error)

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.

func (*M) FindInstalledVersions

func (m *M) FindInstalledVersions(installDir string) error

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
	Info                Info
}

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