tabdrawer

package module
v0.0.0-...-3db1f85 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

README

tabdrawer

Golang library to draw tab list of minecraft servers

Example tab render

Example under example/constantiam

You can ask for live demo in my discord

Requires golang 1.19

Configuration

In order to render tab you need to collect together some styling:

type TabParameters struct {
 // LatencyColoring func that returns color of latency text that you desire
 // if nil DefaultLatencyColoring is used
 LatencyColoring func(int) color.Color

 // LatencyStyle do you want "ms" at the end?
 LatencyStyle LatencyStyling

 // ChatColorCodes Issues with color contrast? You can change it here
 // if nil DefaultChatColorCodes is used
 ChatColorCodes map[string]color.RGBA

 // BackgroundColor if nil DefaultDiscordBackgroundColor
 BackgroundColor color.Color

 // BackgroundColor if nil DefaultPlayerBackgroundColor
 PlayerBackgroundColor color.Color

 // RowSpacing distance between rows
 RowSpacing float64

 // RowAdditionalHeight adds space above and below text in rows (measures to keep weird symbols inside their rows)
 RowAdditionalHeight float64

 // ColumnSpacing distance between columns
 ColumnSpacing float64

 // MaxRows how many rows will be in one column at max
 MaxRows int

 FontColor color.Color
 Font      font.Face

 // OverridePlayerName if not nil can override rendering of particular uuid (must not be multiline), can return nil
 OverridePlayerName func(uuid.UUID) *chat.Message

 // SortFunction used to sort player names if nil DefaultPlayerSorter is used (sorts by name)
 SortFunction func(a []uuid.UUID, p map[uuid.UUID]TabPlayer, i int, j int) bool

 // LineSpacing spacing between lines in tab text (top and bottom)
 LineSpacing float64

 DebugTopBottom bool
 DebugHeight    bool
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDiscordBackgroundColor = color.RGBA{R: 0x36, G: 0x39, B: 0x3f, A: 0xff}
	DefaultPlayerBackgroundColor  = color.RGBA{0, 0, 0, 150}
)
View Source
var DefaultChatColorCodes = map[string]color.RGBA{
	"black":        {0, 0, 0, 255},
	"dark_blue":    {0, 0, 170, 255},
	"dark_green":   {0, 170, 0, 255},
	"dark_aqua":    {0, 170, 170, 255},
	"dark_red":     {170, 0, 0, 255},
	"dark_purple":  {170, 0, 170, 255},
	"gold":         {255, 170, 0, 255},
	"gray":         {170, 170, 170, 255},
	"dark_gray":    {85, 85, 85, 255},
	"blue":         {85, 85, 255, 255},
	"green":        {85, 255, 85, 255},
	"aqua":         {85, 255, 255, 255},
	"red":          {255, 85, 85, 255},
	"light_purple": {255, 85, 255, 255},
	"yellow":       {255, 255, 85, 255},
	"white":        {255, 255, 255, 255},
}

Functions

func ConvertColorCodes

func ConvertColorCodes(inputString string) chat.Message

func DefaultLatencyColoring

func DefaultLatencyColoring(ping int) color.Color

func DefaultPlayerSorter

func DefaultPlayerSorter(k []uuid.UUID, p map[uuid.UUID]TabPlayer, i int, j int) bool

func DrawTab

func DrawTab(players map[uuid.UUID]TabPlayer, tabtop, tabbottom *chat.Message, params *TabParameters) image.Image

Types

type LatencyStyling

type LatencyStyling int
const (
	LatencyNumberMs LatencyStyling = iota
	LatencyNumber
)

type TabParameters

type TabParameters struct {
	// LatencyColoring func that returns color of latency text that you desire
	// if nil DefaultLatencyColoring is used
	LatencyColoring func(int) color.Color

	// LatencyStyle do you want "ms" at the end?
	LatencyStyle LatencyStyling

	// ChatColorCodes Issues with color contrast? You can change it here
	// if nil DefaultChatColorCodes is used
	ChatColorCodes map[string]color.RGBA

	// BackgroundColor if nil DefaultDiscordBackgroundColor
	BackgroundColor color.Color

	// BackgroundColor if nil DefaultPlayerBackgroundColor
	PlayerBackgroundColor color.Color

	// RowSpacing distance between rows
	RowSpacing float64

	// RowAdditionalHeight adds space above and below text in rows (measures to keep weird symbols inside their rows)
	RowAdditionalHeight float64

	// ColumnSpacing distance between columns
	ColumnSpacing float64

	// MaxRows how many rows will be in one column at max
	MaxRows int

	FontColor color.Color
	Font      font.Face

	// OverridePlayerName if not nil can override rendering of particular uuid (must not be multiline), can return nil
	OverridePlayerName func(uuid.UUID) *chat.Message

	// SortFunction used to sort player names if nil DefaultPlayerSorter is used (sorts by name)
	SortFunction func(a []uuid.UUID, p map[uuid.UUID]TabPlayer, i int, j int) bool

	// LineSpacing spacing between lines in tab text (top and bottom)
	LineSpacing float64

	DebugTopBottom bool
	DebugHeight    bool
}

type TabPlayer

type TabPlayer struct {
	Name        chat.Message
	Ping        int
	HeadTexture image.Image
	Gamemode    string
}

Jump to

Keyboard shortcuts

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