Toast Engine
Loading...
Searching...
No Matches
assets::Prefab Class Referencefinal
Inheritance diagram for assets::Prefab:
Collaboration diagram for assets::Prefab:

Classes

struct  Field
 One field value read from a prefab file. More...
struct  Subgroup
 A named sub-section of fields within a group. More...
struct  Group
 A named group of fields and optional subgroups. More...
struct  LuaVarOverride
 Inspector Lua script variable that differs from its declared default. More...
struct  SignalConnection
struct  Signal
struct  BasicNode
 One node entry in a prefab file. More...

Public Types

enum class  Purpose : uint8_t { asset_definition , instance_copy , editor_snapshot }

Public Member Functions

 Prefab (std::istream &file)
 Parses a prefab from a text (.tnode) stream.
 Prefab (std::span< const uint8_t > bytes)
 Parses a prefab from a binary (.tbnode) byte span.
 Prefab (const toast::Node &node, toast::UID self_uid=toast::UID(0), Purpose purpose=Purpose::asset_definition)
 Serializes a live node tree into a Prefab object.
 Prefab (const Prefab &other)
 Prefab (Prefab &&other) noexcept
auto operator= (const Prefab &other) -> Prefab &
auto operator= (Prefab &&other) noexcept -> Prefab &
auto type () const -> std::string_view override
auto serialize (SaveMode mode) const -> std::vector< uint8_t > override
 Convenience wrapper that delegates to toFile() or toBinary() based on mode.
auto toFile () const -> std::string
 Serializes to the human-readable text format.
auto toBinary () const -> std::vector< uint8_t >
 Serializes to the compact binary format.
auto validate () const -> bool
 Checks structural invariants.
Public Member Functions inherited from assets::Asset
 Asset (const Asset &)=delete
auto operator= (const Asset &) -> Asset &=delete
auto refCount () const noexcept -> uint32_t

Static Public Member Functions

static auto stringifyValue (toast::FieldType type, bool is_array, const std::any &value) -> std::string
 Converts a reflected field value to its text representation.
static auto valueFromString (toast::FieldType type, bool is_array, std::string_view value) -> std::optional< std::any >
 Parses a text value back into a typed std::any for a reflected field.

Public Attributes

std::vector< Field > global_fields
std::vector< BasicNode > nodes

Additional Inherited Members

Protected Member Functions inherited from assets::Asset
void addRef () noexcept
void release () noexcept

Constructor & Destructor Documentation

◆ Prefab() [1/3]

assets::Prefab::Prefab ( std::istream & file)

Parses a prefab from a text (.tnode) stream.

Parameters
fileOpen input stream positioned at the start of the file
Note
The text format is human-readable; missing or unknown fields are silently skipped
Here is the caller graph for this function:

◆ Prefab() [2/3]

assets::Prefab::Prefab ( std::span< const uint8_t > bytes)

Parses a prefab from a binary (.tbnode) byte span.

Parameters
bytesRaw file bytes; must start with the TNODE magic header
Note
The binary header contains a version field; a mismatch logs a warning but loading is still attempted

◆ Prefab() [3/3]

assets::Prefab::Prefab ( const toast::Node & node,
toast::UID self_uid = toast::UID(0),
Purpose purpose = Purpose::asset_definition )
explicit

Serializes a live node tree into a Prefab object.

Parameters
nodeThe root node of the tree to serialize; all descendants are included
self_uidUID of this prefab asset on disk; stored in m_self_uid to detect self-referencing loops during instantiation

Member Function Documentation

◆ serialize()

auto assets::Prefab::serialize ( SaveMode mode) const -> std::vector< uint8_t >
overridevirtual

Convenience wrapper that delegates to toFile() or toBinary() based on mode.

Parameters
modeSaveMode::editor produces text; SaveMode::game produces binary
Returns
Serialized bytes

Implements assets::ISaveable.

Here is the caller graph for this function:

◆ stringifyValue()

auto assets::Prefab::stringifyValue ( toast::FieldType type,
bool is_array,
const std::any & value ) -> std::string
static

Converts a reflected field value to its text representation.

Parameters
typeSerialization kind of the value
is_arrayTrue if value holds a std::vector of the field type
valueThe value as returned by a FieldInfo getter
Returns
The same text encoding used by the .node text format
Note
Shared by the text serializer and the editor inspector so both agree on formatting
Here is the caller graph for this function:

◆ toBinary()

auto assets::Prefab::toBinary ( ) const -> std::vector< uint8_t >

Serializes to the compact binary format.

Returns
The .tnode file bytes, including the magic header and version
Here is the caller graph for this function:

◆ toFile()

auto assets::Prefab::toFile ( ) const -> std::string

Serializes to the human-readable text format.

Returns
A string containing the full .node file content
Here is the caller graph for this function:

◆ type()

auto assets::Prefab::type ( ) const -> std::string_view
inlinenodiscardoverridevirtual

Implements assets::Asset.

◆ validate()

auto assets::Prefab::validate ( ) const -> bool

Checks structural invariants.

Returns
false and logs errors if nodes is empty, any UID is duplicated, or any field has an unknown type
Here is the caller graph for this function:

◆ valueFromString()

auto assets::Prefab::valueFromString ( toast::FieldType type,
bool is_array,
std::string_view value ) -> std::optional< std::any >
static

Parses a text value back into a typed std::any for a reflected field.

Parameters
typeSerialization kind to parse as
is_arrayTrue if value encodes a std::vector of the field type
valueThe text encoding produced by stringifyValue()
Returns
The typed value, or std::nullopt if value could not be parsed
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • engine/src/toast/assets/prefab.hpp
  • engine/src/toast/assets/prefab.cpp