ancestry

package
v5.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2022 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Simple      = NameGenerationType("simple")
	MarkovChain = NameGenerationType("markov_chain")
)

Possible NameGenerationType values.

View Source
const (
	Default = "Human"
)

Default holds the name of the default ancestry.

Variables

View Source
var AllNameGenerationTypes = []NameGenerationType{
	Simple,
	MarkovChain,
}

AllNameGenerationTypes is the complete set of NameGenerationType values.

Functions

func AvailableAncestries

func AvailableAncestries(libraries library.Libraries) []*library.NamedFileSet

AvailableAncestries scans the libraries and returns the available ancestries.

func ChooseStringOption

func ChooseStringOption(options []*StringOption, not string) string

ChooseStringOption selects a string option from the available set.

Types

type Ancestry

type Ancestry struct {
	Name          string                     `json:"name,omitempty"`
	CommonOptions *Options                   `json:"common_options,omitempty"`
	GenderOptions []*WeightedAncestryOptions `json:"gender_options,omitempty"`
}

Ancestry holds details necessary to generate ancestry-specific customizations.

func Lookup

func Lookup(name string, libraries library.Libraries) *Ancestry

Lookup an Ancestry by name.

func NewAncestryFromFile

func NewAncestryFromFile(fileSystem fs.FS, filePath string) (*Ancestry, error)

NewAncestryFromFile creates a new Ancestry from a file.

func (*Ancestry) GenderedOptions

func (a *Ancestry) GenderedOptions(gender string) *Options

GenderedOptions returns the options for the specified gender, or nil.

func (*Ancestry) RandomAge

func (a *Ancestry) RandomAge(resolver eval.VariableResolver, gender string, not int) int

RandomAge returns a randomized age.

func (*Ancestry) RandomEyes

func (a *Ancestry) RandomEyes(gender, not string) string

RandomEyes returns a randomized eyes.

func (*Ancestry) RandomGender

func (a *Ancestry) RandomGender(not string) string

RandomGender returns a randomized gender.

func (*Ancestry) RandomHair

func (a *Ancestry) RandomHair(gender, not string) string

RandomHair returns a randomized hair.

func (*Ancestry) RandomHandedness

func (a *Ancestry) RandomHandedness(gender, not string) string

RandomHandedness returns a randomized handedness.

func (*Ancestry) RandomHeight

func (a *Ancestry) RandomHeight(resolver eval.VariableResolver, gender string, not measure.Length) measure.Length

RandomHeight returns a randomized height.

func (*Ancestry) RandomName

func (a *Ancestry) RandomName(nameGeneratorRefs []*NameGeneratorRef, gender string) string

RandomName returns a randomized name.

func (*Ancestry) RandomSkin

func (a *Ancestry) RandomSkin(gender, not string) string

RandomSkin returns a randomized skin.

func (*Ancestry) RandomWeight

func (a *Ancestry) RandomWeight(resolver eval.VariableResolver, gender string, not measure.Weight) measure.Weight

RandomWeight returns a randomized weight.

func (*Ancestry) Save

func (a *Ancestry) Save(filePath string) error

Save writes the Ancestry to the file as JSON.

type NameGenerationType

type NameGenerationType string

NameGenerationType holds the type of a name generation technique.

func (NameGenerationType) EnsureValid

func (n NameGenerationType) EnsureValid() NameGenerationType

EnsureValid ensures this is of a known value.

func (NameGenerationType) String

func (n NameGenerationType) String() string

String implements fmt.Stringer.

type NameGenerator

type NameGenerator struct {
	Type         NameGenerationType `json:"type"`
	TrainingData []string           `json:"training_data"`
	// contains filtered or unexported fields
}

NameGenerator holds the data for name generation.

func NewNameGeneratorFromFS

func NewNameGeneratorFromFS(fileSystem fs.FS, filePath string) (*NameGenerator, error)

NewNameGeneratorFromFS creates a new NameGenerator from a file.

func (*NameGenerator) Generate

func (n *NameGenerator) Generate() string

Generate a name.

type NameGeneratorRef

type NameGeneratorRef struct {
	FileRef *library.NamedFileRef
	// contains filtered or unexported fields
}

NameGeneratorRef holds a reference to a NameGenerator.

func AvailableNameGenerators

func AvailableNameGenerators(libraries library.Libraries) []*NameGeneratorRef

AvailableNameGenerators scans the libraries and returns the available name generators.

func (*NameGeneratorRef) Generator

func (n *NameGeneratorRef) Generator() (*NameGenerator, error)

Generator returns the NameGenerator, loading it if needed.

type Options

type Options struct {
	Name              string          `json:"name,omitempty"`
	HeightFormula     string          `json:"height_formula,omitempty"`
	WeightFormula     string          `json:"weight_formula,omitempty"`
	AgeFormula        string          `json:"age_formula,omitempty"`
	HairOptions       []*StringOption `json:"hair_options,omitempty"`
	EyeOptions        []*StringOption `json:"eye_options,omitempty"`
	SkinOptions       []*StringOption `json:"skin_options,omitempty"`
	HandednessOptions []*StringOption `json:"handedness_options,omitempty"`
	NameGenerators    []string        `json:"name_generators,omitempty"`
}

Options holds options that may be randomized for an Entity's ancestry.

func ChooseWeightedAncestryOptions

func ChooseWeightedAncestryOptions(options []*WeightedAncestryOptions, omitter func(*Options) bool) *Options

ChooseWeightedAncestryOptions selects a string option from the available set.

func (*Options) RandomAge

func (o *Options) RandomAge(resolver eval.VariableResolver, not int) int

RandomAge returns a randomized age.

func (*Options) RandomEye

func (o *Options) RandomEye(not string) string

RandomEye returns a randomized eye.

func (*Options) RandomHair

func (o *Options) RandomHair(not string) string

RandomHair returns a randomized hair.

func (*Options) RandomHandedness

func (o *Options) RandomHandedness(not string) string

RandomHandedness returns a randomized handedness.

func (*Options) RandomHeight

func (o *Options) RandomHeight(resolver eval.VariableResolver, not measure.Length) measure.Length

RandomHeight returns a randomized height.

func (*Options) RandomName

func (o *Options) RandomName(nameGeneratorRefs []*NameGeneratorRef) string

RandomName returns a randomized name.

func (*Options) RandomSkin

func (o *Options) RandomSkin(not string) string

RandomSkin returns a randomized skin.

func (*Options) RandomWeight

func (o *Options) RandomWeight(resolver eval.VariableResolver, not measure.Weight) measure.Weight

RandomWeight returns a randomized weight.

type StringOption

type StringOption struct {
	Weight int    `json:"weight"`
	Value  string `json:"value"`
}

StringOption is a string that has a weight associated with it.

func (*StringOption) Valid

func (o *StringOption) Valid() bool

Valid returns true if this option has a valid weight.

type WeightedAncestryOptions

type WeightedAncestryOptions struct {
	Weight int      `json:"weight"`
	Value  *Options `json:"value"`
}

WeightedAncestryOptions is a string that has a weight associated with it.

func (*WeightedAncestryOptions) Valid

func (o *WeightedAncestryOptions) Valid() bool

Valid returns true if this option has a valid weight.

Jump to

Keyboard shortcuts

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