Json11 => NlohmannJson (#393)
* Json11 => NlohmannJson * Fix release build * Updated gitmodulie * Address review * Update .gitmodules Co-authored-by: rackover <roxanne@thegamebakers.com> Co-authored-by: Edo <edoardo.sanguineti222@gmail.com>
This commit is contained in:
parent
78b4ae788b
commit
f3c15f2cda
7
.gitmodules
vendored
7
.gitmodules
vendored
@ -2,10 +2,6 @@
|
|||||||
path = deps/zlib
|
path = deps/zlib
|
||||||
url = https://github.com/madler/zlib.git
|
url = https://github.com/madler/zlib.git
|
||||||
branch = develop
|
branch = develop
|
||||||
[submodule "deps/json11"]
|
|
||||||
path = deps/json11
|
|
||||||
url = https://github.com/dropbox/json11.git
|
|
||||||
branch = master
|
|
||||||
[submodule "deps/libtommath"]
|
[submodule "deps/libtommath"]
|
||||||
path = deps/libtommath
|
path = deps/libtommath
|
||||||
url = https://github.com/libtom/libtommath.git
|
url = https://github.com/libtom/libtommath.git
|
||||||
@ -35,3 +31,6 @@
|
|||||||
[submodule "deps/GSL"]
|
[submodule "deps/GSL"]
|
||||||
path = deps/GSL
|
path = deps/GSL
|
||||||
url = https://github.com/microsoft/GSL.git
|
url = https://github.com/microsoft/GSL.git
|
||||||
|
[submodule "deps/nlohmannjson"]
|
||||||
|
path = deps/nlohmannjson
|
||||||
|
url = https://github.com/nlohmann/json.git
|
||||||
|
1
deps/json11
vendored
1
deps/json11
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit 2df9473fb3605980db55ecddf34392a2e832ad35
|
|
1
deps/nlohmannjson
vendored
Submodule
1
deps/nlohmannjson
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 2d48a4d9c5e8f0a5ce914922eb2a45dc0ec93ee3
|
33
deps/premake/json11.lua
vendored
33
deps/premake/json11.lua
vendored
@ -1,33 +0,0 @@
|
|||||||
json11 = {
|
|
||||||
source = path.join(dependencies.basePath, "json11"),
|
|
||||||
}
|
|
||||||
|
|
||||||
function json11.import()
|
|
||||||
links {"json11"}
|
|
||||||
|
|
||||||
json11.includes()
|
|
||||||
end
|
|
||||||
|
|
||||||
function json11.includes()
|
|
||||||
includedirs {json11.source}
|
|
||||||
end
|
|
||||||
|
|
||||||
function json11.project()
|
|
||||||
project "json11"
|
|
||||||
language "C++"
|
|
||||||
cppdialect "C++11"
|
|
||||||
|
|
||||||
files
|
|
||||||
{
|
|
||||||
path.join(json11.source, "*.cpp"),
|
|
||||||
path.join(json11.source, "*.hpp"),
|
|
||||||
}
|
|
||||||
|
|
||||||
warnings "Off"
|
|
||||||
|
|
||||||
defines {"_LIB"}
|
|
||||||
removedefines {"_USRDLL", "_DLL"}
|
|
||||||
kind "StaticLib"
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(dependencies, json11)
|
|
18
deps/premake/nlohmannjson.lua
vendored
Normal file
18
deps/premake/nlohmannjson.lua
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
nlohmannjson = {
|
||||||
|
source = path.join(dependencies.basePath, "nlohmannjson"),
|
||||||
|
}
|
||||||
|
|
||||||
|
function nlohmannjson.import()
|
||||||
|
nlohmannjson.includes()
|
||||||
|
end
|
||||||
|
|
||||||
|
function nlohmannjson.includes()
|
||||||
|
includedirs {
|
||||||
|
path.join(nlohmannjson.source, "single_include/nlohmann")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function nlohmannjson.project()
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(dependencies, nlohmannjson)
|
@ -601,7 +601,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json vertexData = json11::Json::object
|
nlohmann::json vertexData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "name", vertexdecl->name },
|
{ "name", vertexdecl->name },
|
||||||
{ "streamCount", vertexdecl->streamCount },
|
{ "streamCount", vertexdecl->streamCount },
|
||||||
@ -651,7 +651,7 @@ namespace Components
|
|||||||
literalConsts.push_back(curArg->u.literalConst[3]);
|
literalConsts.push_back(curArg->u.literalConst[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json argData = json11::Json::object
|
nlohmann::json argData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "type", curArg->type },
|
{ "type", curArg->type },
|
||||||
{ "value", literalConsts },
|
{ "value", literalConsts },
|
||||||
@ -660,7 +660,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else if (curArg->type == 3 || curArg->type == 5)
|
else if (curArg->type == 3 || curArg->type == 5)
|
||||||
{
|
{
|
||||||
json11::Json argData = json11::Json::object
|
nlohmann::json argData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "type", curArg->type },
|
{ "type", curArg->type },
|
||||||
{ "firstRow", curArg->u.codeConst.firstRow },
|
{ "firstRow", curArg->u.codeConst.firstRow },
|
||||||
@ -671,7 +671,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
json11::Json argData = json11::Json::object
|
nlohmann::json argData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "type", curArg->type },
|
{ "type", curArg->type },
|
||||||
{ "value", static_cast<int>(curArg->u.codeSampler) },
|
{ "value", static_cast<int>(curArg->u.codeSampler) },
|
||||||
@ -680,7 +680,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json passData = json11::Json::object
|
nlohmann::json passData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "perObjArgCount", curPass->perObjArgCount },
|
{ "perObjArgCount", curPass->perObjArgCount },
|
||||||
{ "perPrimArgCount", curPass->perPrimArgCount },
|
{ "perPrimArgCount", curPass->perPrimArgCount },
|
||||||
@ -693,7 +693,7 @@ namespace Components
|
|||||||
passDataArray.push_back(passData);
|
passDataArray.push_back(passData);
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json techData = json11::Json::object
|
nlohmann::json techData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "name", curTech->name },
|
{ "name", curTech->name },
|
||||||
{ "index", technique },
|
{ "index", technique },
|
||||||
@ -708,7 +708,7 @@ namespace Components
|
|||||||
fwrite(&stringData[0], stringData.size(), 1, fp);
|
fwrite(&stringData[0], stringData.size(), 1, fp);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
json11::Json techsetTechnique = json11::Json::object
|
nlohmann::json techsetTechnique = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "name", curTech->name },
|
{ "name", curTech->name },
|
||||||
{ "index", technique },
|
{ "index", technique },
|
||||||
@ -721,7 +721,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json techsetData = json11::Json::object
|
nlohmann::json techsetData = json11::Json::object
|
||||||
{
|
{
|
||||||
{ "name", techset->name },
|
{ "name", techset->name },
|
||||||
{ "techniques", techniques },
|
{ "techniques", techniques },
|
||||||
|
@ -100,26 +100,19 @@ namespace Assets
|
|||||||
|
|
||||||
if (fontDefFile.exists() && fontFile.exists())
|
if (fontDefFile.exists() && fontFile.exists())
|
||||||
{
|
{
|
||||||
std::string errors;
|
auto fontDef = nlohmann::json::parse(fontDefFile.getBuffer());
|
||||||
auto fontDef = json11::Json::parse(fontDefFile.getBuffer(), errors);
|
|
||||||
|
|
||||||
if (!errors.empty())
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Font define {} is broken: {}", name, errors);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fontDef.is_object())
|
if (!fontDef.is_object())
|
||||||
{
|
{
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Font define {} is invalid {}", name, errors);
|
Components::Logger::Error(Game::ERR_FATAL, "Font define {} is invalid", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int w = fontDef["textureWidth"].int_value();
|
int w = fontDef["textureWidth"].get<int>();
|
||||||
int h = fontDef["textureHeight"].int_value();
|
int h = fontDef["textureHeight"].get<int>();
|
||||||
|
|
||||||
int size = fontDef["size"].int_value();
|
int size = fontDef["size"].get<int>();
|
||||||
int yOffset = fontDef["yOffset"].int_value();
|
int yOffset = fontDef["yOffset"].get<int>();
|
||||||
|
|
||||||
auto* pixels = builder->getAllocator()->allocateArray<uint8_t>(w * h);
|
auto* pixels = builder->getAllocator()->allocateArray<uint8_t>(w * h);
|
||||||
|
|
||||||
@ -153,8 +146,9 @@ namespace Assets
|
|||||||
|
|
||||||
if (fontDef["charset"].is_array())
|
if (fontDef["charset"].is_array())
|
||||||
{
|
{
|
||||||
for (auto& ch : fontDef["charset"].array_items())
|
nlohmann::json::array_t charsetArray = fontDef["charset"];
|
||||||
charset.push_back(static_cast<uint16_t>(ch.int_value()));
|
for (auto& ch : charsetArray)
|
||||||
|
charset.push_back(static_cast<uint16_t>(ch.get<int>()));
|
||||||
|
|
||||||
// order matters
|
// order matters
|
||||||
std::sort(charset.begin(), charset.end());
|
std::sort(charset.begin(), charset.end());
|
||||||
|
@ -332,165 +332,13 @@ namespace Assets
|
|||||||
header->material = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).material;
|
header->material = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).material;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMaterial::loadJson(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder)
|
void IMaterial::loadJson(Game::XAssetHeader* header, const std::string& name, [[maybe_unused]] Components::ZoneBuilder::Zone* builder)
|
||||||
{
|
{
|
||||||
Components::FileSystem::File materialInfo(Utils::String::VA("materials/%s.json", name.data()));
|
Components::FileSystem::File materialInfo(Utils::String::VA("materials/%s.json", name.data()));
|
||||||
|
|
||||||
if (!materialInfo.exists()) return;
|
if (!materialInfo.exists()) return;
|
||||||
|
|
||||||
std::string errors;
|
header->material = nullptr;
|
||||||
json11::Json infoData = json11::Json::parse(materialInfo.getBuffer(), errors);
|
|
||||||
|
|
||||||
if (!infoData.is_object())
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Failed to load material information for {}!", name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto base = infoData["base"];
|
|
||||||
|
|
||||||
if (!base.is_string())
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "No valid material base provided for {}!", name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game::Material* baseMaterial = Game::DB_FindXAssetHeader(Game::XAssetType::ASSET_TYPE_MATERIAL, base.string_value().data()).material;
|
|
||||||
|
|
||||||
if (!baseMaterial) // TODO: Maybe check if default asset? Maybe not? You could still want to use the default one as base!?
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Basematerial '{}' not found for {}!", base.string_value(), name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game::Material* material = builder->getAllocator()->allocate<Game::Material>();
|
|
||||||
|
|
||||||
if (!material)
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate material structure!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy base material to our structure
|
|
||||||
std::memcpy(material, baseMaterial, sizeof(Game::Material));
|
|
||||||
material->info.name = builder->getAllocator()->duplicateString(name);
|
|
||||||
|
|
||||||
material->info.textureAtlasRowCount = 1;
|
|
||||||
material->info.textureAtlasColumnCount = 1;
|
|
||||||
|
|
||||||
// Load animation frames
|
|
||||||
auto anims = infoData["anims"];
|
|
||||||
if (anims.is_array())
|
|
||||||
{
|
|
||||||
auto animCoords = anims.array_items();
|
|
||||||
|
|
||||||
if (animCoords.size() >= 2)
|
|
||||||
{
|
|
||||||
auto animCoordX = animCoords[0];
|
|
||||||
auto animCoordY = animCoords[1];
|
|
||||||
|
|
||||||
if (animCoordX.is_number())
|
|
||||||
{
|
|
||||||
material->info.textureAtlasColumnCount = static_cast<char>(animCoordX.number_value()) & 0xFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (animCoordY.is_number())
|
|
||||||
{
|
|
||||||
material->info.textureAtlasRowCount = static_cast<char>(animCoordY.number_value()) & 0xFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Model surface textures are special, they need a special order and whatnot
|
|
||||||
bool replaceTexture = Utils::String::StartsWith(name, "mc/");
|
|
||||||
if (replaceTexture)
|
|
||||||
{
|
|
||||||
Game::MaterialTextureDef* textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(baseMaterial->textureCount);
|
|
||||||
std::memcpy(textureTable, baseMaterial->textureTable, sizeof(Game::MaterialTextureDef) * baseMaterial->textureCount);
|
|
||||||
material->textureTable = textureTable;
|
|
||||||
material->textureCount = baseMaterial->textureCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load referenced textures
|
|
||||||
auto textures = infoData["textures"];
|
|
||||||
if (textures.is_array())
|
|
||||||
{
|
|
||||||
std::vector<Game::MaterialTextureDef> textureList;
|
|
||||||
|
|
||||||
for (auto& texture : textures.array_items())
|
|
||||||
{
|
|
||||||
if (!texture.is_array()) continue;
|
|
||||||
if (textureList.size() >= 0xFF) break;
|
|
||||||
|
|
||||||
auto textureInfo = texture.array_items();
|
|
||||||
if (textureInfo.size() < 2) continue;
|
|
||||||
|
|
||||||
auto map = textureInfo[0];
|
|
||||||
auto image = textureInfo[1];
|
|
||||||
if (!map.is_string() || !image.is_string()) continue;
|
|
||||||
|
|
||||||
Game::MaterialTextureDef textureDef;
|
|
||||||
|
|
||||||
textureDef.semantic = 0; // No water image
|
|
||||||
textureDef.samplerState = -30;
|
|
||||||
textureDef.nameEnd = map.string_value().back();
|
|
||||||
textureDef.nameStart = map.string_value().front();
|
|
||||||
textureDef.nameHash = Game::R_HashString(map.string_value().data());
|
|
||||||
|
|
||||||
textureDef.u.image = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_IMAGE, image.string_value(), builder).image;
|
|
||||||
|
|
||||||
if (replaceTexture)
|
|
||||||
{
|
|
||||||
bool applied = false;
|
|
||||||
|
|
||||||
for (char i = 0; i < baseMaterial->textureCount; ++i)
|
|
||||||
{
|
|
||||||
if (material->textureTable[i].nameHash == textureDef.nameHash)
|
|
||||||
{
|
|
||||||
applied = true;
|
|
||||||
material->textureTable[i].u.image = textureDef.u.image;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!applied)
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Unable to find texture for map '{}' in {}!",
|
|
||||||
map.string_value(), baseMaterial->info.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
textureList.push_back(textureDef);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!replaceTexture)
|
|
||||||
{
|
|
||||||
if (!textureList.empty())
|
|
||||||
{
|
|
||||||
Game::MaterialTextureDef* textureTable = builder->getAllocator()->allocateArray<Game::MaterialTextureDef>(textureList.size());
|
|
||||||
|
|
||||||
if (!textureTable)
|
|
||||||
{
|
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Failed to allocate texture table!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::memcpy(textureTable, textureList.data(), sizeof(Game::MaterialTextureDef) * textureList.size());
|
|
||||||
|
|
||||||
material->textureTable = textureTable;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
material->textureTable = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
material->textureCount = static_cast<char>(textureList.size()) & 0xFF;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
header->material = material;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IMaterial::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
void IMaterial::mark(Game::XAssetHeader header, Components::ZoneBuilder::Zone* builder)
|
||||||
|
@ -20,10 +20,10 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string errors;
|
std::string errors;
|
||||||
json11::Json infoData = json11::Json::parse(aliasFile.getBuffer(), errors);
|
nlohmann::json infoData = nlohmann::json::parse(aliasFile.getBuffer());
|
||||||
json11::Json aliasesContainer = infoData["head"];
|
nlohmann::json aliasesContainer = infoData["head"];
|
||||||
|
|
||||||
auto aliases = aliasesContainer.array_items();
|
nlohmann::json::array_t aliases = aliasesContainer;
|
||||||
|
|
||||||
aliasList->count = aliases.size();
|
aliasList->count = aliases.size();
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace Assets
|
|||||||
|
|
||||||
for (size_t i = 0; i < aliasList->count; i++)
|
for (size_t i = 0; i < aliasList->count; i++)
|
||||||
{
|
{
|
||||||
json11::Json head = aliasesContainer[i];
|
nlohmann::json head = aliasesContainer[i];
|
||||||
|
|
||||||
if (!infoData.is_object())
|
if (!infoData.is_object())
|
||||||
{
|
{
|
||||||
@ -211,37 +211,37 @@ namespace Assets
|
|||||||
{
|
{
|
||||||
|
|
||||||
alias->soundFile->exists = true;
|
alias->soundFile->exists = true;
|
||||||
alias->aliasName = builder->getAllocator()->duplicateString(aliasName.string_value().c_str());
|
alias->aliasName = builder->getAllocator()->duplicateString(aliasName.get<std::string>());
|
||||||
|
|
||||||
if (subtitle.is_string())
|
if (subtitle.is_string())
|
||||||
{
|
{
|
||||||
alias->subtitle = builder->getAllocator()->duplicateString(subtitle.string_value().c_str());
|
alias->subtitle = builder->getAllocator()->duplicateString(subtitle.get<std::string>());
|
||||||
}
|
}
|
||||||
if (secondaryAliasName.is_string())
|
if (secondaryAliasName.is_string())
|
||||||
{
|
{
|
||||||
alias->secondaryAliasName = builder->getAllocator()->duplicateString(secondaryAliasName.string_value().c_str());
|
alias->secondaryAliasName = builder->getAllocator()->duplicateString(secondaryAliasName.get<std::string>());
|
||||||
}
|
}
|
||||||
if (chainAliasName.is_string())
|
if (chainAliasName.is_string())
|
||||||
{
|
{
|
||||||
alias->chainAliasName = builder->getAllocator()->duplicateString(chainAliasName.string_value().c_str());
|
alias->chainAliasName = builder->getAllocator()->duplicateString(chainAliasName.get<std::string>());
|
||||||
}
|
}
|
||||||
|
|
||||||
alias->sequence = sequence.int_value();
|
alias->sequence = sequence.get<int>();
|
||||||
alias->volMin = float(volMin.number_value());
|
alias->volMin = volMin.get<float>();
|
||||||
alias->volMax = float(volMax.number_value());
|
alias->volMax = volMax.get<float>();
|
||||||
alias->pitchMin = float(pitchMin.number_value());
|
alias->pitchMin = pitchMin.get<float>();
|
||||||
alias->pitchMax = float(pitchMax.number_value());
|
alias->pitchMax = pitchMax.get<float>();
|
||||||
alias->distMin = float(distMin.number_value());
|
alias->distMin = distMin.get<float>();
|
||||||
alias->distMax = float(distMax.number_value());
|
alias->distMax = distMax.get<float>();
|
||||||
alias->flags = flags.int_value();
|
alias->flags = flags.get<int>();
|
||||||
alias->___u15.slavePercentage = float(slavePercentage.number_value());
|
alias->___u15.slavePercentage = slavePercentage.get<float>();
|
||||||
alias->probability = float(probability.number_value());
|
alias->probability = probability.get<float>();
|
||||||
alias->lfePercentage = float(lfePercentage.number_value());
|
alias->lfePercentage = lfePercentage.get<float>();
|
||||||
alias->centerPercentage = float(centerPercentage.number_value());
|
alias->centerPercentage = centerPercentage.get<float>();
|
||||||
alias->startDelay = startDelay.int_value();
|
alias->startDelay = startDelay.get<int>();
|
||||||
alias->envelopMin = float(envelopMin.number_value());
|
alias->envelopMin = envelopMin.get<float>();
|
||||||
alias->envelopMax = float(envelopMax.number_value());
|
alias->envelopMax = envelopMax.get<float>();
|
||||||
alias->envelopPercentage = float(envelopPercentage.number_value());
|
alias->envelopPercentage = envelopPercentage.get<float>();
|
||||||
|
|
||||||
// Speaker map object
|
// Speaker map object
|
||||||
if (!speakerMap.is_null())
|
if (!speakerMap.is_null())
|
||||||
@ -253,12 +253,12 @@ namespace Assets
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
alias->speakerMap->name = builder->getAllocator()->duplicateString(speakerMap["name"].string_value().c_str());
|
alias->speakerMap->name = builder->getAllocator()->duplicateString(speakerMap["name"].get<std::string>());
|
||||||
alias->speakerMap->isDefault = speakerMap["isDefault"].bool_value();
|
alias->speakerMap->isDefault = speakerMap["isDefault"].get<bool>();
|
||||||
|
|
||||||
if (speakerMap["channelMaps"].is_array())
|
if (speakerMap["channelMaps"].is_array())
|
||||||
{
|
{
|
||||||
json11::Json::array channelMaps = speakerMap["channelMaps"].array_items();
|
nlohmann::json::array_t channelMaps = speakerMap["channelMaps"];
|
||||||
|
|
||||||
assert(channelMaps.size() <= 4);
|
assert(channelMaps.size() <= 4);
|
||||||
|
|
||||||
@ -268,19 +268,19 @@ namespace Assets
|
|||||||
// subChannelIndex should never exceed 1
|
// subChannelIndex should never exceed 1
|
||||||
for (size_t subChannelIndex = 0; subChannelIndex < 2; subChannelIndex++)
|
for (size_t subChannelIndex = 0; subChannelIndex < 2; subChannelIndex++)
|
||||||
{
|
{
|
||||||
json11::Json channelMap = channelMaps[channelMapIndex * 2 + subChannelIndex]; // 0-3
|
nlohmann::json channelMap = channelMaps[channelMapIndex * 2 + subChannelIndex]; // 0-3
|
||||||
|
|
||||||
auto speakers = channelMap["speakers"].array_items();
|
nlohmann::json::array_t speakers = channelMap["speakers"];
|
||||||
|
|
||||||
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakerCount = speakers.size();
|
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakerCount = speakers.size();
|
||||||
|
|
||||||
for (size_t speakerIndex = 0; speakerIndex < alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakerCount; speakerIndex++)
|
for (size_t speakerIndex = 0; speakerIndex < alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakerCount; speakerIndex++)
|
||||||
{
|
{
|
||||||
auto speaker = speakers[speakerIndex];
|
auto speaker = speakers[speakerIndex];
|
||||||
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].levels[0] = static_cast<float>(speaker["levels0"].number_value());
|
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].levels[0] = speaker["levels0"].get<float>();
|
||||||
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].levels[1] = static_cast<float>(speaker["levels1"].number_value());
|
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].levels[1] = speaker["levels1"].get<float>();
|
||||||
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].numLevels = static_cast<int>(speaker["numLevels"].number_value());
|
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].numLevels = speaker["numLevels"].get<int>();
|
||||||
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].speaker = static_cast<int>(speaker["speaker"].number_value());
|
alias->speakerMap->channelMaps[channelMapIndex][subChannelIndex].speakers[speakerIndex].speaker = speaker["speaker"].get<int>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -289,7 +289,7 @@ namespace Assets
|
|||||||
|
|
||||||
if (volumeFalloffCurve.is_string())
|
if (volumeFalloffCurve.is_string())
|
||||||
{
|
{
|
||||||
std::string fallOffCurve = volumeFalloffCurve.string_value();
|
std::string fallOffCurve = volumeFalloffCurve.get<std::string>();
|
||||||
|
|
||||||
if (fallOffCurve.size() == 0)
|
if (fallOffCurve.size() == 0)
|
||||||
{
|
{
|
||||||
@ -305,16 +305,16 @@ namespace Assets
|
|||||||
alias->volumeFalloffCurve = curve;
|
alias->volumeFalloffCurve = curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (static_cast<Game::snd_alias_type_t>(type.number_value()) == Game::snd_alias_type_t::SAT_LOADED) // Loaded
|
if (static_cast<Game::snd_alias_type_t>(type.get<int>()) == Game::snd_alias_type_t::SAT_LOADED) // Loaded
|
||||||
{
|
{
|
||||||
alias->soundFile->type = Game::SAT_LOADED;
|
alias->soundFile->type = Game::SAT_LOADED;
|
||||||
alias->soundFile->u.loadSnd = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, soundFile.string_value().c_str(), builder).loadSnd;
|
alias->soundFile->u.loadSnd = Components::AssetHandler::FindAssetForZone(Game::XAssetType::ASSET_TYPE_LOADED_SOUND, soundFile.get<std::string>(), builder).loadSnd;
|
||||||
}
|
}
|
||||||
else if (static_cast<Game::snd_alias_type_t>(type.number_value()) == Game::snd_alias_type_t::SAT_STREAMED) // Streamed
|
else if (static_cast<Game::snd_alias_type_t>(type.get<int>()) == Game::snd_alias_type_t::SAT_STREAMED) // Streamed
|
||||||
{
|
{
|
||||||
alias->soundFile->type = Game::SAT_STREAMED;
|
alias->soundFile->type = Game::SAT_STREAMED;
|
||||||
|
|
||||||
std::string streamedFile = soundFile.string_value();
|
std::string streamedFile = soundFile.get<std::string>();
|
||||||
std::string directory = ""s;
|
std::string directory = ""s;
|
||||||
int split = streamedFile.find_last_of('/');
|
int split = streamedFile.find_last_of('/');
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ namespace Assets
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Components::Logger::Error(Game::ERR_FATAL, "Failed to parse sound {}! Invalid sound type {}\n", name, type.string_value());
|
Components::Logger::Error(Game::ERR_FATAL, "Failed to parse sound {}! Invalid sound type {}\n", name, type.get<std::string>());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ namespace Components
|
|||||||
ipEntry.bytes[3] & 0xFF));
|
ipEntry.bytes[3] & 0xFF));
|
||||||
}
|
}
|
||||||
|
|
||||||
const json11::Json bans = json11::Json::object
|
const nlohmann::json bans = nlohmann::json
|
||||||
{
|
{
|
||||||
{ "ip", ipVector },
|
{ "ip", ipVector },
|
||||||
{ "id", idVector },
|
{ "id", idVector },
|
||||||
@ -131,13 +131,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
const auto banData = json11::Json::parse(bans.getBuffer(), error);
|
const auto banData = nlohmann::json::parse(bans.getBuffer());
|
||||||
|
|
||||||
if (!error.empty())
|
|
||||||
{
|
|
||||||
Logger::PrintError(Game::CON_CHANNEL_ERROR, "Failed to parse bans.json: {}\n", error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!banData.is_object())
|
if (!banData.is_object())
|
||||||
{
|
{
|
||||||
@ -150,12 +144,14 @@ namespace Components
|
|||||||
|
|
||||||
if (idList.is_array())
|
if (idList.is_array())
|
||||||
{
|
{
|
||||||
for (auto &idEntry : idList.array_items())
|
nlohmann::json::array_t arr = idList;
|
||||||
|
|
||||||
|
for (auto &idEntry : arr)
|
||||||
{
|
{
|
||||||
if (idEntry.is_string())
|
if (idEntry.is_string())
|
||||||
{
|
{
|
||||||
SteamID id;
|
SteamID id;
|
||||||
id.bits = strtoull(idEntry.string_value().data(), nullptr, 16);
|
id.bits = strtoull(idEntry.get<std::string>().data(), nullptr, 16);
|
||||||
|
|
||||||
list->idList.push_back(id);
|
list->idList.push_back(id);
|
||||||
}
|
}
|
||||||
@ -164,11 +160,13 @@ namespace Components
|
|||||||
|
|
||||||
if (ipList.is_array())
|
if (ipList.is_array())
|
||||||
{
|
{
|
||||||
for (auto &ipEntry : ipList.array_items())
|
nlohmann::json::array_t arr = ipList;
|
||||||
|
|
||||||
|
for (auto &ipEntry : arr)
|
||||||
{
|
{
|
||||||
if (ipEntry.is_string())
|
if (ipEntry.is_string())
|
||||||
{
|
{
|
||||||
Network::Address addr(ipEntry.string_value());
|
Network::Address addr(ipEntry.get<std::string>());
|
||||||
|
|
||||||
list->ipList.push_back(addr.getIP());
|
list->ipList.push_back(addr.getIP());
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ namespace Components
|
|||||||
download->files.clear();
|
download->files.clear();
|
||||||
|
|
||||||
std::string error;
|
std::string error;
|
||||||
json11::Json listData = json11::Json::parse(list, error);
|
nlohmann::json listData = nlohmann::json::parse(list);
|
||||||
|
|
||||||
if (!error.empty() || !listData.is_array())
|
if (!error.empty() || !listData.is_array())
|
||||||
{
|
{
|
||||||
@ -72,8 +72,9 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
download->totalBytes = 0;
|
download->totalBytes = 0;
|
||||||
|
nlohmann::json::array_t listDataArray = listData;
|
||||||
|
|
||||||
for (auto& file : listData.array_items())
|
for (auto& file : listDataArray)
|
||||||
{
|
{
|
||||||
if (!file.is_object()) return false;
|
if (!file.is_object()) return false;
|
||||||
|
|
||||||
@ -84,9 +85,9 @@ namespace Components
|
|||||||
if (!hash.is_string() || !name.is_string() || !size.is_number()) return false;
|
if (!hash.is_string() || !name.is_string() || !size.is_number()) return false;
|
||||||
|
|
||||||
Download::ClientDownload::File fileEntry;
|
Download::ClientDownload::File fileEntry;
|
||||||
fileEntry.name = name.string_value();
|
fileEntry.name = name.get<std::string>();
|
||||||
fileEntry.hash = hash.string_value();
|
fileEntry.hash = hash.get<std::string>();
|
||||||
fileEntry.size = static_cast<size_t>(size.number_value());
|
fileEntry.size = size.get<size_t>();
|
||||||
|
|
||||||
if (!fileEntry.name.empty())
|
if (!fileEntry.name.empty())
|
||||||
{
|
{
|
||||||
@ -502,14 +503,14 @@ namespace Components
|
|||||||
// Only handle http requests
|
// Only handle http requests
|
||||||
if (ev != MG_EV_HTTP_REQUEST) return;
|
if (ev != MG_EV_HTTP_REQUEST) return;
|
||||||
|
|
||||||
std::vector<json11::Json> servers;
|
std::vector<nlohmann::json> servers;
|
||||||
|
|
||||||
// Build server list
|
// Build server list
|
||||||
for (auto& node : Node::GetNodes())
|
for (auto& node : Node::GetNodes())
|
||||||
{
|
{
|
||||||
if (node.isValid())
|
if (node.isValid())
|
||||||
{
|
{
|
||||||
servers.push_back(json11::Json{ node });
|
servers.push_back(nlohmann::json{ node.to_json()});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -519,7 +520,7 @@ namespace Components
|
|||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"Access-Control-Allow-Origin: *\r\n"
|
"Access-Control-Allow-Origin: *\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"%s", json11::Json(servers).dump().data());
|
"%s", nlohmann::json(servers).dump().data());
|
||||||
|
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
}
|
}
|
||||||
@ -532,17 +533,17 @@ namespace Components
|
|||||||
if (!Download::VerifyPassword(nc, reinterpret_cast<http_message*>(ev_data))) return;
|
if (!Download::VerifyPassword(nc, reinterpret_cast<http_message*>(ev_data))) return;
|
||||||
|
|
||||||
static std::string mapnamePre;
|
static std::string mapnamePre;
|
||||||
static json11::Json jsonList;
|
static nlohmann::json jsonList;
|
||||||
|
|
||||||
std::string mapname = (Party::IsInUserMapLobby() ? Dvar::Var("ui_mapname").get<std::string>() : Maps::GetUserMap()->getName());
|
std::string mapname = (Party::IsInUserMapLobby() ? Dvar::Var("ui_mapname").get<std::string>() : Maps::GetUserMap()->getName());
|
||||||
if (!Maps::GetUserMap()->isValid() && !Party::IsInUserMapLobby())
|
if (!Maps::GetUserMap()->isValid() && !Party::IsInUserMapLobby())
|
||||||
{
|
{
|
||||||
mapnamePre.clear();
|
mapnamePre.clear();
|
||||||
jsonList = std::vector<json11::Json>();
|
jsonList = std::vector<nlohmann::json>();
|
||||||
}
|
}
|
||||||
else if (!mapname.empty() && mapname != mapnamePre)
|
else if (!mapname.empty() && mapname != mapnamePre)
|
||||||
{
|
{
|
||||||
std::vector<json11::Json> fileList;
|
std::vector<nlohmann::json> fileList;
|
||||||
|
|
||||||
mapnamePre = mapname;
|
mapnamePre = mapname;
|
||||||
|
|
||||||
@ -553,7 +554,7 @@ namespace Components
|
|||||||
std::string filename = path + "\\" + mapname + Maps::UserMapFiles[i];
|
std::string filename = path + "\\" + mapname + Maps::UserMapFiles[i];
|
||||||
if (Utils::IO::FileExists(filename))
|
if (Utils::IO::FileExists(filename))
|
||||||
{
|
{
|
||||||
std::map<std::string, json11::Json> file;
|
std::map<std::string, nlohmann::json> file;
|
||||||
std::string fileBuffer = Utils::IO::ReadFile(filename);
|
std::string fileBuffer = Utils::IO::ReadFile(filename);
|
||||||
|
|
||||||
file["name"] = mapname + Maps::UserMapFiles[i];
|
file["name"] = mapname + Maps::UserMapFiles[i];
|
||||||
@ -591,13 +592,13 @@ namespace Components
|
|||||||
// else
|
// else
|
||||||
{
|
{
|
||||||
static std::string fsGamePre;
|
static std::string fsGamePre;
|
||||||
static json11::Json jsonList;
|
static nlohmann::json jsonList;
|
||||||
|
|
||||||
std::string fsGame = Dvar::Var("fs_game").get<std::string>();
|
std::string fsGame = Dvar::Var("fs_game").get<std::string>();
|
||||||
|
|
||||||
if (!fsGame.empty() && fsGame != fsGamePre)
|
if (!fsGame.empty() && fsGame != fsGamePre)
|
||||||
{
|
{
|
||||||
std::vector<json11::Json> fileList;
|
std::vector<nlohmann::json> fileList;
|
||||||
|
|
||||||
fsGamePre = fsGame;
|
fsGamePre = fsGame;
|
||||||
|
|
||||||
@ -611,7 +612,7 @@ namespace Components
|
|||||||
std::string filename = path + "\\" + *i;
|
std::string filename = path + "\\" + *i;
|
||||||
if (strstr(i->data(), "_svr_") == nullptr && Utils::IO::FileExists(filename))
|
if (strstr(i->data(), "_svr_") == nullptr && Utils::IO::FileExists(filename))
|
||||||
{
|
{
|
||||||
std::map<std::string, json11::Json> file;
|
std::map<std::string, nlohmann::json> file;
|
||||||
std::string fileBuffer = Utils::IO::ReadFile(filename);
|
std::string fileBuffer = Utils::IO::ReadFile(filename);
|
||||||
|
|
||||||
file["name"] = *i;
|
file["name"] = *i;
|
||||||
@ -735,16 +736,16 @@ namespace Components
|
|||||||
Utils::InfoString status = ServerInfo::GetInfo();
|
Utils::InfoString status = ServerInfo::GetInfo();
|
||||||
Utils::InfoString host = ServerInfo::GetHostInfo();
|
Utils::InfoString host = ServerInfo::GetHostInfo();
|
||||||
|
|
||||||
std::map<std::string, json11::Json> info;
|
std::map<std::string, nlohmann::json> info;
|
||||||
info["status"] = status.to_json();
|
info["status"] = status.to_json();
|
||||||
info["host"] = host.to_json();
|
info["host"] = host.to_json();
|
||||||
|
|
||||||
std::vector<json11::Json> players;
|
std::vector<nlohmann::json> players;
|
||||||
|
|
||||||
// Build player list
|
// Build player list
|
||||||
for (int i = 0; i < atoi(status.get("sv_maxclients").data()); ++i) // Maybe choose 18 here?
|
for (int i = 0; i < atoi(status.get("sv_maxclients").data()); ++i) // Maybe choose 18 here?
|
||||||
{
|
{
|
||||||
std::map<std::string, json11::Json> playerInfo;
|
std::map<std::string, nlohmann::json> playerInfo;
|
||||||
playerInfo["score"] = 0;
|
playerInfo["score"] = 0;
|
||||||
playerInfo["ping"] = 0;
|
playerInfo["ping"] = 0;
|
||||||
playerInfo["name"] = "";
|
playerInfo["name"] = "";
|
||||||
@ -777,7 +778,7 @@ namespace Components
|
|||||||
"Connection: close\r\n"
|
"Connection: close\r\n"
|
||||||
"Access-Control-Allow-Origin: *\r\n"
|
"Access-Control-Allow-Origin: *\r\n"
|
||||||
"\r\n"
|
"\r\n"
|
||||||
"%s", json11::Json(info).dump().data());
|
"%s", nlohmann::json(info).dump().data());
|
||||||
|
|
||||||
nc->flags |= MG_F_SEND_AND_CLOSE;
|
nc->flags |= MG_F_SEND_AND_CLOSE;
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const json11::Json json = Data;
|
const nlohmann::json json = Data;
|
||||||
|
|
||||||
FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump());
|
FileSystem::FileWriter("scriptdata/scriptstorage.json").write(json.dump());
|
||||||
});
|
});
|
||||||
|
@ -62,7 +62,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json MapRotation::RotationData::to_json() const
|
nlohmann::json MapRotation::RotationData::to_json() const
|
||||||
{
|
{
|
||||||
std::vector<std::string> mapVector;
|
std::vector<std::string> mapVector;
|
||||||
std::vector<std::string> gametypeVector;
|
std::vector<std::string> gametypeVector;
|
||||||
@ -80,7 +80,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
json11::Json mapRotationJson = json11::Json::object
|
nlohmann::json mapRotationJson = nlohmann::json
|
||||||
{
|
{
|
||||||
{"maps", mapVector},
|
{"maps", mapVector},
|
||||||
{"gametypes", gametypeVector},
|
{"gametypes", gametypeVector},
|
||||||
|
@ -34,7 +34,7 @@ namespace Components
|
|||||||
void parse(const std::string& data);
|
void parse(const std::string& data);
|
||||||
|
|
||||||
// Json11 Implicit constructor
|
// Json11 Implicit constructor
|
||||||
[[nodiscard]] json11::Json to_json() const;
|
[[nodiscard]] nlohmann::json to_json() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<rotationEntry> rotationEntries_;
|
std::vector<rotationEntry> rotationEntries_;
|
||||||
|
@ -50,7 +50,7 @@ namespace Components
|
|||||||
this->lastRequest.reset();
|
this->lastRequest.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json Node::Entry::to_json() const
|
nlohmann::json Node::Entry::to_json() const
|
||||||
{
|
{
|
||||||
return this->address.getString();
|
return this->address.getString();
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace Components
|
|||||||
void sendRequest();
|
void sendRequest();
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
json11::Json to_json() const;
|
nlohmann::json to_json() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node();
|
Node();
|
||||||
|
@ -318,7 +318,7 @@ namespace Components
|
|||||||
if (Utils::IO::FileExists("players/favourites.json"))
|
if (Utils::IO::FileExists("players/favourites.json"))
|
||||||
{
|
{
|
||||||
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
||||||
json11::Json object = json11::Json::parse(data, data);
|
nlohmann::json object = nlohmann::json::parse(data);
|
||||||
|
|
||||||
if (!object.is_array())
|
if (!object.is_array())
|
||||||
{
|
{
|
||||||
@ -327,24 +327,24 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto storedServers = object.array_items();
|
nlohmann::json::array_t storedServers = object;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < storedServers.size(); ++i)
|
for (unsigned int i = 0; i < storedServers.size(); ++i)
|
||||||
{
|
{
|
||||||
if (!storedServers[i].is_string()) continue;
|
if (!storedServers[i].is_string()) continue;
|
||||||
if (storedServers[i].string_value() == server)
|
if (storedServers[i].get<std::string>() == server)
|
||||||
{
|
{
|
||||||
Game::ShowMessageBox("Server already marked as favourite.", "Error");
|
Game::ShowMessageBox("Server already marked as favourite.", "Error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
servers.push_back(storedServers[i].string_value());
|
servers.push_back(storedServers[i].get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
servers.push_back(server);
|
servers.push_back(server);
|
||||||
|
|
||||||
json11::Json data = json11::Json(servers);
|
nlohmann::json data = nlohmann::json(servers);
|
||||||
Utils::IO::WriteFile("players/favourites.json", data.dump());
|
Utils::IO::WriteFile("players/favourites.json", data.dump());
|
||||||
Game::ShowMessageBox("Server added to favourites.", "Success");
|
Game::ShowMessageBox("Server added to favourites.", "Success");
|
||||||
}
|
}
|
||||||
@ -356,7 +356,7 @@ namespace Components
|
|||||||
if (Utils::IO::FileExists("players/favourites.json"))
|
if (Utils::IO::FileExists("players/favourites.json"))
|
||||||
{
|
{
|
||||||
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
||||||
json11::Json object = json11::Json::parse(data, data);
|
nlohmann::json object = nlohmann::json::parse(data);
|
||||||
|
|
||||||
if (!object.is_array())
|
if (!object.is_array())
|
||||||
{
|
{
|
||||||
@ -365,16 +365,18 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& storedServer : object.array_items())
|
nlohmann::json::array_t arr = object;
|
||||||
|
|
||||||
|
for (auto& storedServer : arr)
|
||||||
{
|
{
|
||||||
if (storedServer.is_string() && storedServer.string_value() != server)
|
if (storedServer.is_string() && storedServer.get<std::string>() != server)
|
||||||
{
|
{
|
||||||
servers.push_back(storedServer.string_value());
|
servers.push_back(storedServer.get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json11::Json data = json11::Json(servers);
|
nlohmann::json data = nlohmann::json(servers);
|
||||||
Utils::IO::WriteFile("players/favourites.json", data.dump());
|
Utils::IO::WriteFile("players/favourites.json", data.dump());
|
||||||
|
|
||||||
auto list = ServerList::GetList();
|
auto list = ServerList::GetList();
|
||||||
@ -393,7 +395,7 @@ namespace Components
|
|||||||
if (list) list->clear();
|
if (list) list->clear();
|
||||||
|
|
||||||
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
std::string data = Utils::IO::ReadFile("players/favourites.json");
|
||||||
json11::Json object = json11::Json::parse(data, data);
|
nlohmann::json object = nlohmann::json::parse(data);
|
||||||
|
|
||||||
if (!object.is_array())
|
if (!object.is_array())
|
||||||
{
|
{
|
||||||
@ -402,12 +404,12 @@ namespace Components
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto servers = object.array_items();
|
nlohmann::json::array_t servers = object;
|
||||||
|
|
||||||
for (unsigned int i = 0; i < servers.size(); ++i)
|
for (unsigned int i = 0; i < servers.size(); ++i)
|
||||||
{
|
{
|
||||||
if (!servers[i].is_string()) continue;
|
if (!servers[i].is_string()) continue;
|
||||||
ServerList::InsertRequest(servers[i].string_value());
|
ServerList::InsertRequest(servers[i].get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,7 @@ namespace Components
|
|||||||
std::unordered_map<std::string, std::string> otherPatches;
|
std::unordered_map<std::string, std::string> otherPatches;
|
||||||
|
|
||||||
std::string errors;
|
std::string errors;
|
||||||
json11::Json defData = json11::Json::parse(definition.getBuffer(), errors);
|
nlohmann::json defData = nlohmann::json::parse(definition.getBuffer());
|
||||||
|
|
||||||
if (!errors.empty())
|
if (!errors.empty())
|
||||||
{
|
{
|
||||||
@ -228,11 +228,11 @@ namespace Components
|
|||||||
|
|
||||||
if (enumData.is_array())
|
if (enumData.is_array())
|
||||||
{
|
{
|
||||||
for (auto rawEntry : enumData.array_items())
|
for (auto rawEntry : enumData)
|
||||||
{
|
{
|
||||||
if (rawEntry.is_string())
|
if (rawEntry.is_string())
|
||||||
{
|
{
|
||||||
entryData.push_back(rawEntry.string_value());
|
entryData.push_back(rawEntry.get<std::string>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -244,11 +244,11 @@ namespace Components
|
|||||||
|
|
||||||
if (other.is_object())
|
if (other.is_object())
|
||||||
{
|
{
|
||||||
for (auto& item : other.object_items())
|
for (auto& item : other.items())
|
||||||
{
|
{
|
||||||
if (item.second.is_string())
|
if (item.value().is_string())
|
||||||
{
|
{
|
||||||
otherPatches[item.first] = item.second.string_value();
|
otherPatches[item.key()] = item.value().get<std::string>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ namespace Components
|
|||||||
|
|
||||||
// Write metadata
|
// Write metadata
|
||||||
FileSystem::FileWriter meta(Utils::String::VA("%s.json", Theatre::CurrentInfo.name.data()));
|
FileSystem::FileWriter meta(Utils::String::VA("%s.json", Theatre::CurrentInfo.name.data()));
|
||||||
meta.write(json11::Json(Theatre::CurrentInfo).dump());
|
meta.write(nlohmann::json(Theatre::CurrentInfo.to_json()).dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Theatre::LoadDemos(UIScript::Token)
|
void Theatre::LoadDemos(UIScript::Token)
|
||||||
@ -195,18 +195,18 @@ namespace Components
|
|||||||
if (meta.exists())
|
if (meta.exists())
|
||||||
{
|
{
|
||||||
std::string error;
|
std::string error;
|
||||||
json11::Json metaObject = json11::Json::parse(meta.getBuffer(), error);
|
nlohmann::json metaObject = nlohmann::json::parse(meta.getBuffer());
|
||||||
|
|
||||||
if (metaObject.is_object())
|
if (metaObject.is_object())
|
||||||
{
|
{
|
||||||
Theatre::DemoInfo info;
|
Theatre::DemoInfo info;
|
||||||
|
|
||||||
info.name = demo.substr(0, demo.find_last_of("."));
|
info.name = demo.substr(0, demo.find_last_of("."));
|
||||||
info.author = metaObject["author"].string_value();
|
info.author = metaObject["author"].get<std::string>();
|
||||||
info.gametype = metaObject["gametype"].string_value();
|
info.gametype = metaObject["gametype"].get<std::string>();
|
||||||
info.mapname = metaObject["mapname"].string_value();
|
info.mapname = metaObject["mapname"].get<std::string>();
|
||||||
info.length = static_cast<int>(metaObject["length"].number_value());
|
info.length = metaObject["length"].get<int>();
|
||||||
info.timeStamp = _atoi64(metaObject["timestamp"].string_value().data());
|
info.timeStamp = _atoi64(metaObject["timestamp"].get<std::string>().data());
|
||||||
|
|
||||||
Theatre::Demos.push_back(info);
|
Theatre::Demos.push_back(info);
|
||||||
}
|
}
|
||||||
|
@ -20,9 +20,9 @@ namespace Components
|
|||||||
int length;
|
int length;
|
||||||
std::time_t timeStamp;
|
std::time_t timeStamp;
|
||||||
|
|
||||||
json11::Json to_json() const
|
nlohmann::json to_json() const
|
||||||
{
|
{
|
||||||
return json11::Json::object
|
return nlohmann::json
|
||||||
{
|
{
|
||||||
{ "mapname", mapname },
|
{ "mapname", mapname },
|
||||||
{ "gametype", gametype },
|
{ "gametype", gametype },
|
||||||
|
@ -1523,7 +1523,7 @@ namespace Components
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger::Print("------------------- BEGIN IWI DUMP -------------------\n");
|
Logger::Print("------------------- BEGIN IWI DUMP -------------------\n");
|
||||||
Logger::Print("{}\n", json11::Json(images).dump());
|
Logger::Print("{}\n", nlohmann::json(images).dump());
|
||||||
Logger::Print("------------------- END IWI DUMP -------------------\n");
|
Logger::Print("------------------- END IWI DUMP -------------------\n");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -78,7 +78,6 @@
|
|||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <gsl/gsl>
|
#include <gsl/gsl>
|
||||||
#include <json11.hpp>
|
|
||||||
#include <tomcrypt.h>
|
#include <tomcrypt.h>
|
||||||
#include <mongoose.h>
|
#include <mongoose.h>
|
||||||
#include <udis86.h>
|
#include <udis86.h>
|
||||||
@ -95,6 +94,12 @@ using namespace std::literals;
|
|||||||
#undef min
|
#undef min
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Needs to be included after the nominmax above ^
|
||||||
|
#ifdef snprintf
|
||||||
|
#undef snprintf
|
||||||
|
#endif
|
||||||
|
#include <json.hpp>
|
||||||
|
|
||||||
#define AssertSize(x, size) \
|
#define AssertSize(x, size) \
|
||||||
static_assert(sizeof(x) == (size), \
|
static_assert(sizeof(x) == (size), \
|
||||||
"Structure has an invalid size. " #x " must be " #size " bytes")
|
"Structure has an invalid size. " #x " must be " #size " bytes")
|
||||||
|
@ -74,7 +74,7 @@ namespace Utils
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
json11::Json InfoString::to_json() const
|
nlohmann::json InfoString::to_json() const
|
||||||
{
|
{
|
||||||
return {this->keyValuePairs};
|
return {this->keyValuePairs};
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ namespace Utils
|
|||||||
void dump();
|
void dump();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
[[nodiscard]] json11::Json to_json() const;
|
[[nodiscard]] nlohmann::json to_json() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::string> keyValuePairs;
|
std::unordered_map<std::string, std::string> keyValuePairs;
|
||||||
|
@ -2,24 +2,28 @@
|
|||||||
|
|
||||||
namespace Utils::Json
|
namespace Utils::Json
|
||||||
{
|
{
|
||||||
std::string TypeToString(json11::Json::Type type)
|
std::string TypeToString(nlohmann::json::value_t type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case json11::Json::NUL:
|
case nlohmann::json::value_t::null:
|
||||||
return "NUL";
|
return "null";
|
||||||
case json11::Json::NUMBER:
|
case nlohmann::json::value_t::number_integer:
|
||||||
return "NUMBER";
|
return "number_integer";
|
||||||
case json11::Json::BOOL:
|
case nlohmann::json::value_t::number_unsigned:
|
||||||
return "BOOL";
|
return "number_unsigned";
|
||||||
case json11::Json::STRING:
|
case nlohmann::json::value_t::number_float:
|
||||||
return "STRING";
|
return "number_float";
|
||||||
case json11::Json::ARRAY:
|
case nlohmann::json::value_t::boolean:
|
||||||
return "ARRAY";
|
return "boolean";
|
||||||
case json11::Json::OBJECT:
|
case nlohmann::json::value_t::string:
|
||||||
return "OBJECT";
|
return "string";
|
||||||
|
case nlohmann::json::value_t::array:
|
||||||
|
return "array";
|
||||||
|
case nlohmann::json::value_t::object:
|
||||||
|
return "object";
|
||||||
default:
|
default:
|
||||||
return "NUL";
|
return "null";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
namespace Utils::Json
|
namespace Utils::Json
|
||||||
{
|
{
|
||||||
std::string TypeToString(json11::Json::Type type);
|
std::string TypeToString(nlohmann::json::value_t type);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user