Skip to content

Commit

Permalink
Implements a basic CreateMessage function for non-GetItem text.
Browse files Browse the repository at this point in the history
  • Loading branch information
leggettc18 committed Jul 19, 2022
1 parent e04b2c8 commit 32abe61
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
36 changes: 30 additions & 6 deletions soh/soh/Enhancements/custom_message/CustomMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,20 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) {
message += MESSAGE_END();
}

void CustomMessage::FormatCustomMessage(std::string& message) {
size_t start_pos = 0;
std::replace(message.begin(), message.end(), '&', NEWLINE()[0]);
while ((start_pos = message.find('^', start_pos)) != std::string::npos) {
message.replace(start_pos, 1, WAIT_FOR_INPUT());
start_pos += 3;
}
std::replace(message.begin(), message.end(), '@', PLAYER_NAME()[0]);
ReplaceSpecialCharacters(message);
ReplaceColors(message);
message += MESSAGE_END();
}


bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) {
FormatCustomMessage(messages.english, iid);
FormatCustomMessage(messages.german, iid);
FormatCustomMessage(messages.french, iid);
const uint16_t textID = giid;
bool CustomMessage::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
auto result = messageTables.find(tableID);
if (result == messageTables.end()) {
return false;
Expand All @@ -76,6 +83,23 @@ bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, It
return success.second;
}



bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages) {
FormatCustomMessage(messages.english, iid);
FormatCustomMessage(messages.german, iid);
FormatCustomMessage(messages.french, iid);
const uint16_t textID = giid;
return InsertCustomMessage(tableID, textID, messages);
}

bool CustomMessage::CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
FormatCustomMessage(messages.english);
FormatCustomMessage(messages.german);
FormatCustomMessage(messages.french);
return InsertCustomMessage(tableID, textID, messages);
}

std::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) {
std::unordered_map<std::string, CustomMessageTable>::const_iterator result = messageTables.find(tableID);
if (result == messageTables.end()) {
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/Enhancements/custom_message/CustomMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class CustomMessage {
void ReplaceSpecialCharacters(std::string &string);
void ReplaceColors(std::string& string);
void FormatCustomMessage(std::string& message, ItemID iid);
void FormatCustomMessage(std::string& message);
bool InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages);

std::string MESSAGE_END();
std::string ITEM_OBTAINED(uint8_t x);
Expand All @@ -46,6 +48,7 @@ class CustomMessage {
~CustomMessage();

bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages);
bool CreateMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages);
std::string RetrieveMessage(std::string tableID, uint16_t textID);
bool AddCustomMessageTable(std::string tableID);
};

0 comments on commit 32abe61

Please sign in to comment.