Documentation ¶
Overview ¶
Package d2util is a utility package for general-purpose functions used frequently throughout the codebase.
Index ¶
- Constants
- func AsterToEmpty(text string) string
- func Color(rgba uint32) color.RGBA
- func EmptyToZero(text string) string
- func ImgIndexToRGBA(indexData []byte, palette d2interface.Palette) []byte
- func Now() float64
- func SplitIntoLinesWithMaxWidth(fullSentence string, maxChars int) []string
- func StringToInt(text string) int
- func StringToInt8(text string) int8
- func StringToUint(text string) uint
- func StringToUint8(text string) uint8
- func Utf16BytesToString(b []byte) (string, error)
- type GlyphPrinter
- type LogLevel
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(fmtMsg string, args ...interface{})
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(fmtMsg string, args ...interface{})
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(fmtMsg string, args ...interface{})
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(fmtMsg string, args ...interface{})
- func (l *Logger) SetColorEnabled(b bool)
- func (l *Logger) SetLevel(level LogLevel)
- func (l *Logger) SetPrefix(s string)
- func (l *Logger) Warning(msg string)
- func (l *Logger) Warningf(fmtMsg string, args ...interface{})
- func (l *Logger) Write(p []byte) (n int, err error)
Constants ¶
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
const LogLevelDefault = LogLevelInfo
LogLevelDefault is the default log level
Variables ¶
This section is empty.
Functions ¶
func AsterToEmpty ¶
AsterToEmpty converts strings beginning with "*" to "", for use when handling columns where an asterix can be used to comment out entries
func EmptyToZero ¶
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 ¶
SplitIntoLinesWithMaxWidth splits the given string into lines considering the given maxChars
func StringToUint8 ¶
StringToUint8 converts a string to an uint8
func Utf16BytesToString ¶
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)
type Logger ¶
Logger is used to write log messages, and can have a log level to determine verbosity
func (*Logger) SetColorEnabled ¶
SetColorEnabled adds color escape-sequences to the logging output
func (*Logger) SetPrefix ¶
SetPrefix sets a prefix for the message. example:
logger.SetPrefix("XYZ") logger.Debug("ABC") will print "[XYZ] [DEBUG] ABC"