Back to godoc.org

Package d2util

v0.0.0-...-2704a23
Latest Go to latest

The latest major version is .

Published: 2 days ago | License: GPL3 | Module: github.com/OpenDiablo2/OpenDiablo2

Overview

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

Index

Constants

const (
	LogFmtDebug   = "[DEBUG] %s\n\r"
	LogFmtInfo    = "[INFO] %s\n\r"
	LogFmtWarning = "[WARNING] %s\n\r"
	LogFmtError   = "[ERROR] %s\n\r"
)

Log format strings for log levels

Variables

var DebugPrinter = NewDebugPrinter() //nolint:gochecknoglobals // currently global by design

DebugPrinter is the global debug printer

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 color.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

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 *ebiten.Image, 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 *ebiten.Image, 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
	LogLevelError
	LogLevelWarning
	LogLevelInfo
	LogLevelDebug
)

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 (*Logger) Debug

func (l *Logger) Debug(msg string)

Debug logs a debug message

func (*Logger) Error

func (l *Logger) Error(msg string)

Error logs an error message

func (*Logger) Info

func (l *Logger) Info(msg string)

Info logs an info message

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel)

SetLevel sets the log level

func (*Logger) Warning

func (l *Logger) Warning(msg string)

Warning logs a warning message

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier