QtCraft API C++ classes QML types Handbook

QcWorldOptions::Option Struct

struct QcWorldOptions::Option

A usable option of the content: its definition, its target and its default. More...

Header: #include <worldgen/generators/QcWorldOptions.h>

Public Functions

bool isSwitch() const
QJsonValue json(double value) const
std::optional<double> read(const QJsonValue &json, bool strict) const
double snapped(double value) const

Public Variables

double defaultValue
const QcWorldOptionDefinition *definition
const QcWorldOptionTargets::Target *target

Detailed Description

Member Function Documentation

bool Option::isSwitch() const

Returns whether the option is on or off rather than a number.

QJsonValue Option::json(double value) const

Returns value as world.json writes it: true/false for a switch, else the number.

std::optional<double> Option::read(const QJsonValue &json, bool strict) const

Returns the value of json for this option; empty when it is of the wrong type or outside the option's range (strict) or the target's.

double Option::snapped(double value) const

Returns value on the option's grid (min + n ยท step, written with the step's decimals, so that 0.6 is the same double as the 0.6 of a JSON file), and exactly the default when it lies within rounding of it; a switch's value as it is. A slider's 0.6000000000000001 thus becomes 0.6. A value outside the range stays outside (read() refuses it).

Member Variable Documentation

double Option::defaultValue

The definition's default, or else the value the target reads from the content.

const QcWorldOptionDefinition *Option::definition

The option's definition in the content.

const QcWorldOptionTargets::Target *Option::target

The generator value the option sets.