class
#include <ldtk_field.h>
field
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 type | Butano type T |
---|---|
Integer | INT (Various integer types, see below) |
Float | bn::fixed |
Boolean | bool |
String | bn::string_view |
Multilines | bn::string_view |
Color | bn::color |
Enum (enum_name ) | ldtk::gen::enum_name |
Entity ref | ldtk:: |
Point | bn::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_
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
orstd::int8_t
. - If the limits are set to large range, it will use
std::int32_t
.- LDtk does not allow values out of [-2147483..2147483], so unsigned 4 bytes integer is never used.
- 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.
- [0..127] will be

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 type | T when CAN'T contain nulls | T when CAN contain nulls |
---|---|---|
Integer | bn::span<const INT> | bn::span<const bn::optional<INT>> |
Float | bn::span<const bn::fixed> | bn::span<const bn::optional<bn::fixed>> |
Boolean | bn::span<const bool> | bn::span<const bn::optional<bool>> |
String | bn::span<const bn::string_view> | bn::span<const bn::optional<bn::string_view>> |
Multilines | bn::span<const bn::string_view> | bn::span<const bn::optional<bn::string_view>> |
Color | bn::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 ref | bn::span<const ldtk:: | bn::span<const bn::optional<ldtk:: |
Point | bn::span<const bn::point> | bn::span<const bn::optional<bn::point>> |
For arrays, checking has_
is not necessary, as it always returns true
.