Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
Moved loaders into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed May 14, 2022
1 parent f9d641e commit 2369c9d
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 359 deletions.
4 changes: 4 additions & 0 deletions Blueprint Converter.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
<ClCompile Include="Code\Lib\String.cpp" />
<ClCompile Include="Code\Main.cpp" />
<ClCompile Include="Code\ObjectDatabase\Blueprint.cpp" />
<ClCompile Include="Code\ObjectDatabase\DataLoaders\BlockListLoader.cpp" />
<ClCompile Include="Code\ObjectDatabase\DataLoaders\PartListLoader.cpp" />
<ClCompile Include="Code\ObjectDatabase\KeywordReplacer.cpp" />
<ClCompile Include="Code\ObjectDatabase\LanguageDatabase.cpp" />
<ClCompile Include="Code\ObjectDatabase\MaterialManager.cpp" />
Expand Down Expand Up @@ -96,6 +98,8 @@
<ClInclude Include="Code\Lib\String.h" />
<ClInclude Include="Code\Lib\WinInclude.h" />
<ClInclude Include="Code\ObjectDatabase\Blueprint.h" />
<ClInclude Include="Code\ObjectDatabase\DataLoaders\BlockListLoader.h" />
<ClInclude Include="Code\ObjectDatabase\DataLoaders\PartListLoader.h" />
<ClInclude Include="Code\ObjectDatabase\KeywordReplacer.h" />
<ClInclude Include="Code\ObjectDatabase\LanguageDatabase.h" />
<ClInclude Include="Code\ObjectDatabase\MaterialManager.h" />
Expand Down
4 changes: 4 additions & 0 deletions Blueprint Converter.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<ClCompile Include="Code\ObjectDatabase\ObjectRotations.cpp" />
<ClCompile Include="Code\BlueprintConverter\ObjectDefinitions\BlockModel.cpp" />
<ClCompile Include="Code\ObjectDatabase\MaterialManager.cpp" />
<ClCompile Include="Code\ObjectDatabase\DataLoaders\BlockListLoader.cpp" />
<ClCompile Include="Code\ObjectDatabase\DataLoaders\PartListLoader.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Code\BlueprintConverter\BlueprintConverter.h" />
Expand Down Expand Up @@ -77,5 +79,7 @@
<ClInclude Include="Code\ObjectDatabase\MaterialManager.h" />
<ClInclude Include="Code\Lib\WinInclude.h" />
<ClInclude Include="Code\ConsoleColors.hpp" />
<ClInclude Include="Code\ObjectDatabase\DataLoaders\BlockListLoader.h" />
<ClInclude Include="Code\ObjectDatabase\DataLoaders\PartListLoader.h" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion Code/Gui/About.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ namespace BlueprintConverter {
this->Version_LBL->Name = L"Version_LBL";
this->Version_LBL->Size = System::Drawing::Size(86, 16);
this->Version_LBL->TabIndex = 6;
this->Version_LBL->Text = L"Version: 1.1.1";
this->Version_LBL->Text = L"Version: 1.1.2";
this->Version_LBL->TextAlign = System::Drawing::ContentAlignment::MiddleLeft;
//
// GitHubRepo_LL
Expand Down
2 changes: 1 addition & 1 deletion Code/Lib/BuildVersion.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#pragma once
#define SMBC_BUILD_VERSION 858
#define SMBC_BUILD_VERSION 863
36 changes: 0 additions & 36 deletions Code/Lib/Json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,42 +72,6 @@ namespace SMBC
#endif

return nlohmann::json();
/*try
{
std::ifstream _InputFile(path);
if (_InputFile.is_open())
{
std::string _RawJson;
if (_stringify)
_RawJson = Json::ReadWholeFile(_InputFile);
else
{
std::stringstream sstream;
sstream << _InputFile.rdbuf();
_RawJson = sstream.str();
}
return nlohmann::json::parse(_RawJson, nullptr, true, true);
}
#ifdef _DEBUG
else
{
DebugErrorL("Couldn't open the specified file: ", path);
}
#endif
}
#ifdef _DEBUG
catch (nlohmann::json::parse_error& err)
{
DebugErrorL("Couldn't load the specified json file:\nFile: ", path, "\nByte: ", err.byte, "\nId: ", err.id, "\nError Message: ", err.what());
}
#else
catch (...) {}
#endif
return nlohmann::json();*/
}

void Json::WriteToFile(const std::wstring& path, const nlohmann::json& mJson)
Expand Down
91 changes: 91 additions & 0 deletions Code/ObjectDatabase/DataLoaders/BlockListLoader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include "BlockListLoader.h"

#include "ObjectDatabase\ModData.h"
#include "ObjectDatabase\KeywordReplacer.h"

#include "Lib\ConvData.h"
#include "Lib\String.h"
#include "Lib\Json.h"

#include "DebugCon.h"

namespace SMBC
{
void BlockListLoader::GetBlockMaterials(const nlohmann::json& block, Texture::TextureList& tex)
{
const auto& bGlass = Json::Get(block, "glass");
const auto& bAlpha = Json::Get(block, "alpha");

if (bGlass.is_boolean() && bGlass.get<bool>())
{
tex.material = L"BlockGlass";
}
else
{
tex.material = L"BlockDifAsgNor";

if (bAlpha.is_boolean() && bAlpha.get<bool>())
tex.material.append(L"Alpha");
}
}

static const std::string blkTexNames[3] = { "dif", "asg", "nor" };
bool BlockListLoader::GetBlockTextures(const nlohmann::json& block, Texture::TextureList& tex)
{
for (int a = 0; a < 3; a++)
{
const auto& bTexture = Json::Get(block, blkTexNames[a]);

if (bTexture.is_string())
{
std::wstring& strRef = tex.GetStringRef(a);

strRef = String::ToWide(bTexture.get<std::string>());
strRef = PathReplacer::ReplaceKey(strRef);
}
}

return tex.HasTextures();
}

void BlockListLoader::Load(const nlohmann::json& block_list, Mod* pMod)
{
ConvData::ProgressMax += block_list.size();
for (const auto& l_block : block_list)
{
if (!l_block.is_object()) continue;

const auto& b_uuid = Json::Get(l_block, "uuid");
if (!b_uuid.is_string()) continue;

const auto& b_tiling = Json::Get(l_block, "tiling");
const auto& b_color = Json::Get(l_block, "color");

SMBC::Uuid uuid_obj(b_uuid.get<std::string>());
if (Mod::AllObjects.find(uuid_obj) != Mod::AllObjects.end())
{
DebugWarningL("An object with this uuid already exists! (", uuid_obj.ToString(), ")");
continue;
}

Texture::TextureList tex_list;
if (!BlockListLoader::GetBlockTextures(l_block, tex_list))
continue;

BlockListLoader::GetBlockMaterials(l_block, tex_list);

int tiling_val = (b_tiling.is_number() ? b_tiling.get<int>() : 4);
if (tiling_val > 16 || tiling_val <= 0) tiling_val = 4;

const std::wstring l_NameWstr = pMod->m_LanguageDb.GetTranslation(uuid_obj);

BlockData* p_new_blk = new BlockData(uuid_obj, l_NameWstr, tex_list, tiling_val, pMod);

const auto new_pair = std::make_pair(p_new_blk->Uuid, p_new_blk);
Mod::AllObjects.insert(new_pair);
pMod->m_Objects.insert(new_pair);

ConvData::ProgressValue++;
}
}
}
23 changes: 23 additions & 0 deletions Code/ObjectDatabase/DataLoaders/BlockListLoader.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <nlohmann\json.hpp>

namespace SMBC
{
namespace Texture
{
struct TextureList;
}

class BlockListLoader
{
BlockListLoader() = default;
~BlockListLoader() = default;

static void GetBlockMaterials(const nlohmann::json& block, Texture::TextureList& tex);
static bool GetBlockTextures(const nlohmann::json& block, Texture::TextureList& tex);

public:
static void Load(const nlohmann::json& block_list, class Mod* pMod);
};
}
Loading

0 comments on commit 2369c9d

Please sign in to comment.