Beispiel #1
0
si32 selectNextID(const JsonNode & fixedID, const Map & map, si32 defaultID)
{
	if (!fixedID.isNull() && fixedID.Float() < defaultID)
		return fixedID.Float(); // H3M object with fixed ID

	if (map.empty())
		return defaultID; // no objects loaded, keep gap for H3M objects
	if (map.rbegin()->first >= defaultID)
		return map.rbegin()->first + 1; // some modded objects loaded, return next available

	return defaultID; // some H3M objects loaded, first modded found
}
Beispiel #2
0
QVariant toVariant(const JsonNode & node)
{
	switch(node.getType())
	{
		break;
	case JsonNode::JsonType::DATA_NULL:
		return QVariant();
		break;
	case JsonNode::JsonType::DATA_BOOL:
		return QVariant(node.Bool());
		break;
	case JsonNode::JsonType::DATA_FLOAT:
		return QVariant(node.Float());
		break;
	case JsonNode::JsonType::DATA_STRING:
		return QVariant(QString::fromUtf8(node.String().c_str()));
		break;
	case JsonNode::JsonType::DATA_VECTOR:
		return JsonToList(node.Vector());
		break;
	case JsonNode::JsonType::DATA_STRUCT:
		return JsonToMap(node.Struct());
	}
	return QVariant();
}
Beispiel #3
0
static ui32 loadJsonOrMax(const JsonNode & input)
{
	if (input.isNull())
		return std::numeric_limits<ui32>::max();
	else
		return input.Float();
}
Beispiel #4
0
void JsonWriter::writeNode(const JsonNode &node)
{
	switch(node.getType())
	{
		break; case JsonNode::DATA_NULL:
			out << "null";

		break; case JsonNode::DATA_BOOL:
			if (node.Bool())
				out << "true";
			else
				out << "false";

		break; case JsonNode::DATA_FLOAT:
			out << node.Float();

		break; case JsonNode::DATA_STRING:
			writeString(node.String());

		break; case JsonNode::DATA_VECTOR:
			out << "[" << "\n";
			writeContainer(node.Vector().begin(), node.Vector().end());
			out << prefix << "]";

		break; case JsonNode::DATA_STRUCT:
			out << "{" << "\n";
			writeContainer(node.Struct().begin(), node.Struct().end());
			out << prefix << "}";
	}
}
Beispiel #5
0
JsonNode toJson(QVariant object)
{
	JsonNode ret;

	if (object.canConvert<QVariantMap>())
		ret.Struct() = VariantToMap(object.toMap());
	else if (object.canConvert<QVariantList>())
		ret.Vector() = VariantToList(object.toList());
	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::QString)
		ret.String() = object.toString().toUtf8().data();
	else if (static_cast<QMetaType::Type>(object.type()) == QMetaType::Bool)
		ret.Bool() = object.toBool();
	else if (object.canConvert<double>())
		ret.Float() = object.toFloat();

	return ret;
}
Beispiel #6
0
bool JsonParser::extractFloat(JsonNode &node)
{
	assert(input[pos] == '-' || (input[pos] >= '0' && input[pos] <= '9'));
	bool negative=false;
	double result=0;

	if (input[pos] == '-')
	{
		pos++;
		negative = true;
	}

	if (input[pos] < '0' || input[pos] > '9')
		return error("Number expected!");

	//Extract integer part
	while (input[pos] >= '0' && input[pos] <= '9')
	{
		result = result*10+(input[pos]-'0');
		pos++;
	}

	if (input[pos] == '.')
	{
		//extract fractional part
		pos++;
		double fractMult = 0.1;
		if (input[pos] < '0' || input[pos] > '9')
			return error("Decimal part expected!");

		while (input[pos] >= '0' && input[pos] <= '9')
		{
			result = result + fractMult*(input[pos]-'0');
			fractMult /= 10;
			pos++;
		}
	}
	//TODO: exponential part
	if (negative)
		result = -result;

	node.setType(JsonNode::DATA_FLOAT);
	node.Float() = result;
	return true;
}
Beispiel #7
0
void CSoundHandler::onVolumeChange(const JsonNode &volumeNode)
{
	setVolume(volumeNode.Float());
}