Implements a basic CreateMessage function for non-GetItem text.

This commit is contained in:
Christopher Leggett 2022-07-19 00:31:37 -04:00
parent e04b2c80b6
commit 32abe61554
No known key found for this signature in database
GPG Key ID: 7093AE5FF7037D79
2 changed files with 33 additions and 6 deletions

View File

@ -60,13 +60,20 @@ void CustomMessage::FormatCustomMessage(std::string& message, ItemID iid) {
message += MESSAGE_END(); 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::InsertCustomMessage(std::string tableID, uint16_t textID, CustomMessageEntry messages) {
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;
auto result = messageTables.find(tableID); auto result = messageTables.find(tableID);
if (result == messageTables.end()) { if (result == messageTables.end()) {
return false; return false;
@ -76,6 +83,23 @@ bool CustomMessage::CreateGetItemMessage(std::string tableID, GetItemID giid, It
return success.second; 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::string CustomMessage::RetrieveMessage(std::string tableID, uint16_t textID) {
std::unordered_map<std::string, CustomMessageTable>::const_iterator result = messageTables.find(tableID); std::unordered_map<std::string, CustomMessageTable>::const_iterator result = messageTables.find(tableID);
if (result == messageTables.end()) { if (result == messageTables.end()) {

View File

@ -31,6 +31,8 @@ class CustomMessage {
void ReplaceSpecialCharacters(std::string &string); void ReplaceSpecialCharacters(std::string &string);
void ReplaceColors(std::string& string); void ReplaceColors(std::string& string);
void FormatCustomMessage(std::string& message, ItemID iid); 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 MESSAGE_END();
std::string ITEM_OBTAINED(uint8_t x); std::string ITEM_OBTAINED(uint8_t x);
@ -46,6 +48,7 @@ class CustomMessage {
~CustomMessage(); ~CustomMessage();
bool CreateGetItemMessage(std::string tableID, GetItemID giid, ItemID iid, CustomMessageEntry messages); 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); std::string RetrieveMessage(std::string tableID, uint16_t textID);
bool AddCustomMessageTable(std::string tableID); bool AddCustomMessageTable(std::string tableID);
}; };