Skip to main content

Definition

Struct Definition 

Source
pub struct Definition { /* private fields */ }
Expand description

Defines the structure of a specific version of a database table.

A Definition specifies the exact binary layout and field properties for one version of a table. Tables can have multiple definitions in a schema to support different versions across game patches.

§Version Numbers

  • -1: Fake definition used internally for dependency resolution
  • 0: Unversioned files (tables without version markers in their binary format)
  • 1+: Versioned files with explicit version numbers

§Fields Processing

The raw fields list may undergo processing when accessed via fields_processed():

  • Bitwise fields are expanded into multiple boolean fields
  • Enum fields are converted to string fields
  • RGB colour triplets are merged into single ColourRGB fields

Unless you have a specific reason to do so, it is recommended to use fields_processed() instead of fields.

§Localisation

Some tables have fields that are moved to separate LOC files during export:

Implementations§

Source§

impl Definition

Source

pub fn version(&self) -> &i32

The version number of this table definition.

See type-level documentation for version number meanings.

Source

pub fn fields(&self) -> &Vec<Field>

List of fields in the order they appear in the binary format.

This is the raw field list. For the processed version (with bitwise expansion, enum conversion, etc.), use fields_processed().

Source

pub fn localised_fields(&self) -> &Vec<Field>

Fields that are extracted to LOC files during export.

These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.

Source

pub fn localised_key_order(&self) -> &Vec<u32>

Order of key fields when constructing localisation keys.

This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.

Source

pub fn patches(&self) -> &DefinitionPatch

Runtime patches applied to this definition.

These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.

Source§

impl Definition

Source

pub fn version_mut(&mut self) -> &mut i32

The version number of this table definition.

See type-level documentation for version number meanings.

Source

pub fn fields_mut(&mut self) -> &mut Vec<Field>

List of fields in the order they appear in the binary format.

This is the raw field list. For the processed version (with bitwise expansion, enum conversion, etc.), use fields_processed().

Source

pub fn localised_fields_mut(&mut self) -> &mut Vec<Field>

Fields that are extracted to LOC files during export.

These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.

Source

pub fn localised_key_order_mut(&mut self) -> &mut Vec<u32>

Order of key fields when constructing localisation keys.

This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.

Source

pub fn patches_mut(&mut self) -> &mut DefinitionPatch

Runtime patches applied to this definition.

These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.

Source§

impl Definition

Source

pub fn set_version(&mut self, val: i32) -> &mut Self

The version number of this table definition.

See type-level documentation for version number meanings.

Source

pub fn set_fields(&mut self, val: Vec<Field>) -> &mut Self

List of fields in the order they appear in the binary format.

This is the raw field list. For the processed version (with bitwise expansion, enum conversion, etc.), use fields_processed().

Source

pub fn set_localised_fields(&mut self, val: Vec<Field>) -> &mut Self

Fields that are extracted to LOC files during export.

These fields contain localisable text that gets separated from the main table data when exporting said table to binary format.

Source

pub fn set_localised_key_order(&mut self, val: Vec<u32>) -> &mut Self

Order of key fields when constructing localisation keys.

This specifies the order in which key fields should be concatenated when creating LOC entry keys. Only applies to processed fields.

Source

pub fn set_patches(&mut self, val: DefinitionPatch) -> &mut Self

Runtime patches applied to this definition.

These are loaded from the schema’s patch set and applied when retrieving the definition. Not serialized - they come from the schema’s patches field.

Source§

impl Definition

Implementation of Definition.

Source

pub fn new(version: i32, schema_patches: Option<&DefinitionPatch>) -> Definition

Creates a new empty definition for a specific version.

§Arguments
  • version - The version number for this definition
  • schema_patches - Optional patches to apply to this definition
§Returns

Returns a new empty definition with no fields.

Source

pub fn new_with_fields( version: i32, fields: &[Field], loc_fields: &[Field], schema_patches: Option<&DefinitionPatch>, ) -> Definition

Creates a new definition with the specified fields.

§Arguments
  • version - The version number for this definition
  • fields - The table’s field list
  • loc_fields - The localised fields list
  • schema_patches - Optional patches to apply to this definition
§Returns

Returns a new definition with the provided fields.

Source

pub fn reference_data( &self, ) -> BTreeMap<i32, (String, String, Option<Vec<String>>)>

Returns reference and lookup information for all fields with foreign key references.

This function extracts foreign key information from all fields in the definition that have a reference to another table.

§Returns

Returns a map where:

  • Keys are field indices (as i32)
  • Values are tuples of (referenced_table, referenced_column, optional_lookup_columns)

Only fields with is_reference set are included in the result.

Source

pub fn fields_processed(&self) -> Vec<Field>

Returns the processed field list with transformations applied.

This function processes the raw field list and applies various transformations:

  • Bitwise fields: Expanded into multiple boolean fields (e.g., flagsflags_1, flags_2, etc.)
  • Enum fields: Converted to StringU8 fields
  • Colour fields: RGB triplets merged into single ColourRGB fields
  • Numeric fields: Converted to I32 fields (with patches)

This is the field list that should be used for UI display and data editing.

§Returns

Returns the processed field list with all transformations applied.

Source

pub fn original_field_from_processed(&self, index: usize) -> Field

Returns the original raw field corresponding to a processed field index.

This function maps a field from the processed field list back to its original raw field definition. This is useful when you need to access the underlying field data before transformations like bitwise expansion.

§Arguments
  • index - Index in the processed field list
§Returns

Returns the original field from the raw field list.

§Panics

Panics if the field is not found (which should never happen for valid indices).

§Note

This function does not work correctly with combined colour fields, as they don’t have a direct 1:1 mapping to a single raw field.

Source

pub fn fields_processed_sorted(&self, key_first: bool) -> Vec<Field>

Returns the processed field list sorted by either key fields or CA order.

This function returns the processed fields sorted according to the specified criteria.

§Arguments
  • key_first - If true, sorts key fields first, then non-key fields. If false, sorts by CA order.
§Returns

Returns the sorted field list. Fields with ca_order == -1 are left in their original order when sorting by CA order.

Source

pub fn column_position_by_name(&self, column_name: &str) -> Option<usize>

Returns the position of a column in the processed field list by name.

§Arguments
  • column_name - Name of the column to find
§Returns

Returns the column’s index in the processed field list, or None if not found.

Source

pub fn key_column_positions(&self) -> Vec<usize>

Returns the positions of all key columns in the processed field list.

§Returns

Returns a vector of indices for all fields marked as key fields.

Source

pub fn key_column_positions_by_ca_order(&self) -> Vec<usize>

Returns the positions of all key columns sorted by CA order.

This function returns key column positions in the same order as they appear in CA’s Assembly Kit, rather than the binary order. This is primarily needed for twad_key_deletes functionality, which uses CA’s ordering.

§Returns

Returns a vector of key column indices sorted by their ca_order value.

Source

pub fn update_from_raw_definition( &mut self, raw_definition: &RawDefinition, unfound_fields: &mut Vec<String>, )

Updates field properties from Assembly Kit raw definition data.

This function updates the definition’s fields with data extracted from the Assembly Kit, matching fields by name and updating specific properties. Fields not found in the Assembly Kit are added to the unfound_fields list for reporting.

§Updated Properties
  • is_key: Primary key status
  • default_value: Default value for new rows
  • filename_relative_path: Path hints for filename fields
  • is_filename: Whether the field contains a filename
  • is_reference: Foreign key reference information
  • lookup: Lookup column information
  • description: Field description
  • ca_order: Visual position in Assembly Kit
  • is_part_of_colour: Auto-detected RGB colour field grouping
§Arguments
  • raw_definition - The Assembly Kit definition data
  • unfound_fields - List to append unfound field names to (format: "table_name/field_name")
§Note

Fields in IGNORABLE_FIELDS are automatically skipped and not reported as unfound.

§Feature

This function requires the integration_assembly_kit feature.

Source

pub fn update_from_raw_localisable_fields( &mut self, raw_definition: &RawDefinition, raw_localisable_fields: &[RawLocalisableField], )

Populates the localised_fields list from Assembly Kit data.

This function identifies fields that should be extracted to LOC files based on Assembly Kit localisable field data and updates the definition’s localised_fields list. All identified localised fields are set to FieldType::StringU8 for consistency.

§Arguments
  • raw_definition - The Assembly Kit table definition
  • raw_localisable_fields - List of all localisable fields from the Assembly Kit
§Feature

This function requires the integration_assembly_kit feature.

Trait Implementations§

Source§

impl Clone for Definition

Source§

fn clone(&self) -> Definition

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Definition

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Definition

Source§

fn default() -> Definition

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Definition

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&RawDefinition> for Definition

Source§

fn from(raw_definition: &RawDefinition) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Definition

Source§

fn eq(&self, other: &Definition) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Definition

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Definition

Source§

impl StructuralPartialEq for Definition

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,