This repository has been archived by the owner on Jan 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f9d641e
commit 2369c9d
Showing
13 changed files
with
425 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
} |
Oops, something went wrong.