world

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

Documentation

Overview

Package world and its subpackages contain everything a typical simulated world requires.

Index

Constants

View Source
const (
	// StartingLevel identifies the level a new game is started in by default.
	StartingLevel = 1
	// StartingTileX identifies the default X position of the protagonist.
	StartingTileX = 30
	// StartingTileY identifies the default Y position of the protagonist.
	StartingTileY = 22

	// MaxWorldTextures is the limit of how many textures the engine supports.
	// Note that this value is equal to that of the resource limits in package ids. It is actually based on them.
	MaxWorldTextures = 293
)
View Source
const (
	// TexturePropertiesFilename specifies the lowercase name of the file containing texture properties.
	TexturePropertiesFilename = "textprop.dat"

	// ObjectPropertiesFilename specifies the lowercase name of the file containing object properties.
	ObjectPropertiesFilename = "objprop.dat"
)

Variables

This section is empty.

Functions

func IsConsideredCyberspaceByDefault added in v0.3.0

func IsConsideredCyberspaceByDefault(levelID int) bool

IsConsideredCyberspaceByDefault returns true for those level identifier that are hardcoded to be cyberspace levels. For the vanilla engine, this is true for level 10 and any above 13.

func ResourceViewStrategy

func ResourceViewStrategy() resource.ViewStrategy

ResourceViewStrategy returns a strategy that is typical for the game.

Types

type BlockPatch added in v1.4.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 FileLoadResult added in v1.6.0

type FileLoadResult struct {
	FailedFiles int
	Savegames   map[FileLocation]resource.Viewer
	Resources   map[FileLocation]resource.Viewer

	ObjectProperties  object.PropertiesTable
	TextureProperties texture.PropertiesList
}

FileLoadResult contains all the information of a LoadFiles attempt.

func LoadFiles added in v1.6.0

func LoadFiles(allowZips bool, names []string) FileLoadResult

LoadFiles attempts to load compatible files from the given set of filenames.

type FileLocation added in v1.5.0

type FileLocation struct {
	DirPath string
	Name    string
}

FileLocation describes the path and name of a file.

func FileLocationFrom added in v1.7.0

func FileLocationFrom(filename string) FileLocation

FileLocationFrom returns an instance for given filename.

func (FileLocation) AbsolutePathFrom added in v1.5.0

func (loc FileLocation) AbsolutePathFrom(base string) string

AbsolutePathFrom returns the complete path, based on given base, of the location.

func (FileLocation) NestedRelativeTo added in v1.7.0

func (loc FileLocation) NestedRelativeTo(base string) string

NestedRelativeTo returns a string that describes the relative nested location to given base - if possible.

type LocalizedResources added in v1.4.0

type LocalizedResources struct {
	// File describes from which file the data was possibly loaded from, and where it should be stored in.
	File FileLocation
	// Template specifies the "original" filename the data would be stored in.
	// For example, savegames have "archive.dat" as their template.
	// Note: This could be expanded to be a list. The loader could check which IDs are all stored in the loaded file,
	// and match all corresponding templates. Though, this works only for "Any" language resources.
	Template string
	// Language identifies the language this package of resources is for.
	Language resource.Language
	// Store contains all the resources.
	Store resource.Store
}

LocalizedResources associates a language with a resource store under a specific filename.

type Manifest

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

Manifest contains all the data and information of concrete things in a world.

func NewManifest

func NewManifest(modified resource.ModificationCallback) *Manifest

NewManifest returns a new instance that notifies changes to the provided callback.

func (Manifest) Entry

func (manifest Manifest) Entry(at int) (*ManifestEntry, error)

Entry returns the entry at given index.

func (Manifest) EntryCount

func (manifest Manifest) EntryCount() int

EntryCount returns the number of entries currently in the manifest.

func (Manifest) Filter

func (manifest Manifest) Filter(lang resource.Language, id resource.ID) resource.List

Filter finds all resources in the world that match the given parameters.

func (*Manifest) InsertEntry

func (manifest *Manifest) InsertEntry(at int, entries ...*ManifestEntry) error

InsertEntry puts the provided entries in sequence at the specified index. Any entry at the identified index, and all those after that, are moved behind the given ones.

func (*Manifest) LocalizedResources

func (manifest *Manifest) LocalizedResources(lang resource.Language) resource.Selector

LocalizedResources produces a selector to retrieve resources for a specific language from the manifest. The returned selector has the strategy to merge the typical compound resource lists, such as the small textures, or string lookups. It is based on StandardResourceViewStrategy().

func (*Manifest) MoveEntry

func (manifest *Manifest) MoveEntry(to, from int) error

MoveEntry removes an entry and reinserts it at another index. Both indices are resolved before the move.

func (*Manifest) ObjectProperties added in v0.4.0

func (manifest *Manifest) ObjectProperties() object.PropertiesTable

ObjectProperties returns the table of object properties.

func (*Manifest) RemoveEntry

func (manifest *Manifest) RemoveEntry(at int) error

RemoveEntry removes the entry at given index.

func (*Manifest) ReplaceEntry

func (manifest *Manifest) ReplaceEntry(at int, entry *ManifestEntry) error

ReplaceEntry removes the current entry at the identified index and puts the provided one instead.

func (*Manifest) Reset added in v1.7.0

func (manifest *Manifest) Reset()

Reset clears the manifest by removing all entries and notifying of all the removed resource identifier.

func (*Manifest) TextureProperties added in v1.1.0

func (manifest *Manifest) TextureProperties() texture.PropertiesList

TextureProperties returns the table of texture properties.

type ManifestEntry

type ManifestEntry struct {
	Origin    []string
	ID        string
	Resources resource.LocalizedResourcesList

	ObjectProperties  object.PropertiesTable
	TextureProperties texture.PropertiesList
}

ManifestEntry describes a set of localized resources under a collective identifier.

func NewManifestEntryFrom added in v1.6.0

func NewManifestEntryFrom(names []string) (*ManifestEntry, error)

NewManifestEntryFrom attempts to create a manifest in memory from the given set of files. It uses LoadFiles() to load the files with given filenames into memory, allowing archives as well.

func (ManifestEntry) LocalizedResources

func (entry ManifestEntry) LocalizedResources(lang resource.Language) resource.Selector

LocalizedResources produces a selector to retrieve resources for a specific language from this entry.

type Mod added in v1.4.0

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 added in v1.4.0

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

NewMod returns a new instance.

func (Mod) AllAbsoluteFilenames added in v1.6.0

func (mod Mod) AllAbsoluteFilenames(reference string) []string

AllAbsoluteFilenames returns the list of all filenames currently loaded in the mod.

func (Mod) CreateBlockPatch added in v1.4.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 added in v1.4.0

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) FixListResources added in v1.4.0

func (mod *Mod) FixListResources()

FixListResources ensures all resources that contain resource lists to have maximum size. This is done to ensure compatibility with layered modding in the Source Port branch of engines. These engines will have "lower" mods bleed through only if the block is empty in a "higher" mod. This even counts for entries past the last modified one in the higher mod.

func (*Mod) HasModifiableObjectProperties added in v1.7.0

func (mod *Mod) HasModifiableObjectProperties() bool

HasModifiableObjectProperties returns true if the mod has dedicated object properties.

func (*Mod) HasModifiableTextureProperties added in v1.7.0

func (mod *Mod) HasModifiableTextureProperties() bool

HasModifiableTextureProperties returns true if the mod has dedicated texture properties.

func (*Mod) LastChangeTime added in v1.4.0

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

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

func (Mod) LocalizedResources added in v1.4.0

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

LocalizedResources returns a resource selector for a specific language.

func (*Mod) MarkSave added in v1.4.0

func (mod *Mod) MarkSave()

MarkSave clears the list of modified filenames.

func (Mod) ModifiedBlock added in v1.4.0

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 added in v1.4.0

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

ModifiedBlocks returns all blocks of the modified resource.

func (Mod) ModifiedFilenames added in v1.4.0

func (mod Mod) ModifiedFilenames() []string

ModifiedFilenames returns the list of all filenames suspected of change.

func (Mod) ModifiedResource added in v1.4.0

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 added in v1.4.0

func (mod Mod) ModifiedResources() []*LocalizedResources

ModifiedResources returns the current modification state.

func (*Mod) Modify added in v1.4.0

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

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 v1.4.0

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

ObjectProperties returns the table of object properties.

func (*Mod) Reset added in v1.4.0

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 v1.4.0

func (mod *Mod) ResetLastChangeTime()

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

func (*Mod) TextureProperties added in v1.4.0

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

TextureProperties returns the list of texture properties.

func (Mod) World added in v1.4.0

func (mod Mod) World() *Manifest

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

type ModData added in v1.4.0

type ModData struct {
	FileChangeCallback func(string)

	LocalizedResources []*LocalizedResources
	ObjectProperties   object.PropertiesTable
	TextureProperties  texture.PropertiesList
}

ModData contains the core information about a mod.

func (*ModData) DelResource added in v1.4.0

func (data *ModData) DelResource(lang resource.Language, id resource.ID)

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

func (*ModData) PatchResourceBlock added in v1.4.0

func (data *ModData) 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 (*ModData) SetObjectProperties added in v1.4.0

func (data *ModData) SetObjectProperties(triple object.Triple, properties object.Properties)

SetObjectProperties updates the properties of a specific object.

func (*ModData) SetResourceBlock added in v1.4.0

func (data *ModData) SetResourceBlock(lang resource.Language, id resource.ID, index int, blockData []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.

func (*ModData) SetResourceBlocks added in v1.4.0

func (data *ModData) SetResourceBlocks(lang resource.Language, id resource.ID, blocks [][]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 (*ModData) SetTextureProperties added in v1.4.0

func (data *ModData) SetTextureProperties(index int, properties texture.Properties)

SetTextureProperties updates the properties of a specific texture.

type ModResetCallback added in v1.4.0

type ModResetCallback func()

ModResetCallback is called when the mod was reset.

type ModTransaction added in v1.4.0

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

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

func (*ModTransaction) DelResource added in v1.4.0

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 v1.4.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) SetObjectProperties added in v1.4.0

func (trans *ModTransaction) SetObjectProperties(triple object.Triple, properties object.Properties)

SetObjectProperties updates the properties of a specific object.

func (*ModTransaction) SetResourceBlock added in v1.4.0

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 added in v1.4.0

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.4.0

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

SetTextureProperties updates the properties of a specific texture.

type Modder added in v1.4.0

type Modder interface {

	// 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.
	SetResourceBlock(lang resource.Language, id resource.ID, index int, data []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(). (see also: Mod.CreateBlockPatch)
	PatchResourceBlock(lang resource.Language, id resource.ID, index int, expectedLength int, patch []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).
	SetResourceBlocks(lang resource.Language, id resource.ID, data [][]byte)

	// 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.
	DelResource(lang resource.Language, id resource.ID)

	// SetTextureProperties updates the properties of a specific texture.
	SetTextureProperties(textureIndex int, properties texture.Properties)

	// SetObjectProperties updates the properties of a specific object.
	SetObjectProperties(triple object.Triple, properties object.Properties)
}

Modder describes actions meant to modify resources.

Directories

Path Synopsis
Package ids contains constants for all necessary identifier used in the world.
Package ids contains constants for all necessary identifier used in the world.

Jump to

Keyboard shortcuts

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