Documentation
¶
Index ¶
- Constants
- func AddMemoryReporter(name string, reporter MemReport)
- func ApproximateMemoryUsage(i interface{}) uint64
- func BoolYN(b bool) string
- func BreakIntoParts(full string) []string
- func Compress(input []byte) []byte
- func ConvertColorShortTags(input string) string
- func ConvertForFilename(input string) string
- func CopyoverContributor() copyover.Contributor
- func Decode(base64str string) []byte
- func Decompress(input []byte) []byte
- func Encode(blobdata []byte) string
- func FilePath(pathParts ...string) string
- func FindMatchIn(searchName string, items ...string) (match string, closeMatch string)
- func FormatBytes(bytes uint64) string
- func FormatDiceRoll(attacks int, dCount int, dSides int, bonus int, buffOnCrit []int) string
- func FormatNumber(n int) string
- func GetLockSequence(lockIdentifier string, difficulty int, seed string) string
- func GetMatchNumber(input string) (string, int)
- func GetMemoryReport() (names []string, trackedResults []map[string]MemoryResult)
- func GetMyIP() string
- func GetRoundCount() uint64
- func GetServerAddress() string
- func GetTurnCount() uint64
- func Hash(input string) string
- func HashBytes(input []byte) string
- func HealthClass(health int, maxHealth int) string
- func IncrementRoundCount() uint64
- func IncrementTurnCount() uint64
- func LoadRoundCount(fpath string) uint64
- func LockMud()
- func LogRoll(name string, rollResult int, targetNumber int)
- func ManaClass(mana int, maxMana int) string
- func Md5(input string) string
- func Md5Bytes(input []byte) []byte
- func MemoryUsage(i interface{}) uint64
- func ParseDiceRoll(dRoll string) (attacks int, dCount int, dSides int, bonus int, buffOnCrit []int)
- func PercentOfTotal(value1 int, value2 int) float64
- func ProgressBar(complete float64, maxBarSize int, barParts ...string) (fullBar string, emptyBar string)
- func QuantizeTens(value int, max int) int
- func RLockMud()
- func RUnlockMud()
- func Rand(maxInt int) int
- func ReadFile(path string) ([]byte, error)
- func RollDice(dice int, sides int) int
- func SafeSave(path string, data []byte) error
- func Save(path string, data []byte, doSafe ...bool) error
- func SaveRoundCount(fpath string)
- func ServerGetMemoryUsage() map[string]MemoryResult
- func ServerStats() string
- func SetRoundCount(newRoundCount uint64)
- func SetServerAddress(addr string)
- func SplitButRespectQuotes(s string) []string
- func SplitString(input string, lineWidth int) []string
- func SplitStringNL(input string, lineWidth int, nlPrefix ...string) string
- func StringWildcardMatch(stringToSearch string, patternToSearch string) bool
- func StripANSI(str string) string
- func StripCharsForScreenReaders(s string) string
- func StripPrepositions(input string) string
- func TrackTime(name string, timePassed float64)
- func UnlockMud()
- func ValidateWorldFiles(exampleWorldPath string, worldPath string) error
- func WriteFile(path string, data []byte, perm os.FileMode) error
- type Accumulator
- type Hook
- type MemReport
- type MemResultUnit
- type MemoryResult
Constants ¶
const ( // start at 1314000 (approx. 4 years in the future) to avoid complexities of // delta comparisons and to allow for date adjustments. RoundCountMinimum = 1314000 RoundCountFilename = `.roundcount` )
Variables ¶
This section is empty.
Functions ¶
func AddMemoryReporter ¶
AddMemoryReporter registers a named memory reporter. Duplicate names are accepted but will appear as separate sections in the report.
func ApproximateMemoryUsage ¶ added in v0.9.8
func ApproximateMemoryUsage(i interface{}) uint64
ApproximateMemoryUsage returns a rough estimate of the memory occupied by i. It accounts for slice capacity, string backing arrays, interface values, and deduplicates shared pointer targets. Map internal bucket overhead is not counted. Returns 0 for nil.
func BreakIntoParts ¶
func ConvertColorShortTags ¶
func ConvertForFilename ¶
Make everything lowercase Convert anything that isn't a-z, 0-9 into _
func CopyoverContributor ¶ added in v0.9.8
func CopyoverContributor() copyover.Contributor
CopyoverContributor returns the util contributor for registration.
func Decompress ¶
func FindMatchIn ¶
func FormatBytes ¶
FormatBytes formats a byte count as a human-readable string. Returns "0 B" for zero, otherwise scales to KB/MB/GB/TB/PB/EB.
func FormatDiceRoll ¶
func FormatNumber ¶
func GetLockSequence ¶
func GetMatchNumber ¶
accepts an input and splits it along a # if any. By default returns the full string and 1 as the number.
func GetMemoryReport ¶
func GetMemoryReport() (names []string, trackedResults []map[string]MemoryResult)
GetMemoryReport calls every registered reporter and returns the section names and their results. The two slices are parallel: names[i] corresponds to trackedResults[i].
func GetRoundCount ¶
func GetRoundCount() uint64
func GetServerAddress ¶
func GetServerAddress() string
func GetTurnCount ¶
func GetTurnCount() uint64
func HealthClass ¶
func IncrementRoundCount ¶
func IncrementRoundCount() uint64
func IncrementTurnCount ¶
func IncrementTurnCount() uint64
func LoadRoundCount ¶
func LockMud ¶
func LockMud()
Mutex lock intended for synchronizing at a high level between components that may asyncronously access game data
func MemoryUsage ¶
func MemoryUsage(i interface{}) uint64
MemoryUsage is an alias for ApproximateMemoryUsage retained for backwards compatibility with existing callers.
func ParseDiceRoll ¶
Gets the specifics of the item damage Format: 2@1d3+2#1,2,3
func PercentOfTotal ¶
func ProgressBar ¶
func QuantizeTens ¶
Creates a percentage and quantizes it to the nearest 10
func RUnlockMud ¶
func RUnlockMud()
func SafeSave ¶
SafeSave first saves to a temp file, then renames it to save over the target destination This is to lessen the risk of a partial write being interrupted and corrupting the file due to power loss etc.
func SaveRoundCount ¶
func SaveRoundCount(fpath string)
func ServerGetMemoryUsage ¶
func ServerGetMemoryUsage() map[string]MemoryResult
ServerGetMemoryUsage reads runtime stats and returns them as a MemoryResult map. Entries whose Unit is UnitCount hold plain integer counts, not bytes.
func ServerStats ¶
func ServerStats() string
ServerStats returns a formatted ANSI string summarising Go runtime memory and scheduler statistics. A single ReadMemStats call is shared with ServerGetMemoryUsage when both are needed; call ServerGetMemoryUsageFromStats directly to reuse an already-read MemStats value.
func SetRoundCount ¶
func SetRoundCount(newRoundCount uint64)
func SetServerAddress ¶
func SetServerAddress(addr string)
func SplitButRespectQuotes ¶
func SplitString ¶
func SplitStringNL ¶
Splits a string by adding line breaks at the end of each line
func StringWildcardMatch ¶
func StripPrepositions ¶
Strips out common prepositions from a string
func ValidateWorldFiles ¶
Types ¶
type Accumulator ¶
type Accumulator struct {
Name string
Total float64
Lowest float64
Highest float64
Count float64
Start time.Time
}
func GetTimeTrackers ¶
func GetTimeTrackers() []Accumulator
func (*Accumulator) Average ¶
func (t *Accumulator) Average() float64
func (*Accumulator) Record ¶
func (t *Accumulator) Record(nextValue float64)
type Hook ¶ added in v0.9.8
type Hook[T any] struct { // contains filtered or unexported fields }
Hook is a generic, type-safe synchronous callback chain. Handlers registered against a Hook receive the current value, may modify it, and return the (possibly modified) value. All registered handlers are called in registration order. The final value is returned to the caller.
Hook is safe for concurrent registration and firing.
Example – defining a hook point in a package:
var OnRoomLook util.Hook[RoomTemplateDetails]
Example – registering a handler from a module:
rooms.OnRoomLook.Register(func(d rooms.RoomTemplateDetails) rooms.RoomTemplateDetails {
d.Alert("You can fish here!")
return d
})
Example – firing the hook at the call site:
details = rooms.OnRoomLook.Fire(details)
type MemReport ¶
type MemReport func() map[string]MemoryResult
type MemResultUnit ¶ added in v0.9.8
type MemResultUnit uint8
MemResultUnit describes what the Memory field of a MemoryResult holds so callers can format it correctly.
const ( UnitBytes MemResultUnit = iota // Memory holds a byte count UnitCount // Memory holds a plain integer count (not bytes) )
type MemoryResult ¶
type MemoryResult struct {
Memory uint64
Count int
Unit MemResultUnit
}