Skip to content

Commit

Permalink
Merge pull request #44 from Pepper0ni/FixPatch
Browse files Browse the repository at this point in the history
Apply patch
  • Loading branch information
Caladius authored Nov 13, 2024
2 parents e5ecf6a + 3b1d1ee commit aafd19d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
42 changes: 30 additions & 12 deletions soh/soh/Enhancements/custom-message/CustomMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ static const std::unordered_map<std::string, std::string> percentColors = { { "w
{ "b", QM_BLUE }, { "c", QM_LBLUE }, { "p", QM_PINK },
{ "y", QM_YELLOW }, { "B", QM_BLACK } };

static const std::unordered_map<std::string, std::string> colorToPercent = { { QM_WHITE, "%w" }, { QM_RED, "%r"}, { QM_GREEN, "%g" },
{ QM_BLUE, "%b" }, { QM_LBLUE, "%c"}, { QM_PINK, "%p" },
{ QM_YELLOW, "%y" }, { QM_BLACK, "%B" } };

static const std::unordered_map<std::string, ItemID> altarIcons = {
{ "0", ITEM_KOKIRI_EMERALD },
{ "1", ITEM_GORON_RUBY },
Expand Down Expand Up @@ -147,6 +151,8 @@ void CustomMessage::ProcessMessageFormat(std::string& str, MessageFormat format)
CleanString(str);
} else if (format == MF_AUTO_FORMAT){
AutoFormatString(str);
}else if (format == MF_ENCODE){
EncodeColors(str);
}
}

Expand Down Expand Up @@ -281,6 +287,12 @@ void CustomMessage::Clean() {
}
}

void CustomMessage::Encode() {
for (std::string& str : messages) {
EncodeColors(str);
}
}

void CustomMessage::FormatString(std::string& str) const {
std::replace(str.begin(), str.end(), '&', NEWLINE()[0]);
std::replace(str.begin(), str.end(), '^', WAIT_FOR_INPUT()[0]);
Expand Down Expand Up @@ -506,7 +518,23 @@ const char* Interface_ReplaceSpecialCharacters(char text[]) {
return textChar;
}

void CustomMessage::EncodeColors(std::string& str) const {
for (std::string color: colors) {
if (const size_t firstHashtag = str.find('#'); firstHashtag != std::string::npos) {
str.replace(firstHashtag, 1, colorToPercent.at(color));
if (const size_t secondHashtag = str.find('#', firstHashtag + 1); secondHashtag != std::string::npos) {
str.replace(secondHashtag, 1, "%w");
} else {
SPDLOG_DEBUG("non-matching hashtags in string: \"%s\"", str);
}
}
}
// Remove any remaining '#' characters.
std::erase(str, '#');
}

void CustomMessage::ReplaceColors(std::string& str) const {
EncodeColors(str);
for (const auto& colorPair : percentColors) {
std::string textToReplace = "%";
textToReplace += colorPair.first;
Expand All @@ -516,18 +544,6 @@ void CustomMessage::ReplaceColors(std::string& str) const {
start_pos += textToReplace.length();
}
}
for (auto color: colors) {
if (const size_t firstHashtag = str.find('#'); firstHashtag != std::string::npos) {
str.replace(firstHashtag, 1, COLOR(color));
if (const size_t secondHashtag = str.find('#', firstHashtag + 1); secondHashtag != std::string::npos) {
str.replace(secondHashtag, 1, COLOR(QM_WHITE));
} else {
SPDLOG_DEBUG("non-matching hashtags in string: \"%s\"", str);
}
}
}
// Remove any remaining '#' characters.
std::erase(str, '#');
}

void CustomMessage::ReplaceAltarIcons(std::string& str) const {
Expand Down Expand Up @@ -619,6 +635,8 @@ CustomMessage CustomMessageManager::RetrieveMessage(std::string tableID, uint16_
message.AutoFormat();
} else if (format == MF_CLEAN){
message.Clean();
} else if (format == MF_ENCODE){
message.Encode();
}

return message;
Expand Down
13 changes: 12 additions & 1 deletion soh/soh/Enhancements/custom-message/CustomMessageManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ typedef enum {
MF_FORMATTED,
MF_CLEAN,
MF_RAW,
MF_AUTO_FORMAT
MF_AUTO_FORMAT,
MF_ENCODE,
} MessageFormat;

/**
Expand Down Expand Up @@ -108,6 +109,11 @@ class CustomMessage {
*/
void ReplaceSpecialCharacters(std::string& str) const;

/**
* @brief Replaces hashtags with stored colors.
*/
void EncodeColors(std::string& str) const;

/**
* @brief Replaces our color variable strings with the OoT control codes.
*/
Expand Down Expand Up @@ -160,6 +166,11 @@ class CustomMessage {
*/
void Clean();

/**
* @brief Replaces variable characters with fixed ones to store the sata in string form
*/
void Encode();

/**
* @brief Replaces various symbols with the control codes necessary to
* display them in OoT's textboxes for a single string
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/Enhancements/randomizer/3drando/hints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ StaticHintInfo::StaticHintInfo(HintType _type, std::vector<RandomizerHintTextKey

RandomizerHintTextKey GetRandomJunkHint(){
//temp code to handle random junk hints now I work in keys instead of a vector of HintText
// Will be replaced with a better system once more customisable hint pools are added
//Will be replaced with a better system once more customisable hint pools are added
uint32_t range = RHT_JUNK_CREW_29 - RHT_JUNK02;
return (RandomizerHintTextKey)(Random(0, range) + RHT_JUNK02);
}
Expand Down
1 change: 1 addition & 0 deletions soh/soh/Enhancements/randomizer/3drando/hints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct StaticHintInfo{
std::vector<RandomizerCheck> _hintChecks = {}, bool _yourPocket = false, int _num = 0);
};

RandomizerHintTextKey GetRandomJunkHint();
extern void CreateAllHints();
extern void CreateWarpSongTexts();
void CreateStaticHints();
Expand Down
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/randomizer/Plandomizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ void PlandomizerItemImageCorrection(Rando::Item randoItem) {

void PlandomizerRandomizeHint(int32_t status, int32_t index) {
if (status == HINT_SINGLE) {
plandoHintData[index].hintText = Rando::StaticData::hintTextTable[GetRandomJunkHint()].GetHintMessage().GetForCurrentLanguage();
plandoHintData[index].hintText = Rando::StaticData::hintTextTable[GetRandomJunkHint()].GetHintMessage().GetForCurrentLanguage(MF_ENCODE);
} else {
for (auto& hint : plandoHintData) {
hint.hintText = Rando::StaticData::hintTextTable[GetRandomJunkHint()].GetHintMessage().GetForCurrentLanguage();
hint.hintText = Rando::StaticData::hintTextTable[GetRandomJunkHint()].GetHintMessage().GetForCurrentLanguage(MF_ENCODE);
}
}
}
Expand Down

0 comments on commit aafd19d

Please sign in to comment.