builder

package module
v0.0.0-...-dbc3ccf Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const ComponentSkipChance float64 = 0.5
View Source
const PropertySkipChance float64 = 0.5

Variables

View Source
var (
	ErrSetterEmpty = errors.New("setters require a slice with at least 1 element")
	ErrNameBlank   = errors.New("setters require struct with valid 'Name' field")
)

Functions

This section is empty.

Types

type Atom

type Atom struct {
	PropertyLabel string
	WeightFactor  float64
	ValueFactor   float64
	String        string
}

type AtomSlice

type AtomSlice struct {
	ComponentLabel string
	Atoms          []Atom
}

type Attribute

type Attribute struct {
	Name         string       `json:"name"`
	Common       VariantBlock `json:"common"`
	Uncommon     VariantBlock `json:"uncommon"`
	Rare         VariantBlock `json:"rare"`
	WeightFactor float64      `json:"weight_factor"`
	PrefixNames  []string     `json:"prefix_names"`
	SuffixNames  []string     `json:"suffix_names"`
	Prefixes     []*Attribute
	Suffixes     []*Attribute
}

func (*Attribute) RandomPrefix

func (a *Attribute) RandomPrefix() (*Attribute, bool)

func (*Attribute) RandomSuffix

func (a *Attribute) RandomSuffix() (*Attribute, bool)

func (*Attribute) Reduce

func (a *Attribute) Reduce() Variant

type AttributeGroup

type AttributeGroup struct {
	Name           string   `json:"name"`
	AttributeNames []string `json:"attribute_names"`
	Attributes     []*Attribute
}

type Builder

type Builder interface {
	SetRecipes(io.Reader) error
	SetAttributes(io.Reader) error
	SetAttributeGroups(io.Reader) error
	LinkResources() error
	Item() (*Item, error)
}

type Component

type Component struct {
	Name       string     `json:"name"`
	Required   bool       `json:"required"`
	Properties []Property `json:"properties"`
}

func (*Component) Atomize

func (c *Component) Atomize() []Atom

func (*Component) Reduce

func (c *Component) Reduce() []Property

Reduce returns a slice of randomly selected Properties.

type Item

type Item struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	Class       string  `json:"class"`
	Value       float64 `json:"value"`
	Weight      float64 `json:"weight"`
	Description string  `json:"description"`
}

type MundaneBuilder

type MundaneBuilder struct {
	Recipes    map[string]Recipe
	Attributes map[string]Attribute
	Groups     map[string]*AttributeGroup
}

MundaneBuilder implements the Builder interface. MundaneBuilder randomly generates mundane Items from the provided resources.

func NewMundaneBuilder

func NewMundaneBuilder() MundaneBuilder

NewMundaneBuilder returns an initialized MundaneBuilder.

func (*MundaneBuilder) Item

func (mb *MundaneBuilder) Item() (*Item, error)

Item generates a unique mundane Item using the set resources in MundaneBuilder.

func (*MundaneBuilder) LinkResources

func (mb *MundaneBuilder) LinkResources() error

LinkResources iterates through all of the receiver's maps and links each object's list of AttributeNames and AttributeGroupNames to their respective Attributes and AttributeGroups.

func (*MundaneBuilder) Reduce

func (mb *MundaneBuilder) Reduce() Recipe

Reduce returns a randomly selected Recipe.

func (*MundaneBuilder) SetAttributeGroups

func (mb *MundaneBuilder) SetAttributeGroups(r io.Reader) error

SetAttributeGroups reads the JSON-encoded AttributeGroups from the provided Reader and adds them to the receiver's AttributeGroup map.

func (*MundaneBuilder) SetAttributes

func (mb *MundaneBuilder) SetAttributes(r io.Reader) error

SetAttributes reads the JSON-encoded Attributes from the provided Reader and adds them to the receiver's Attribute map.

func (*MundaneBuilder) SetRecipes

func (mb *MundaneBuilder) SetRecipes(r io.Reader) error

SetRecipes reads the JSON-encoded Recipes from the provided Reader and adds them to the receiver's Recipe map.

type Property

type Property struct {
	Name                string   `json:"name"`
	Required            bool     `json:"required"`
	AttributeNames      []string `json:"attribute_names"`
	AttributeGroupNames []string `json:"attribute_group_names"`
	Attributes          []*Attribute
	AttributeGroups     []*AttributeGroup
}

func (*Property) Reduce

func (p *Property) Reduce() []Attribute

Reduce returns a slice of randomly selected Attributes.

type Recipe

type Recipe struct {
	Name       string      `json:"name"`
	BaseValue  float64     `json:"base_value"`
	BaseWeight float64     `json:"base_weight"`
	Comps      []Component `json:"components"`
}

func (*Recipe) Produce

func (r *Recipe) Produce() Item

func (*Recipe) Reduce

func (r *Recipe) Reduce() []Component

Reduce returns a slice of randomly selected Components.

type Variant

type Variant struct {
	Name         string
	ValueFactor  float64
	WeightFactor float64
}

type VariantBlock

type VariantBlock struct {
	ValueFactor float64  `json:"value_factor"`
	Variants    []string `json:"variants"`
}

func (*VariantBlock) Reduce

func (vb *VariantBlock) Reduce() Variant

Reduce returns a randomly selected Variant.

Jump to

Keyboard shortcuts

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