utils

package
v0.0.0-...-bd7a5bd Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const HorizontalDivider = "---------------------------------"
View Source
const NewLine = "\n\r"

Variables

This section is empty.

Functions

func Capitalize

func Capitalize(str string) string

func ClampInt

func ClampInt(v, min, max int) int

func Contains

func Contains[T comparable](s []T, v T) bool

func FindFilePathsWithExtension

func FindFilePathsWithExtension(root, ext string) []string

func FindIndex

func FindIndex[T comparable](s []T, v T) int

func GetLuaFunctionFromTable

func GetLuaFunctionFromTable(tbl *lua.LTable, fnName string) *lua.LFunction

func Keys

func Keys[TKey comparable, TValue any](m map[TKey]TValue) []TKey

func LineBreak

func LineBreak(str string, maxLen int, delimiter string) []string

func LoadFileBytes

func LoadFileBytes(path string) ([]byte, error)

func MaxInt

func MaxInt(a, b int) int

func MinInt

func MinInt(a, b int) int

func RandChance100

func RandChance100() float64

func RandRange

func RandRange(min int, max int) int

func SnakeFriendlyTitle

func SnakeFriendlyTitle(str string) string

func SwapDelete

func SwapDelete[T any](s []T, idx int) []T

func ToUserData

func ToUserData(L *lua.LState, val interface{}) *lua.LUserData

func ToUserDataList

func ToUserDataList[T any](L *lua.LState, arr []T) *lua.LTable

func Values

func Values[TKey comparable, TValue any](m map[TKey]TValue) []TValue

func WrapLuaFunc

func WrapLuaFunc(L *lua.LState, val lua.LValue) func()

Types

type ChanceTable

type ChanceTable[T any] []*ChanceTableEntry[T]

func (*ChanceTable[T]) Select

func (t *ChanceTable[T]) Select() []T

func (*ChanceTable[T]) SelectMultiplied

func (t *ChanceTable[T]) SelectMultiplied(mult float64) []T

type ChanceTableEntry

type ChanceTableEntry[T any] struct {
	Value  T
	Chance float64
}

type List

type List[T comparable] struct {
	Head *Node[T]
	Tail *Node[T]
}

func (*List[T]) AddBack

func (l *List[T]) AddBack(value T)

func (*List[T]) AddFront

func (l *List[T]) AddFront(value T)

func (*List[T]) Contains

func (l *List[T]) Contains(value T) bool

func (*List[T]) FindFirst

func (l *List[T]) FindFirst(pred func(T) bool) T

func (*List[T]) Remove

func (l *List[T]) Remove(value T)

type Node

type Node[T any] struct {
	Value T
	Next  *Node[T]
}

type Seconds

type Seconds float64

type StringBuilder

type StringBuilder struct {
	NewLine string
	// contains filtered or unexported fields
}

func (*StringBuilder) Len

func (sb *StringBuilder) Len() int

func (*StringBuilder) Reset

func (sb *StringBuilder) Reset()

func (*StringBuilder) String

func (sb *StringBuilder) String() string

func (*StringBuilder) WriteHorizontalDivider

func (sb *StringBuilder) WriteHorizontalDivider() *StringBuilder

func (*StringBuilder) WriteLine

func (sb *StringBuilder) WriteLine(s string) *StringBuilder

func (*StringBuilder) WriteLinef

func (sb *StringBuilder) WriteLinef(format string, a ...any) *StringBuilder

func (*StringBuilder) WriteNewLine

func (sb *StringBuilder) WriteNewLine() *StringBuilder

func (*StringBuilder) WriteString

func (sb *StringBuilder) WriteString(s string) *StringBuilder

func (*StringBuilder) WriteStringf

func (sb *StringBuilder) WriteStringf(format string, a ...any) *StringBuilder

type StringMapping

type StringMapping[T comparable] struct {
	ToValue  map[string]T
	ToString map[T]string
}

func NewStringMapping

func NewStringMapping[T comparable](mapping map[T]string) *StringMapping[T]

type WeightedTable

type WeightedTable[T any] struct {
	// contains filtered or unexported fields
}

func NewWeightedTable

func NewWeightedTable[T any](cfg WeightedTableConfig[T]) *WeightedTable[T]

func (*WeightedTable[T]) Select

func (t *WeightedTable[T]) Select() T

type WeightedTableConfig

type WeightedTableConfig[T any] []*WeightedTableEntry[T]

type WeightedTableEntry

type WeightedTableEntry[T any] struct {
	Value  T
	Weight float64
}

Jump to

Keyboard shortcuts

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