Class WorldDataModel
Represents a WorldData resource: the placement of a world's lots and the objects of the world outside them (🔓)
public sealed class WorldDataModel : Model, IModel<WorldDataModel>, IModel
- Inheritance
-
WorldDataModel
- Implements
- Inherited Members
Remarks
A world file is a package (see DataBasePackedFile); this models one of the resources in it, not the file.
The resource is a tree of tagged chunks (OMGS, holding OMGR object managers, holding ID, LOT and OBJ chunks).
Decode(ReadOnlyMemory<byte>) supports the chunks the game's world files contain and rejects the others the game can also read (MODL, DEFG, LEVL, SCRP, TRES, REFS, SIZY), whose layouts are not established.
Encode() writes the chunks in the order the game's world files do, so decoding and encoding one of them reproduces it byte for byte.
Older world files lack the SNOW and OPRP chunks of objects; the corresponding properties are then null and are not written.
The game names the resource after its world file; see GetKey(string).
Properties
ObjectManagers
Gets the object managers
public Collection<WorldDataObjectManager> ObjectManagers { get; }
Property Value
ResourceName
Gets the name of this resource if it has one
public override string? ResourceName { get; }
Property Value
SupportedTypes
Gets a list of resource types that this model supports
public static ISet<ResourceType> SupportedTypes { get; }
Property Value
Methods
Decode(ReadOnlyMemory<byte>)
Decodes the resource in raw format to produce an operable model (🔄️🏃)
public static WorldDataModel Decode(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>
Returns
Exceptions
- InvalidDataException
The data is not a well-formed world data resource, or it contains a chunk this model does not support
Encode()
Encodes the resource model into raw format (🔄️🏃)
public override ReadOnlyMemory<byte> Encode()
Returns
GetKey(string)
Gets the key the game gives the WorldData resource of the world file named worldFileName (such as EP01_AlienWorld_01 or EP01_AlienWorld_01.world)
public static ResourceKey GetKey(string worldFileName)
Parameters
worldFileNamestring
Returns
Remarks
The game derives the key from a file name: the instance is the FNV-1 64-bit hash of the world file's name without its extension, lowercased, and the type is the FNV-1 32-bit hash of the extension dworld.
GetName(Stream)
Gets the name of a resource from its raw data, if it has one (🔄️💤)
public static string? GetName(Stream stream)
Parameters
streamStream
Returns
GetNameAsync(Stream, CancellationToken)
Gets the name of a resource from its raw data, if it has one, asynchronously (🔄️💤)
public static Task<string?> GetNameAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamcancellationTokenCancellationToken