ldtk::field class

Public functions

auto def() const -> const field_definition& constexpr
Reference to the Field definition.
template<typename Ident>
auto identifier() const -> Ident constexpr
Field definition identifier.
auto type() const -> field_type constexpr
Type of the field.
auto enum_type() const -> const bn::optional<bn::type_id_t>& constexpr
Enum type of the field.
auto has_value() const -> bool constexpr
If this field has a value or not.
template<typename T>
auto get() const -> T constexpr
Extract the concrete object from the field.

Function documentation

template<typename Ident>
Ident ldtk::field::identifier() const constexpr

Field definition identifier.

Template parameters
Ident Either gen::level_field_ident or gen::entity_field_ident, depending on where this field belongs

bool ldtk::field::has_value() const constexpr

If this field has a value or not.

template<typename T>
T ldtk::field::get() const constexpr

Extract the concrete object from the field.

Template parameters
T Type of the field to be extracted.

Type parameter T depends on your LDtk level/entity field type.

If it is a non-array type, you use one of these type:

LDtk non-array typeButano type T
IntegerINT (Various integer types, see below)
Floatbn::fixed
Booleanbool
Stringbn::string_view
Multilinesbn::string_view
Colorbn::color
Enum (enum_name)ldtk::gen::enum_name
Entity refldtk::entity_ref
Pointbn::point

If the field is set to Can be null/Is optional in the LDtk field value specifications, (See the image below)
you must check has_value() before calling get().

INT is determined by the limits you set in the LDtk field value specifications. (See the image below)
By default, it uses std::int16_t.

  • If the limits are set to small range, it can use either std::uint8_t or std::int8_t.
  • If the limits are set to large range, it will use std::int32_t.
  • Unsigned always takes precedence over the same size of signed integer type, whenever possible.
    • [0..127] will be std::uint8_t, not signed.
    • std::int32_t is the exception, unsigned 4 bytes integer is never used as mentioned above.
Image

If it is an array type, you also need to consider if it is set to Can contain nulls in the LDtk field value specifications:

LDtk array typeT when CAN'T contain nullsT when CAN contain nulls
Integerbn::span<const INT>bn::span<const bn::optional<INT>>
Floatbn::span<const bn::fixed>bn::span<const bn::optional<bn::fixed>>
Booleanbn::span<const bool>bn::span<const bn::optional<bool>>
Stringbn::span<const bn::string_view>bn::span<const bn::optional<bn::string_view>>
Multilinesbn::span<const bn::string_view>bn::span<const bn::optional<bn::string_view>>
Colorbn::span<const bn::color>bn::span<const bn::optional<bn::color>>
Enum (enum_name)bn::span<const ldtk::gen::enum_name>bn::span<const bn::optional<ldtk::gen::enum_name>>
Entity refbn::span<const ldtk::entity_ref>bn::span<const bn::optional<ldtk::entity_ref>>
Pointbn::span<const bn::point>bn::span<const bn::optional<bn::point>>

For arrays, checking has_value() is not necessary, as it always returns true.