Documentation
¶
Index ¶
- Variables
- type Chat
- func (chat *Chat) Close() error
- func (chat *Chat) Subscribe(s Subscriber)
- func (chat *Chat) Subscribed(s Subscriber) bool
- func (chat *Chat) Unsubscribe(s Subscriber)
- func (chat *Chat) Write(p []byte) (n int, err error)
- func (chat *Chat) WriteString(s string) (n int, err error)
- func (chat *Chat) Writet(t Translation, a ...any)
- type StdoutSubscriber
- type Subscriber
- type Translation
- type TranslationString
- type Translator
Constants ¶
This section is empty.
Variables ¶
var Global = New()
Global represents a global chat. Players will write in this chat by default when they send any message in the chat.
var MessageJoin = Translate(str("%multiplayer.player.joined"), 1, `%v joined the game`).Enc("<yellow>%v</yellow>")
var MessageQuit = Translate(str("%multiplayer.player.left"), 1, `%v left the game`).Enc("<yellow>%v</yellow>")
var MessageServerDisconnect = Translate(str("%disconnect.disconnected"), 0, `Disconnected by Server`).Enc("<yellow>%v</yellow>")
Functions ¶
This section is empty.
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat represents the in-game chat. Messages may be written to it to send a message to all subscribers. Methods on Chat may be called from multiple goroutines concurrently. Chat implements the io.Writer and io.StringWriter interfaces. fmt.Fprintf and fmt.Fprint may be used to write formatted messages to the chat.
func (*Chat) Subscribe ¶
func (chat *Chat) Subscribe(s Subscriber)
Subscribe adds a subscriber to the chat, sending it every message written to the chat. In order to remove it again, use Chat.Unsubscribe().
func (*Chat) Subscribed ¶ added in v0.2.0
func (chat *Chat) Subscribed(s Subscriber) bool
Subscribed checks if a subscriber is currently subscribed to the chat.
func (*Chat) Unsubscribe ¶
func (chat *Chat) Unsubscribe(s Subscriber)
Unsubscribe removes a subscriber from the chat, so that messages written to the chat will no longer be sent to it.
func (*Chat) Write ¶
Write writes the byte slice p as a string to the chat. It is equivalent to calling Chat.WriteString(string(p)).
func (*Chat) WriteString ¶
WriteString writes a string s to the chat.
func (*Chat) Writet ¶ added in v0.10.0
func (chat *Chat) Writet(t Translation, a ...any)
Writet writes a Translation message to a Chat, parameterising the message using the arguments passed. Messages are translated according to the locale of subscribers if they implement Translator. Subscribers that do not implement Translator have the fallback message sent.
type StdoutSubscriber ¶
type StdoutSubscriber struct{}
StdoutSubscriber is an implementation of Subscriber that forwards messages sent to the chat to the stdout.
type Subscriber ¶
type Subscriber interface { // UUID returns a unique ID for the Subscriber. UUID() uuid.UUID // Message sends a formatted message to the subscriber. The message is // formatted as it would when using fmt.Println. Message(a ...any) }
Subscriber represents an entity that may subscribe to a Chat. In order to do so, the Subscriber must implement methods to send messages to it.
type Translation ¶ added in v0.10.0
type Translation struct {
// contains filtered or unexported fields
}
Translation represents a TranslationString with additional formatting, that may be filled out by calling F on it with a list of arguments for the translation.
func Translate ¶ added in v0.10.0
func Translate(str TranslationString, params int, fallback string) Translation
Translate returns a Translation for a TranslationString. The required number of parameters specifies how many arguments may be passed to Translation.F. The fallback string should be a 'standard' translation of the string, which is used when translation.String is called on the translation that results from a call to Translation.F. This fallback string should have as many formatting identifiers (like in fmt.Sprintf) as the number of params.
func (Translation) Enc ¶ added in v0.10.0
func (t Translation) Enc(format string) Translation
Enc encapsulates the translation string into the format passed. This format should have exactly one formatting identifier, %v, to specify where the translation string should go, such as 'translation: %v'. Enc accepts colouring formats parsed by text.Colourf.
func (Translation) F ¶ added in v0.10.0
func (t Translation) F(a ...any) translation
F takes arguments for a translation string passed and returns a filled out translation that may be sent to players. The number of arguments passed must be exactly equal to the number specified in Translate. If not, F will panic. Arguments passed are converted to strings using fmt.Sprint(). Exceptions are made for argument values of the type TranslationString, Translation and translation, which are resolved based on the Translator's language. Translations used as arguments should not require any parameters.
func (Translation) Resolve ¶ added in v0.10.0
func (t Translation) Resolve(l language.Tag) string
Resolve passes 0 arguments to the translation and resolves the translation string for the language passed. It is equal to calling t.F().Resolve(l). Resolve panics if the Translation requires at least 1 argument.
func (Translation) Zero ¶ added in v0.10.0
func (t Translation) Zero() bool
Zero returns false if a Translation was not created using Translate or Untranslated.
type TranslationString ¶ added in v0.10.0
type TranslationString interface { // Resolve finds a suitable translated version for a translation string for // a specific language.Tag. Resolve(l language.Tag) string }
TranslationString is a value that can resolve a translated version of itself for a language.Tag passed.
type Translator ¶ added in v0.10.0
type Translator interface { // Messaget sends a Translation message to the Translator, using the // arguments passed to fill out any translation parameters. Messaget(t Translation, a ...any) }
Translator is a Subscriber that is able to translate messages to their own locale.