stub

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: 12 Imported by: 0

Documentation

Overview

Package stub is a library that helps generate stub code for new games

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileContents

type FileContents map[string][]byte

FileContents is the generated contents of the files to later write to the filesystem.

func Generate

func Generate(opt *Options) (FileContents, error)

Generate generates FileContents for the given set of options. A convenience wrapper around DefaultTemplateSet, templates.Generate(), and files.Format().

func (FileContents) Format

func (f FileContents) Format() error

Format go formats all of the code om FileContents whose path ends in ".go", erroring if the code isn't valid. If an error is returned, then the contents of FileContents will not have been modified.

func (FileContents) Save

func (f FileContents) Save(dir string, overwrite bool) error

Save saves the given FileContents to the filesystem, creating any implied directories. Dir is the prefix to join with each path in FileContents; "" is fine. Will error if overwite is not true and any of the files to create already exist.

type Options

type Options struct {
	//The name of the game
	Name string
	//DisplayName to output (skipped if "")
	DisplayName string
	//Description of game to output (skipped if "")
	Description       string
	MinNumPlayers     int
	MaxNumPlayers     int
	DefaultNumPlayers int
	//If true, won't save main_test.go
	SuppressTest  bool
	SuppressPhase bool
	//If true, won't add a CurrentPlayer to gameState
	SuppressCurrentPlayer bool
	//If true, won't render moves_normal.go, moves_setup.go, or moves.go if suppressphase is true
	SuppressMovesStubs bool
	//If true, instead of using reflection for delegate.Name() will just output {{.Name}}
	SuppressReflectedName               bool
	SuppressComponentsStubs             bool
	SuppressClientRenderGame            bool
	SuppressClientRenderPlayerInfo      bool
	EnableExampleDeck                   bool
	EnableExampleDynamicComponentValues bool
	EnableExampleEndState               bool
	EnableExampleComputedProperties     bool
	EnableExampleConstants              bool
	EnableExampleVariants               bool
	EnableExampleClient                 bool
	EnableExampleMoves                  bool
	EnableSeatPlayer                    bool
	EnableInactivePlayer                bool
}

Options is the default options struct. Name is the only required field; the zero-value of every other field is default.

func InteractiveOptions

func InteractiveOptions(in, out *os.File, gameName string) *Options

InteractiveOptions renders an interactve prompt at out, in to generate an Options from the user. If in or out are nil, StdIn or StdOut will be used implicitly.

func (*Options) EnableTutorials

func (o *Options) EnableTutorials()

EnableTutorials enables all of the off-by-default tutorial options.

func (*Options) SuppressClient

func (o *Options) SuppressClient()

SuppressClient sets the options about clients to suppressed.

func (*Options) SuppressExtras

func (o *Options) SuppressExtras()

SuppressExtras sets all of the non-client extras that are on by default to off.

func (*Options) Validate

func (o *Options) Validate() error

Validate verifies that Options is in a legal state. Makes sure Name exists and ensures it's lowerCase. Repeated calls are OK.

type TemplateSet

type TemplateSet map[string]*template.Template

TemplateSet is a collection of templates that can create a derived and expanded FileContents when given an Options struct.

func DefaultTemplateSet

func DefaultTemplateSet(opt *Options) (TemplateSet, error)

DefaultTemplateSet returns the default template set for this stub.

func (TemplateSet) Generate

func (t TemplateSet) Generate(opt *Options) (FileContents, error)

Generate generates FileContents based on this TemplateSet, using those options to expand. Names of files will also be run through templates and expanded.

Jump to

Keyboard shortcuts

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