d2util

package
v0.0.0-...-7f92c57 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package d2util is a utility package for general-purpose functions used frequently throughout the codebase.

Index

Constants

View Source
const (
	LogFmtDebug   = "[DEBUG]" + colorEscapeReset + " %s\r\n"
	LogFmtInfo    = "[INFO]" + colorEscapeReset + " %s\r\n"
	LogFmtWarning = "[WARNING]" + colorEscapeReset + " %s\r\n"
	LogFmtError   = "[ERROR]" + colorEscapeReset + " %s\r\n"
	LogFmtFatal   = "[FATAL]" + colorEscapeReset + " %s\r\n"
)

Log format strings for log levels

View Source
const LogLevelDefault = LogLevelInfo

LogLevelDefault is the default log level

Variables

This section is empty.

Functions

func AsterToEmpty

func AsterToEmpty(text string) string

AsterToEmpty converts strings beginning with "*" to "", for use when handling columns where an asterix can be used to comment out entries

func Color

func Color(rgba uint32) color.RGBA

Color converts an rgba uint32 to a colorEnabled.RGBA

func EmptyToZero

func EmptyToZero(text string) string

EmptyToZero converts empty strings to "0" and leaves non-empty strings as is, for use before converting numerical data which equates empty to zero

func ImgIndexToRGBA

func ImgIndexToRGBA(indexData []byte, palette d2interface.Palette) []byte

ImgIndexToRGBA converts the given indices byte slice and palette into a byte slice of RGBA values

func Now

func Now() float64

Now returns how many seconds have elapsed since Unix time (January 1, 1970 UTC)

func SplitIntoLinesWithMaxWidth

func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string

SplitIntoLinesWithMaxWidth splits the given string into lines considering the given maxChars

func StringToInt

func StringToInt(text string) int

StringToInt converts a string to an integer

func StringToInt8

func StringToInt8(text string) int8

StringToInt8 converts a string to an int8

func StringToUint

func StringToUint(text string) uint

StringToUint converts a string to a uint32

func StringToUint8

func StringToUint8(text string) uint8

StringToUint8 converts a string to an uint8

func Utf16BytesToString

func Utf16BytesToString(b []byte) (string, error)

Utf16BytesToString converts a utf16 byte array to string

Types

type GlyphPrinter

type GlyphPrinter struct {
	// contains filtered or unexported fields
}

GlyphPrinter uses an image containing glyphs to draw text onto ebiten images

func NewDebugPrinter

func NewDebugPrinter() *GlyphPrinter

NewDebugPrinter creates a new debug printer

func (*GlyphPrinter) Print

func (p *GlyphPrinter) Print(target interface{}, str string) error

Print draws the string str on the image on left top corner.

The available runes are in U+0000 to U+00FF, which is C0 Controls and Basic Latin and C1 Controls and Latin-1 Supplement.

DebugPrint always returns nil as of 1.5.0-alpha.

func (*GlyphPrinter) PrintAt

func (p *GlyphPrinter) PrintAt(target interface{}, str string, x, y int)

PrintAt draws the string str on the image at (x, y) position. The available runes are in U+0000 to U+00FF, which is C0 Controls and Basic Latin and C1 Controls and Latin-1 Supplement.

type LogLevel

type LogLevel = int

LogLevel determines how verbose the logging is (higher is more verbose)

const (
	LogLevelNone LogLevel = iota
	LogLevelFatal
	LogLevelError
	LogLevelWarning
	LogLevelInfo
	LogLevelDebug
	LogLevelUnspecified
)

Log levels

type Logger

type Logger struct {
	io.Writer
	// contains filtered or unexported fields
}

Logger is used to write log messages, and can have a log level to determine verbosity

func NewLogger

func NewLogger() *Logger

NewLogger creates a new logger with a default

func (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug logs a debug message

func (*Logger) Debugf

func (l *Logger) Debugf(fmtMsg string, args ...interface{})

Debugf formats and then logs a debug message

func (*Logger) Error

func (l *Logger) Error(msg string)

Error logs an error message

func (*Logger) Errorf

func (l *Logger) Errorf(fmtMsg string, args ...interface{})

Errorf formats and then logs a error message

func (*Logger) Fatal

func (l *Logger) Fatal(msg string)

Fatal logs an fatal error message and exits programm

func (*Logger) Fatalf

func (l *Logger) Fatalf(fmtMsg string, args ...interface{})

Fatalf formats and then logs a error message

func (*Logger) Info

func (l *Logger) Info(msg string)

Info logs an info message

func (*Logger) Infof

func (l *Logger) Infof(fmtMsg string, args ...interface{})

Infof formats and then logs an info message

func (*Logger) SetColorEnabled

func (l *Logger) SetColorEnabled(b bool)

SetColorEnabled adds color escape-sequences to the logging output

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel sets the log level

func (*Logger) SetPrefix

func (l *Logger) SetPrefix(s string)

SetPrefix sets a prefix for the message. example:

logger.SetPrefix("XYZ")
logger.Debug("ABC") will print "[XYZ] [DEBUG] ABC"

func (*Logger) Warning

func (l *Logger) Warning(msg string)

Warning logs a warning message

func (*Logger) Warningf

func (l *Logger) Warningf(fmtMsg string, args ...interface{})

Warningf formats and then logs a warning message

func (*Logger) Write

func (l *Logger) Write(p []byte) (n int, err error)

Directories

Path Synopsis
Package assets provides files for use by the debug utils
Package assets provides files for use by the debug utils

Jump to

Keyboard shortcuts

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