Documentation
¶
Overview ¶
Package mods contains helpers for working with Factorio mods.
Index ¶
- Constants
- func Categories() []string
- type Cache
- func (c *Cache) Clean() error
- func (c *Cache) Close() error
- func (c *Cache) DisableProgressBar()
- func (c *Cache) DownloadURL(ctx context.Context, name string) (*url.URL, error)
- func (c *Cache) EnableProgressBar()
- func (c *Cache) Get(ctx context.Context, name, username, token string) (cachedPath string, err error)
- func (c *Cache) LatestVersion(ctx context.Context, name string) (*semver.Version, error)
- func (c *Cache) ModDir() (string, error)
- func (c *Cache) Mods() ([]M, error)
- func (c *Cache) Pull(ctx context.Context) error
- func (c *Cache) Search(ctx context.Context, searchTerm string, options ...SearchOption) ([]M, error)
- func (c *Cache) Update(ctx context.Context) error
- type Category
- type Dependencies
- type Dependency
- type DependencyMode
- type DependencyVersion
- type Info
- type M
- type SearchOption
- type Version
Constants ¶
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 ¶
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 (*Cache) DisableProgressBar ¶
func (c *Cache) DisableProgressBar()
func (*Cache) DownloadURL ¶
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 ¶
LatestVersion returns the latest released version of a mod. The mod name must be an exact match.
func (*Cache) ModDir ¶
ModDir returns the directory where mods should be downloaded to. The directory will be created before ModDir returns.
func (*Cache) Pull ¶
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.
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 ¶
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)
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 (*M) FindInstalledVersions ¶
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.