Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterCouto committed Apr 3, 2023
1 parent 746a02c commit 88c8b1d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
15 changes: 14 additions & 1 deletion source/D2ItemToolTipCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,20 @@ CSize CD2ItemToolTipCtrl::DoDrawItemInfo(CDC* pDC, CRect rect, BOOL bCalcOnly, c
}
}

if (currItem->isEthereal())
if (currItem->isCharm())
{
std::string u8Text;
uText = utf8::utf8to16(d2ce::LocalizationHelpers::GetCharmsStringTxtValue(u8Text));
strText = reinterpret_cast<LPCWSTR>(uText.c_str());

CSize prevSizeText = sizeText;
pDC->SetTextColor(d2ce::ColorHelpers::GetColorFromChar(d2ce::ColorHelpers::D2Colors::WHITE));

sizeText = CalcTextSize(pDC, strText, rect, bCalcOnly);
sizeText.cy += prevSizeText.cy;
sizeText.cx = std::max(prevSizeText.cx, sizeText.cx);
}
else if (currItem->isEthereal())
{
CSize prevSizeText = sizeText;
pDC->SetTextColor(d2ce::ColorHelpers::GetColorFromChar(d2ce::ColorHelpers::D2Colors::BLUE));
Expand Down
53 changes: 53 additions & 0 deletions source/d2ce/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,22 @@ void d2ce::Character::readHeader(const Json::Value& root)
std::uint32_t uint = m_bJsonSerializedFormat ? std::uint32_t(value.asInt64()) : std::uint32_t(std::stoul(value.asString(), nullptr, 16));
size_t current_byte_offset = 0;
setBytes(current_byte_offset, HEADER_LENGTH, uint);

if (Bs.Version < EnumCharVersion::v100R)
{
setTxtReader(getDefaultTxtReader());
return;
}

value = header[m_bJsonSerializedFormat ? "ModName" : "mod_name"];
if (value.isNull())
{
setTxtReader(getDefaultTxtReader());
return;
}

std::string modName(value.asString());
setTxtReader(getDefaultTxtReader(modName));
}
//---------------------------------------------------------------------------
std::uint32_t d2ce::Character::getHeaderBytes() const
Expand Down Expand Up @@ -2358,9 +2374,19 @@ void d2ce::Character::headerAsJson(Json::Value& parent, EnumCharVersion version,
headerAsJson(parent, bSerializedFormat);
return;
}

if (bSerializedFormat)
{
Json::Value header;
if (version >= EnumCharVersion::v100R)
{
const auto& txtReader = getTxtReader();
if (!txtReader.GetModName().empty())
{
header["ModName"] = txtReader.GetModName();
}
}

header["Magic"] = getHeaderBytes();
header["Version"] = static_cast<std::underlying_type_t<EnumCharVersion>>(version);
if ((version >= EnumCharVersion::v109) && (Bs.Version >= EnumCharVersion::v109))
Expand Down Expand Up @@ -2576,6 +2602,15 @@ void d2ce::Character::headerAsJson(Json::Value& parent, EnumCharVersion version,
else
{
Json::Value header;
if (version >= EnumCharVersion::v100R)
{
const auto& txtReader = getTxtReader();
if (!txtReader.GetModName().empty())
{
header["mod_name"] = txtReader.GetModName();
}
}

{
std::stringstream ss;
ss << std::hex << getHeaderBytes();
Expand Down Expand Up @@ -2809,6 +2844,15 @@ void d2ce::Character::headerAsJson(Json::Value& parent, bool bSerializedFormat)
if (bSerializedFormat)
{
Json::Value header;
if (Bs.Version >= EnumCharVersion::v100R)
{
const auto& txtReader = getTxtReader();
if (!txtReader.GetModName().empty())
{
header["Mod"] = txtReader.GetModName();
}
}

header["Magic"] = getHeaderBytes();
header["Version"] = getVersionBytes();
if (Bs.Version >= EnumCharVersion::v109)
Expand Down Expand Up @@ -3026,6 +3070,15 @@ void d2ce::Character::headerAsJson(Json::Value& parent, bool bSerializedFormat)
else
{
Json::Value header;
if (Bs.Version >= EnumCharVersion::v100R)
{
const auto& txtReader = getTxtReader();
if (!txtReader.GetModName().empty())
{
header["mod_name"] = txtReader.GetModName();
}
}

{
std::stringstream ss;
ss << std::hex << getHeaderBytes();
Expand Down
9 changes: 9 additions & 0 deletions source/d2ce/helpers/ItemHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14584,6 +14584,15 @@ const std::string& d2ce::LocalizationHelpers::GetDifficultyStringTxtValue(EnumDi
}
return outStr;
}
//---------------------------------------------------------------------------
const std::string& d2ce::LocalizationHelpers::GetCharmsStringTxtValue(std::string& outStr)
{
std::string gender;
const std::string str("Charmdes");
GetStringTxtValue(str, outStr, gender, "Keep in Inventory to Gain Bonus");
return outStr;
}
//---------------------------------------------------------------------------
const std::string& d2ce::LocalizationHelpers::CheckCharName(std::string& curName, EnumCharVersion version)
{
bool bASCII = (version <= EnumCharVersion::v100R) ? true : false;
Expand Down
1 change: 1 addition & 0 deletions source/d2ce/helpers/ItemHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ namespace d2ce
const std::string& GetSocketedStringTxtValue(std::string& outStr, std::string& gender);
const std::string& GetSocketedStringTxtValue(std::string& outStr);
const std::string& GetDifficultyStringTxtValue(EnumDifficulty diff, std::string& outStr);
const std::string& GetCharmsStringTxtValue(std::string& outStr);

const std::string& CheckCharName(std::string& curName, d2ce::EnumCharVersion version);
const std::string& CheckCharName(std::string& curName, d2ce::EnumItemVersion version);
Expand Down

0 comments on commit 88c8b1d

Please sign in to comment.