component

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2022 License: Apache-2.0 Imports: 6 Imported by: 28

README

component

A Minecraft text components library for the Go programming language.

Documentation

Overview

Is is recommended to make this package a dot import alias to keep code clean.

Index

Constants

This section is empty.

Variables

View Source
var (
	// DecorationsOrder is the order of applied decorations.
	DecorationsOrder = []Decoration{
		Obfuscated,
		Bold,
		Strikethrough,
		Underlined,
		Italic,
	}

	// Decorations is a map of all decorations.
	Decorations = func() map[Decoration]struct{} {
		m := map[Decoration]struct{}{}
		for _, a := range DecorationsOrder {
			m[a] = struct{}{}
		}
		return m
	}()
)
View Source
var (
	DefaultFont = key.New(key.MinecraftNamespace, "default")
)

Functions

This section is empty.

Types

type ActionType

type ActionType reflect.Type

type ClickAction

type ClickAction interface {
	Name() string   // The ClickAction name.
	Readable() bool // When an clickAction is not readable it will not be unmarshalled.
}
var (
	OpenUrlAction         ClickAction = &clickAction{"open_url", true}
	OpenFileAction        ClickAction = &clickAction{"open_file", false}
	RunCommandAction      ClickAction = &clickAction{"run_command", true}
	SuggestCommandAction  ClickAction = &clickAction{"suggest_command", true}
	ChangePageAction      ClickAction = &clickAction{"change_page", true}
	CopyToClipboardAction ClickAction = &clickAction{"copy_to_clipboard", true}

	ClickActions = func() map[string]ClickAction {
		m := map[string]ClickAction{}
		for _, a := range []ClickAction{
			OpenUrlAction,
			OpenFileAction,
			RunCommandAction,
			SuggestCommandAction,
			ChangePageAction,
			CopyToClipboardAction,
		} {
			m[a.Name()] = a
		}
		return m
	}()
)

type ClickEvent

type ClickEvent interface {
	Action() ClickAction
	Value() string
}

func ChangePage

func ChangePage(page string) ClickEvent

func CopyToClipboard

func CopyToClipboard(text string) ClickEvent

func NewClickEvent

func NewClickEvent(action ClickAction, value string) ClickEvent

func OpenFile

func OpenFile(file string) ClickEvent

func OpenUrl

func OpenUrl(url string) ClickEvent

func RunCommand

func RunCommand(command string) ClickEvent

func SuggestCommand

func SuggestCommand(command string) ClickEvent

type Component

type Component interface {
	Children() []Component
	SetChildren([]Component)
	Style() *Style
}

type Decoration

type Decoration string

Decoration is a text decoration such as "underlined". Use the provided decoration constants.

const (
	// Obfuscated is a decoration which makes text obfuscated/unreadable.
	Obfuscated Decoration = "obfuscated"
	// Bold is a decoration which makes text appear bold.
	Bold Decoration = "bold"
	// Strikethrough is a decoration which makes text have a strike through it.
	Strikethrough Decoration = "strikethrough"
	// Underlined is a decoration which makes text have an underline.
	Underlined Decoration = "underlined"
	// Italic is a decoration which makes text appear in italics.
	Italic Decoration = "italic"
)

Decoration styles

func (Decoration) String

func (d Decoration) String() string

String implements component.Format.

type Format

type Format interface {
	fmt.Stringer
}

Format is text color or decoration.

type HoverAction

type HoverAction interface {
	Name() string
	Type() ActionType
	Readable() bool // When a HoverAction is not readable it will not be unmarshalled.
}
var (
	ShowTextAction   HoverAction = &hoverAction{"show_text", reflect.TypeOf(Text{}), true}
	ShowItemAction   HoverAction = &hoverAction{"show_item", reflect.TypeOf(ShowItemHoverType{}), true}
	ShowEntityAction HoverAction = &hoverAction{"show_entity", reflect.TypeOf(ShowEntityHoverType{}), true}

	HoverActions = func() map[string]HoverAction {
		m := map[string]HoverAction{}
		for _, a := range []HoverAction{
			ShowTextAction,
			ShowItemAction,
			ShowEntityAction,
		} {
			m[a.Name()] = a
		}
		return m
	}()
)

type HoverEvent

type HoverEvent interface {
	Action() HoverAction
	Value() interface{}
}

func NewHoverEvent

func NewHoverEvent(action HoverAction, value interface{}) HoverEvent

func ShowEntity

func ShowEntity(entity *ShowEntityHoverType) HoverEvent

func ShowItem

func ShowItem(item *ShowItemHoverType) HoverEvent

func ShowText

func ShowText(text Component) HoverEvent

type ShowEntityHoverType

type ShowEntityHoverType struct {
	Type key.Key
	Id   uuid.UUID // UUID
	Name Component
}

type ShowItemHoverType

type ShowItemHoverType struct {
	Item  key.Key
	Count int
	NBT   nbt.BinaryTagHolder // nil-able
}

type State

type State uint8

State is a tri-state.

const (
	NotSet State = iota
	True
	False
)

func StateByBool

func StateByBool(b bool) State

func (State) String

func (s State) String() string

type Style

type Style struct {
	Obfuscated, Bold, Strikethrough, Underlined, Italic State

	Font       key.Key
	Color      color.Color
	ClickEvent ClickEvent
	HoverEvent HoverEvent
	Insertion  *string // Gets the string to be inserted when this component is shift-clicked.
}

Style is the style of a Component.

func (*Style) Decoration

func (s *Style) Decoration(decoration Decoration) State

func (*Style) IsZero

func (s *Style) IsZero() bool

IsZero reports whether the Style is the zero value.

func (*Style) SetDecoration

func (s *Style) SetDecoration(decoration Decoration, state State)

type Text

type Text struct {
	Content string
	S       Style
	Extra   []Component
}

func (*Text) Children

func (t *Text) Children() []Component

func (*Text) SetChildren

func (t *Text) SetChildren(children []Component)

func (*Text) Style

func (t *Text) Style() *Style

type Translation

type Translation struct {
	Key  string // Translation key
	S    Style
	With []Component
}

func (*Translation) Children

func (t *Translation) Children() []Component

func (*Translation) SetChildren

func (t *Translation) SetChildren(children []Component)

func (*Translation) Style

func (t *Translation) Style() *Style

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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