Documentation ¶
Overview ¶
Package resource provides interfaces and primitives for low-level handling of resources.
Index ¶
- Constants
- func ErrBlockNotFound(index, available int) error
- func ErrNotFound(id ID) error
- func ErrWrongType(key Key, expected ContentType) error
- type Block
- type BlockNotFoundError
- type BlockProvider
- type Blocks
- type ChangeNotifier
- type ContentType
- type Filter
- type ID
- type IDMarkerMap
- type Key
- type Language
- type List
- type LocalizedResources
- type LocalizedResourcesList
- type Localizer
- type ModificationCallback
- type NotFoundError
- type Properties
- type Resource
- type Selector
- type Store
- type View
- type ViewStrategy
- type Viewer
- type WrongTypeError
Constants ¶
const ( // Palette refers to color tables. Palette = ContentType(0x00) // Text refers to texts. Text = ContentType(0x01) // Bitmap refers to images. Bitmap = ContentType(0x02) // Font refers to font descriptions. Font = ContentType(0x03) // Animation refers to graphical animations. Animation = ContentType(0x04) // Sound refers to audio samples. Sound = ContentType(0x07) // Geometry refers to 3D models. Geometry = ContentType(0x0F) // Movie refers to audio logs and cutscenes. Movie = ContentType(0x11) // Archive refers to archive data. Archive = ContentType(0x30) )
Variables ¶
This section is empty.
Functions ¶
func ErrBlockNotFound ¶ added in v1.8.0
ErrBlockNotFound returns an error specifying the given index does not identify a valid block.
func ErrNotFound ¶ added in v1.8.0
ErrNotFound returns an error specifying the given ID doesn't have an associated resource.
func ErrWrongType ¶ added in v1.8.0
func ErrWrongType(key Key, expected ContentType) error
ErrWrongType returns an error specifying a resource was of unexpected type.
Types ¶
type Block ¶ added in v1.4.0
type Block []byte
Block is one set of bytes stored in a resource. The interpretation of the bytes is dependent on the content type of the resource.
type BlockNotFoundError ¶ added in v1.8.0
BlockNotFoundError indicates the unknown block index.
func (BlockNotFoundError) Error ¶ added in v1.8.0
func (err BlockNotFoundError) Error() string
Error implements the error interface.
type BlockProvider ¶
type BlockProvider interface { // BlockCount returns the number of available blocks in the resource. // Simple resources will always have exactly one block. BlockCount() int // Block returns the reader for the identified block. // Each call returns a new reader instance. // Data provided by this reader is always uncompressed. Block(index int) (io.Reader, error) }
BlockProvider are capable of returning block data of a resource.
type Blocks ¶ added in v1.4.0
type Blocks struct {
// contains filtered or unexported fields
}
Blocks is a list of blocks in memory.
func BlocksFrom ¶ added in v1.4.0
BlocksFrom returns a blocks instance from given data.
func (Blocks) Block ¶ added in v1.4.0
Block returns the reader for the identified block. Each call returns a new reader instance.
func (Blocks) BlockCount ¶ added in v1.4.0
BlockCount returns the number of available blocks.
func (Blocks) BlockRaw ¶ added in v1.4.0
BlockRaw returns the raw byte slice stored in the identified block.
type ChangeNotifier ¶
type ChangeNotifier struct { Localizer Localizer Callback ModificationCallback }
ChangeNotifier is a utility that assists in detecting changes in modifying resources. A callback is called for any resource identifier that refers to resources that are different after a modification.
Use this utility in combination to resource lists where resources can be overwritten by other entries. Changes in order, or content, affects how a resource is resolved.
func (ChangeNotifier) ModifyAndNotify ¶
func (notifier ChangeNotifier) ModifyAndNotify(modifier func(), affectedIDs ...[]ID)
ModifyAndNotify must be called with a range of affected IDs that will change during the call of the modifier. A hash snapshot is taken before and after the modifier, considering the affected IDs. Any change is then reported to the callback, listing all IDs that have different hashes.
Hashing the resources considers all languages, as well as the meta-information of the resources.
type ContentType ¶
type ContentType byte
ContentType identifies how resource data shall be interpreted.
func (ContentType) String ¶ added in v1.2.0
func (t ContentType) String() string
String returns the textual representation of the type.
type ID ¶
type ID uint16
ID represents an integer key of resources.
type IDMarkerMap ¶
type IDMarkerMap struct {
// contains filtered or unexported fields
}
IDMarkerMap is used to collect IDs.
func (IDMarkerMap) ToList ¶
func (marker IDMarkerMap) ToList() []ID
ToList converts the map to a de-duplicated list.
type Key ¶
type Key struct { // ID identifies the resource. ID ID // Lang localizes the resource, should the actual content be localized. Lang Language // Index specifies the exact entry within a resource. Index int }
Key identifies a particular resource out of a combination of a resource ID, a language, and a block index.
Keys are used for retrieving particular content that is stored in resources. Not all resources contain only one atomic entity.
type Language ¶
type Language byte
Language defines the human language of a resource.
const ( // LangAny identifies language agnostic resources. LangAny Language = 0xFF // LangDefault identifies the default language, typically English - unless modded. LangDefault Language = 0 // LangFrench identifies the French language. LangFrench Language = 1 // LangGerman identifies the German language. LangGerman Language = 2 // LanguageCount specifies how many languages are supported. LanguageCount = 3 )
func Languages ¶
func Languages() []Language
Languages returns a slice of all human languages. Does not include "Any" selector.
type List ¶
type List []View
List is a helper type for slices of resources. Although the length of the list is immutable, the content and the fields are not. Meaning, modifying the cells of one list may affect the cells of others.
type LocalizedResources ¶
type LocalizedResources struct { // ID is the identifier of the viewer. This could be a filename for instance. ID string // Language specifies for which language the viewer has resources. Language Language // Viewer is the actual container of the resources. Viewer Viewer }
LocalizedResources associates a language with a resource viewer under a specific identifier.
type LocalizedResourcesList ¶
type LocalizedResourcesList []LocalizedResources
LocalizedResourcesList is a collection of localized resources. it exists to provide a typical implementation of a Selector.
type ModificationCallback ¶
ModificationCallback is a callback function to notify a change in resources.
type NotFoundError ¶ added in v1.8.0
type NotFoundError struct {
ID ID
}
NotFoundError indicates the unknown ID.
func (NotFoundError) Error ¶ added in v1.8.0
func (err NotFoundError) Error() string
Error implements the error interface.
type Properties ¶ added in v1.4.0
type Properties struct { // Compound tells whether the resource should be serialized with a directory. // Compound resources can have zero, one, or more blocks. // Simple resources always have exactly one block. Compound bool // ContentType describes how the block data shall be interpreted. ContentType ContentType // Compressed tells whether the data shall be serialized in compressed form. Compressed bool }
Properties describe the meta information about a resource.
type Resource ¶
type Resource struct { Properties Blocks }
Resource provides meta information as well as access to its contained blocks.
func (Resource) Compound ¶
Compound tells whether the resource should be serialized with a directory. Compound resources can have zero, one, or more blocks. Simple resources always have exactly one block.
func (Resource) Compressed ¶
Compressed tells whether the data shall be serialized in compressed form.
func (Resource) ContentType ¶
func (res Resource) ContentType() ContentType
ContentType describes how the block data shall be interpreted.
type Selector ¶
type Selector struct { // Lang specifies the language to filter by. Lang Language // From specifies from where the resources shall be taken. From Filter // As defines how the found resources should be viewed in case more than one matches. // By default, the last resource will be used. As ViewStrategy }
Selector provides a merged view of resources according to a language.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds a set of resources. This set can be modified.
func (*Store) Put ¶
Put (re-)assigns an identifier with data. If no resource with given ID exists, then it is created. Existing resources are overwritten with the provided data.
type View ¶
type View interface { // Compound tells whether the resource should be serialized with a directory. // Compound resources can have zero, one, or more blocks. // Simple resources always have exactly one block. Compound() bool // ContentType describes how the block data shall be interpreted. ContentType() ContentType // Compressed tells whether the data shall be serialized in compressed form. Compressed() bool // BlockCount returns the number of available blocks in the resource. // Simple resources will always have exactly one block. BlockCount() int // Block returns the reader for the identified block. // Each call returns a new reader instance. // Data provided by this reader is always uncompressed. Block(index int) (io.Reader, error) }
View is a read-only view on a selected resource.
type ViewStrategy ¶
type ViewStrategy interface { // IsCompoundList returns true for compound resources where each contained block is a separate entity. // Separate entities are those that can be replaced without affecting others. // Examples are the small game textures and the list of object names. IsCompoundList(id ID) bool }
ViewStrategy defines how selected resources shall be viewed.
type Viewer ¶ added in v1.4.0
type Viewer interface { // IDs returns a list of available IDs this viewer can provide. IDs() []ID // View returns a read-only view to a resource for the given identifier. View(id ID) (View, error) }
Viewer provides resources from some storage.
type WrongTypeError ¶ added in v1.8.0
type WrongTypeError struct { Key Key Expected ContentType }
WrongTypeError indicates a resource of unexpected type.
func (WrongTypeError) Error ¶ added in v1.8.0
func (err WrongTypeError) Error() string
Error implements the error interface.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package lgres implements serialization of resources using the DOS format.
|
Package lgres implements serialization of resources using the DOS format. |
internal/compression
Package compression implements the LG resource file compression algorithm.
|
Package compression implements the LG resource file compression algorithm. |