Documentation ¶
Overview ¶
Package gamepkg is a package that helps locate, validate, and modify game package imports.
Index ¶
- Constants
- type Pkg
- func AllPackages(inputs []string, optionalBasePath string) ([]*Pkg, error)
- func New(importOrPath string, optionalBasePath string) (*Pkg, error)
- func NewFromImport(importPath string) (*Pkg, error)
- func NewFromPath(path string, optionalBasePath string) (*Pkg, error)
- func Packages(inputs []string, optionalBasePath string) ([]*Pkg, map[string]error)
- func (p *Pkg) AbsolutePath() string
- func (p *Pkg) ClientFolder() string
- func (p *Pkg) EnsureDir(relPath string) error
- func (p *Pkg) Has(relPath string) bool
- func (p *Pkg) Import() string
- func (p *Pkg) Name() string
- func (p *Pkg) ReadOnly() bool
- func (p *Pkg) RemoveDirIfEmpty(relPath string) error
- func (p *Pkg) RemoveFile(relPath string) error
- func (p *Pkg) WriteFile(relPath string, contents []byte, overwrite bool) error
Constants ¶
const RandMagicComment = "boardgame:assert(rand_use_deterministic)"
RandMagicComment is the string the tool looks for. If this comment is included in a source file, then pkg will not error will even if that file does import math.Rand(). This comment asserts that the package is using math/rand for some reason other than game logic, because game logic is supposed to use state.Rand() in order to be predictable.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pkg ¶
type Pkg struct {
// contains filtered or unexported fields
}
Pkg represents a Package that may or may not be a GamePkg.
func AllPackages ¶
AllPackages is a wrapper around Packages that will return a single error and no packages if any of the packages was invalid.
func New ¶
New is a wrapper around NewFromImport and NewFromPath. First, it tries to interpret the input as an import. If that files, tries to interpret it as a path (rel or absolute), and if that fails, bails. optionalBasePath is what to pass to NewFromPath if that is used.
func NewFromImport ¶
NewFromImport will return a new Pkg pointing to that import. Will error if the given path does not appear to denote a valid game package for any reason.
func NewFromPath ¶
NewFromPath takes path (either relative or absolute path) and returns a new Pkg. Will error if the given path does not appear to denote a valid game package for any reason. If the path is not absolute, will join wiht optionalBasePath (can be either a rel or absolute path). If optionalBasePath is "" it will be set to current working directory automatically.
func Packages ¶
Packages is a convenience func that takes a list of arguments to pass to New() (paths or imports) and returns a list of all of the valid packages. Any packages that errored for any reason will have their error contained in the map of errors. If len(errors) == 0 then no packages errored. optionalBasePath will be passed on to New().
func (*Pkg) AbsolutePath ¶
AbsolutePath returns the absolute path where the package in question resides on disk. All constructors will have errored if AbsolutePath doesn't at the very least point to a valid location on disk. For example, "/Users/YOURUSERNAME/Code/go/src/github.com/jkomoros/boardgame/examples/memory"
func (*Pkg) ClientFolder ¶
ClientFolder returns the absolute path to this game package's folder of client assets, or "" if this game does not have a client folder. Example: "/Users/YOURUSERNAME/Code/go/src/github.com/jkomoros/boardgame/examples/memory/client"
func (*Pkg) Has ¶
Has returns whether the given relPath (directory or file) exists relative to this package.
func (*Pkg) Import ¶
Import returns the string that could be used in your source to import this package, for exampjle "github.com/jkomoros/boardgame/examples/memory"
func (*Pkg) Name ¶
Name returns the package name, according to a static analysis of the source. Technically it's possible that this differs from the package's delegate's Name(), however in practice that's extremely unlikely because the core library will fail to create a GameManager if the package and delegate name don't match. That means that the return value of this method can effectively be used as though it equals the delegate's Name().
func (*Pkg) ReadOnly ¶
ReadOnly returns true if the package appears to be in a read-only location (e.g. a cached module checkout)
func (*Pkg) RemoveDirIfEmpty ¶
RemoveDirIfEmpty removes the given dir if it contains no items.
func (*Pkg) RemoveFile ¶
RemoveFile removes the given path, relative to the base of the package, from the package if possible.