xmls

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2024 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package xmls is unstable. It contains functionality for reading some of the OpenTibia Server's XML data files besides just items.xml, but there are no guarantees on its name or stability.

Index

Constants

View Source
const (
	OutfitTypeMale   = OutfitType("male")
	OutfitTypeFemale = OutfitType("female")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Namespace added in v0.0.9

type Namespace struct {
	xml.Name  `xml:"namespace,omitempty"`
	Key       string `xml:"key,attr,omitempty"`
	Case      string `xml:"case,attr,omitempty"`
	Namespace string `xml:",chardata"`
}

Namespace is a Go representation of the MediaWiki dump element 'namespace'.

Experimental. Temporarily public.

type Object added in v0.0.9

type Object map[string]string

Object is a map[string]string representation of an infobox of type 'Object', representing a Tibia item / 'object'.

func (Object) Article added in v0.0.9

func (o Object) Article() string

Article returns the English language article used in front of the item's name, e.g 'an' for 'an apple'.

func (Object) BuyFrom added in v0.0.9

func (o Object) BuyFrom() []string

BuyFrom processes a comma-separated list of names of who the item can be bought from.

func (Object) ItemIDs added in v0.0.9

func (o Object) ItemIDs() []int

ItemIDs processes and returns a slice of ints containing client IDs for the item described in the infobox.

The version for which the clientIDs apply is not specified, but spotchecking, seems to be fine for 8.54 uses.

func (Object) Name added in v0.0.9

func (o Object) Name() string

Name returns the item's name.

func (Object) Pickupable added in v0.0.9

func (o Object) Pickupable() bool

Pickupable returns whether an item can be picked up.

type Outfit

type Outfit struct {
	ID      int               `xml:"id,attr"`
	Premium int               `xml:"premium,attr"`
	Default string            `xml:"default,attr"`
	List    []OutfitListEntry `xml:"list"`
}

type OutfitListEntry

type OutfitListEntry struct {
	Type     OutfitType `xml:"type,attr"`
	LookType int        `xml:"looktype,attr"`
	Name     string     `xml:"name,attr"`
}
func (c *OutfitListEntry) Temp__ExternalLink() string

n.b. this belongs not in outfit definition but in creature definition

(and by creature, this means NPCs and enemies -- so not even in Things)

func (c *OutfitListEntry) Temp__ExternalLootStatsLink() string

n.b. this belongs not in outfit definition but in creature definition

(and by creature, this means NPCs and enemies -- so not even in Things)

type OutfitType

type OutfitType string

type Outfits

type Outfits struct {
	xml.Name `xml:"outfits"`
	Outfit   []Outfit `xml:"outfit"`
}

func ReadOutfits

func ReadOutfits(r io.Reader) (Outfits, error)

type Page added in v0.0.9

type Page struct {
	Namespace int        `xml:"ns,omitempty"`
	ID        int        `xml:"id,omitempty"`
	Title     string     `xml:"title,omitempty"`
	Revisions []Revision `xml:"revision,omitempty"`
}

Page is a Go representation of the MediaWiki dump element 'page'.

It is a set of revisions of a page's content and metadata, along with its own metadata.

Experimental. Temporarily public.

type Revision added in v0.0.9

type Revision struct {
	ID int `xml:"id,omitempty"`
	// parentid, timestamp, contributor, comment, origin, ...
	Model  string `xml:"model,omitempty"`
	Format string `xml:"format,omitempty"` // mime
	Text   []Text `xml:"text,omitempty"`
}

Revision is a Go representation of the MediaWiki dump element 'revision'.

It is a single stored version of a page's content and metadata, essentially a 'commit' in version control systems.

Experimental. Temporarily public.

type SiteInfo added in v0.0.9

type SiteInfo struct {
	SiteName   string      `xml:"sitename,omitempty"`
	DBName     string      `xml:"dbname,omitempty"`
	Base       string      `xml:"base,omitempty"`
	Generator  string      `xml:"generator,omitempty"`
	Case       string      `xml:"case,omitempty"`
	Namespaces []Namespace `xml:"namespaces,omitempty"`
}

SiteInfo is a Go representation of the MediaWiki dump element 'siteinfo'.

Experimental. Temporarily public.

type Text added in v0.0.9

type Text struct {
	Bytes int    `xml:"bytes,omitempty"` // size
	SHA1  string `xml:"sha1,omitempty"`
	// xml:space="preserve"
	Content string `xml:",chardata"` // actual content
}

Text is a Go representation of the MediaWiki dump element 'text'.

Experimental. Temporarily public.

func (*Text) CleanedContent added in v0.0.9

func (t *Text) CleanedContent() string

CleanedContent attempts to provide just the bare minimum infobox content from the text.

Some pages have "<noinclude>blob</noinclude>" before infobox, we need to trim that out first.

Ideally we'd just extract the bits that are inside '{{Infobox .. }}' by parsing it all properly, but this is a good enough hack.

func (*Text) Object added in v0.0.9

func (t *Text) Object() (Object, error)

Object turns Text into an Object, a map representation of the Object infobox contained in a wiki page.

type WikiLoader added in v0.0.9

type WikiLoader struct {
	// contains filtered or unexported fields
}

WikiLoader is a streaming XML reader of the mediawiki dump of the Tibia wiki.

Wiki loading functionality is experimental and public API will change.

Prior art includes ot-monster-converter written in C#: https://github.com/soul4soul/ot-monster-converter which focuses on converting creature information. However, the current code in Go has not been written by referring to this codebase.

func NewWikiLoader added in v0.0.9

func NewWikiLoader(r io.ReadSeekCloser) *WikiLoader

NewWikiLoader prepares a streaming read, which can then be done in a loop by invoking the Step function.

func (*WikiLoader) CloseStream added in v0.0.9

func (e *WikiLoader) CloseStream()

Complete reading and close the read stream etc.

func (*WikiLoader) DecodeElement added in v0.0.9

func (e *WikiLoader) DecodeElement(v interface{}, start *xml.StartElement) error

DecodeElement decodes the document from the current start element to the matching close element.

func (*WikiLoader) InnerXML added in v0.0.9

func (e *WikiLoader) InnerXML(se xml.StartElement) (string, error)

func (*WikiLoader) ReadPage added in v0.0.9

func (e *WikiLoader) ReadPage(se *xml.StartElement) error

ReadPage reads the toplevel element 'page' describing a single wiki page.

It should emit the pages into a channel, but currently does not do anything like that, and just prints them out.

Something else should be receiving the pages, determining what they are, and emit the translated objects (Object, Creature, ...) if supported and desired.

func (*WikiLoader) ReadSiteinfo added in v0.0.9

func (e *WikiLoader) ReadSiteinfo(se *xml.StartElement) error

ReadSiteinfo reads the toplevel element 'siteinfo'.

func (*WikiLoader) Skip added in v0.0.9

func (e *WikiLoader) Skip() error

Skip skips processing from the current start element to the close element.

func (*WikiLoader) Step added in v0.0.9

func (e *WikiLoader) Step() bool

Step is a single step in processing the XML.

It will read the startelement for the outer <mediawiki> tag, then individual startelements for its children <siteinfo>, <page>, etc.

We can afford to parse one page at a time, as individual pages are not going to be that large; it's just the overall XML that is too large.

Reads should continue as long as false is returned. NOTE: This may change into true, for consistency with Scanner.

func (*WikiLoader) XMLRawToken added in v0.0.9

func (e *WikiLoader) XMLRawToken() (xml.Token, error)

func (*WikiLoader) XMLToken added in v0.0.9

func (e *WikiLoader) XMLToken() (xml.Token, error)

Jump to

Keyboard shortcuts

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