gamepkg

package
v0.0.0-...-6b15219 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gamepkg is a package that helps locate, validate, and modify game package imports.

Index

Constants

View Source
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

func AllPackages(inputs []string, optionalBasePath string) ([]*Pkg, error)

AllPackages is a wrapper around Packages that will return a single error and no packages if any of the packages was invalid.

func New

func New(importOrPath string, optionalBasePath string) (*Pkg, error)

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

func NewFromImport(importPath string) (*Pkg, error)

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

func NewFromPath(path string, optionalBasePath string) (*Pkg, error)

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

func Packages(inputs []string, optionalBasePath string) ([]*Pkg, map[string]error)

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

func (p *Pkg) AbsolutePath() string

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

func (p *Pkg) ClientFolder() string

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) EnsureDir

func (p *Pkg) EnsureDir(relPath string) error

EnsureDir ensures the given directory, relative to package root, exists.

func (*Pkg) Has

func (p *Pkg) Has(relPath string) bool

Has returns whether the given relPath (directory or file) exists relative to this package.

func (*Pkg) Import

func (p *Pkg) Import() string

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

func (p *Pkg) Name() string

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

func (p *Pkg) ReadOnly() bool

ReadOnly returns true if the package appears to be in a read-only location (e.g. a cached module checkout)

func (*Pkg) RemoveDirIfEmpty

func (p *Pkg) RemoveDirIfEmpty(relPath string) error

RemoveDirIfEmpty removes the given dir if it contains no items.

func (*Pkg) RemoveFile

func (p *Pkg) RemoveFile(relPath string) error

RemoveFile removes the given path, relative to the base of the package, from the package if possible.

func (*Pkg) WriteFile

func (p *Pkg) WriteFile(relPath string, contents []byte, overwrite bool) error

WriteFile writes the given relPath contents with 0644 perms. If overwite is true will overwrite; if overwrite is false and the file already exists will fail.

Jump to

Keyboard shortcuts

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