QtCraft API C++ classes QML types Handbook

QcContentFields Namespace

Field conventions shared by the content-pack parsers. More...

Header: #include <common/content/registry/QcContentFields.h>

Variables

const int maxExperience
const double maxFuelSeconds
const qsizetype maxNames
const int villageFormatVersion

Functions

std::optional<QcBoneRole> boneRoleFromName(const QString &name)
void checkFormatVersion(int supported, QcJsonFieldReader &reader)
QString invalidCategoryMessage()
bool isValidCategory(const QString &category)
QString localPart(const QString &qualifiedName)
QcExperienceDrop parseExperience(const QString &key, QcJsonFieldReader &reader, QcExperienceDrop fallback = {})
QStringList parseNames(const QString &key, const QString &packNamespace, QcJsonFieldReader &reader)
QStringList parseTags(const QJsonValue &value, const QString &packNamespace, QcJsonFieldReader &reader)
QString qualifyIngredient(const QString &text, const QString &packNamespace)
std::optional<QString> stateValue(const QJsonValue &value)
QString translationKey(const QString &prefix, const QString &qualifiedName)
std::optional<QcVec3> vectorField(const QJsonValue &value, double limit = 8.0)

Detailed Description

Variable Documentation

const int QcContentFields::maxExperience

The most experience points a content field may give.

const double QcContentFields::maxFuelSeconds

The longest burn time in seconds a block or item may give as fuel ("fuelSeconds").

const qsizetype QcContentFields::maxNames

The most names parseNames() accepts.

const int QcContentFields::villageFormatVersion

The format of the village files (styles, worldgen/villages.json, villager settings, professions and trades, decision E-421): their "formatVersion", 1 when missing.

Function Documentation

std::optional<QcBoneRole> QcContentFields::boneRoleFromName(const QString &name)

Returns the bone role named name ("none", "head", "body", "right_arm", "left_arm", "right_leg", "left_leg" for skeleton models); none for an unknown name.

void QcContentFields::checkFormatVersion(int supported, QcJsonFieldReader &reader)

Fails reader when its "formatVersion" is no whole number from 1 or newer than supported, so a file written for a later game is left out with a clear warning rather than read wrongly. A missing "formatVersion" passes.

QString QcContentFields::invalidCategoryMessage()

Returns the warning text for a category that isValidCategory() refuses.

bool QcContentFields::isValidCategory(const QString &category)

Returns whether category is a valid recipe category: at most 64 characters of a name part without '/' and without namespace, so that every pack can add recipes to "smelting".

QString QcContentFields::localPart(const QString &qualifiedName)

Returns qualifiedName without its namespace (the part after the first ':'; the whole text when there is none).

QcExperienceDrop QcContentFields::parseExperience(const QString &key, QcJsonFieldReader &reader, QcExperienceDrop fallback = {})

Returns the experience points at key of the object of reader (decision E-398): a whole number, or [min, max] (min not above max) for an even choice between them, each in 0..maxExperience; missing: fallback. Anything else fails reader and gives fallback.

QStringList QcContentFields::parseNames(const QString &key, const QString &packNamespace, QcJsonFieldReader &reader)

Returns the array of content names at key of the object of reader, qualified with packNamespace (at most maxNames; missing: empty). Anything else fails reader and gives an empty list.

QStringList QcContentFields::parseTags(const QJsonValue &value, const QString &packNamespace, QcJsonFieldReader &reader)

Returns the tags in value (an array of at most 16 names, qualified with packNamespace; missing: empty). Anything else fails reader and gives an empty list.

QString QcContentFields::qualifyIngredient(const QString &text, const QString &packNamespace)

Returns the recipe ingredient text qualified with packNamespace: an item name or, with a leading '#', an item tag; empty when the name is invalid.

std::optional<QString> QcContentFields::stateValue(const QJsonValue &value)

Returns the state value in value: strings as they are, booleans as "true"/"false"; none for any other JSON type.

QString QcContentFields::translationKey(const QString &prefix, const QString &qualifiedName)

Returns "<prefix>.<namespace>.<path with '/' as '.'>" for prefix and qualifiedName, the default translation key of a content name.

std::optional<QcVec3> QcContentFields::vectorField(const QJsonValue &value, double limit = 8.0)

Returns the three numbers in value, each within limit metres of 0 (model coordinates); none for anything else.