model

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockPatch added in v0.3.0

type BlockPatch struct {
	// ID identifier of the resource
	ID resource.ID
	// BlockIndex identifies the block for which the patch applies.
	BlockIndex int
	// BlockLength describes the expected length of the block.
	BlockLength int

	// ForwardData contains the delta information to patch to a new version.
	ForwardData []byte
	// ReverseData contains the delta information to change a new version back to the original.
	ReverseData []byte
}

BlockPatch describes a raw delta-change of a resource block. The change can be applied, and reverted.

type IdentifiedResources

type IdentifiedResources map[resource.ID]*MutableResource

IdentifiedResources is a map of mutable resources by their identifier.

func MutableResourcesFromProvider

func MutableResourcesFromProvider(filename string, provider resource.Provider) IdentifiedResources

MutableResourcesFromProvider returns MutableResource instances based on a provider. This function retrieves all data from the provider.

func (IdentifiedResources) Add

Add puts the entries of the provided container into this container.

func (IdentifiedResources) IDs

func (res IdentifiedResources) IDs() []resource.ID

IDs returns a list of all IDs in the map.

func (IdentifiedResources) Resource

func (res IdentifiedResources) Resource(id resource.ID) (*resource.Resource, error)

Resource returns the mutable resource as a read-only view.

type LocalizedResources

type LocalizedResources map[resource.Language]IdentifiedResources

LocalizedResources is a map of identified resources by language.

func NewLocalizedResources

func NewLocalizedResources() LocalizedResources

NewLocalizedResources returns a new instance, prepared for all language keys.

type Mod

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

Mod is the central object for a game-mod.

It is based on a "static" world and adds its own changes. The world data itself is not static, it is merely the unchangeable background for the mod. Changes to the mod are kept in a separate layer, which can be loaded and saved.

func NewMod

func NewMod(resourcesChanged resource.ModificationCallback, resetCallback ModResetCallback) *Mod

NewMod returns a new instance.

func (Mod) CreateBlockPatch added in v0.3.0

func (mod Mod) CreateBlockPatch(lang resource.Language, id resource.ID, index int, newData []byte) (BlockPatch, bool, error)

CreateBlockPatch creates delta information for a block witch static data length. The returned patch structure contains details for both modifying the current state to be equal the new state, as well as the reversal delta. These deltas are calculated using the rle compression package. The returned boolean indicates whether the data differs. This can be used to detect whether the patch is necessary. An error is returned if the resource or the block do not exist, or if the length of newData does not match that of the block.

If no error is returned, both the patch and the boolean provide valid information - even if the data is equal.

func (Mod) Filter

func (mod Mod) Filter(lang resource.Language, id resource.ID) resource.List

Filter returns a list of resources that match the given parameters.

func (*Mod) HasModifyableTextureProperties added in v1.1.0

func (mod *Mod) HasModifyableTextureProperties() bool

HasModifyableTextureProperties returns true if the mod has dedicated texture properties.

func (*Mod) LastChangeTime added in v0.5.0

func (mod *Mod) LastChangeTime() time.Time

LastChangeTime returns the timestamp of the last change. Zero if not modified.

func (Mod) LocalizedResources

func (mod Mod) LocalizedResources(lang resource.Language) resource.Selector

LocalizedResources returns a resource selector for a specific language.

func (*Mod) MarkSave added in v0.5.0

func (mod *Mod) MarkSave()

MarkSave clears the list of modified filenames.

func (Mod) ModifiedBlock

func (mod Mod) ModifiedBlock(lang resource.Language, id resource.ID, index int) (data []byte)

ModifiedBlock retrieves the specific block identified by given parameter. Returns empty slice if the block (or resource) is not modified.

func (Mod) ModifiedBlocks

func (mod Mod) ModifiedBlocks(lang resource.Language, id resource.ID) [][]byte

ModifiedBlocks returns all blocks of the modified resource.

func (Mod) ModifiedFilenames added in v0.5.0

func (mod Mod) ModifiedFilenames() []string

ModifiedFilenames returns the list of all filenames suspected of change.

func (Mod) ModifiedResource

func (mod Mod) ModifiedResource(lang resource.Language, id resource.ID) resource.View

ModifiedResource retrieves the resource of given language and ID. There is no fallback lookup, it will return the exact resource stored under the provided identifier. Returns nil if the resource does not exist.

func (Mod) ModifiedResources

func (mod Mod) ModifiedResources() LocalizedResources

ModifiedResources returns the current modification state.

func (*Mod) Modify

func (mod *Mod) Modify(modifier func(*ModTransaction))

Modify requests to change the mod. The provided function will be called to collect all changes. After the modifier completes, all the requests will be applied and any changes notified.

func (*Mod) ObjectProperties added in v0.4.0

func (mod *Mod) ObjectProperties() object.PropertiesTable

ObjectProperties returns the table of object properties.

func (Mod) Path

func (mod Mod) Path() string

Path returns the path where the mod is loaded from/saved to.

func (*Mod) Reset

func (mod *Mod) Reset(newResources LocalizedResources, objectProperties object.PropertiesTable, textureProperties texture.PropertiesList)

Reset changes the mod to a new set of resources.

func (*Mod) ResetLastChangeTime added in v0.5.0

func (mod *Mod) ResetLastChangeTime()

ResetLastChangeTime clears the last change timestamp. It will be set again at the next modification.

func (*Mod) SetPath

func (mod *Mod) SetPath(p string)

SetPath sets the path where the mod is loaded from/saved to.

func (*Mod) TextureProperties added in v1.1.0

func (mod *Mod) TextureProperties() texture.PropertiesList

TextureProperties returns the list of texture properties.

func (Mod) World

func (mod Mod) World() *world.Manifest

World returns the static background to the mod. Changes in the returned manifest may cause change callbacks being forwarded.

type ModResetCallback

type ModResetCallback func()

ModResetCallback is called when the mod was reset.

type ModTransaction

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

ModTransaction is used to modify a mod. It allows modifications of related resources in one atomic action.

func (*ModTransaction) DelResource

func (trans *ModTransaction) DelResource(lang resource.Language, id resource.ID)

DelResource removes a resource from the mod in the given language.

After the deletion, all the underlying data of the world will become visible again.

func (*ModTransaction) PatchResourceBlock added in v0.3.0

func (trans *ModTransaction) PatchResourceBlock(lang resource.Language, id resource.ID, index int, expectedLength int, patch []byte)

PatchResourceBlock modifies an existing block. This modification assumes the block already exists and can take the given patch data. The patch data is expected to be produced by rle.Compress().

func (*ModTransaction) SetResource

func (trans *ModTransaction) SetResource(id resource.ID,
	compound bool, contentType resource.ContentType, compressed bool)

SetResource changes the meta information about a resource. Should the resource exist in multiple languages, all are modified.

This is a low-level function and should not be required on a regular basis. Mods typically extend on already existing resources, and/or the editor itself should have a list of templates for new resources.

func (*ModTransaction) SetResourceBlock

func (trans *ModTransaction) SetResourceBlock(lang resource.Language, id resource.ID, index int, data []byte)

SetResourceBlock changes the block data of a resource.

If the block data is not empty, then: If the resource does not exist, it will be created with default meta information. If the block does not exist, the resource is extended to allow its addition.

If the block data is empty (or nil), then the block is cleared. If the resource is a compound list, then the underlying data will become visible again.

func (*ModTransaction) SetResourceBlocks

func (trans *ModTransaction) SetResourceBlocks(lang resource.Language, id resource.ID, data [][]byte)

SetResourceBlocks sets the entire list of block data of a resource. This method is primarily meant for compound non-list resources (e.g. text pages).

func (*ModTransaction) SetTextureProperties added in v1.1.0

func (trans *ModTransaction) SetTextureProperties(textureIndex level.TextureIndex, properties texture.Properties)

SetTextureProperties updates the properties of a specific texture.

type MutableResource

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

MutableResource describes a resource open for modification.

func (MutableResource) Block

func (res MutableResource) Block(index int) (io.Reader, error)

Block returns a reader for the identified block.

func (MutableResource) BlockCount

func (res MutableResource) BlockCount() int

BlockCount returns the number of blocks in this resource.

func (MutableResource) Compound

func (res MutableResource) Compound() bool

Compound returns true if the resource holds zero, one, or more blocks.

func (MutableResource) Compressed

func (res MutableResource) Compressed() bool

Compressed returns true if the resource shall be serialized in compressed form.

func (MutableResource) ContentType

func (res MutableResource) ContentType() resource.ContentType

ContentType describes how the data shall be interpreted.

func (MutableResource) Filename

func (res MutableResource) Filename() string

Filename returns the file this resource should be stored in.

Jump to

Keyboard shortcuts

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