diff --git a/src/app/core/platform/view_controller.h b/src/app/core/platform/view_controller.h index 81c640bd..7b006f00 100644 --- a/src/app/core/platform/view_controller.h +++ b/src/app/core/platform/view_controller.h @@ -12,7 +12,7 @@ @interface AppViewController : UIViewController @property(nonatomic) yaze::app::core::Controller *controller; @property(nonatomic) UIHoverGestureRecognizer *hoverGestureRecognizer; -@property(nontatomic) UIPinchGestureRecognizer *pinchRecognizer; +@property(nonatomic) UIPinchGestureRecognizer *pinchRecognizer; @property(nonatomic) UISwipeGestureRecognizer *swipeRecognizer; @end #endif diff --git a/src/app/editor/message/message_data.h b/src/app/editor/message/message_data.h index 9b42e729..3eda2744 100644 --- a/src/app/editor/message/message_data.h +++ b/src/app/editor/message/message_data.h @@ -13,10 +13,9 @@ namespace editor { const uint8_t MESSAGETERMINATOR = 0x7F; std::string ReplaceAllDictionaryWords(std::string str); -std::vector ParseMessageToData(std::string str); -const std::string CHEESE = "\uBEBE"; // Inserted into commands to protect - // them from dictionary replacements. +// Inserted into commands to protect them from dictionary replacements. +const std::string CHEESE = "\uBEBE"; struct MessageData { int ID; @@ -48,12 +47,6 @@ struct MessageData { ContentsParsed = other.ContentsParsed; } - void SetMessage(std::string messageString) { - ContentsParsed = messageString; - RawString = OptimizeMessageForDictionary(messageString); - RecalculateData(); - } - std::string ToString() { return absl::StrFormat("%0X - %s", ID, ContentsParsed); } @@ -85,11 +78,6 @@ struct MessageData { return finalString; } - - void RecalculateData() { - Data = ParseMessageToData(RawString); - DataParsed = ParseMessageToData(ContentsParsed); - } }; struct TextElement { diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index a454f5a8..bd11c913 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -1,5 +1,6 @@ #include "message_editor.h" +#include #include #include #include @@ -304,7 +305,9 @@ void MessageEditor::ReadAllTextData() { current_message_parsed.clear(); continue; - } else if (current_byte == 0xFF) { + } + + if (current_byte == 0xFF) { break; } @@ -335,7 +338,6 @@ void MessageEditor::ReadAllTextData() { // Check for special characters. text_element = FindMatchingSpecial(current_byte); - if (!text_element.Empty()) { current_message_raw.append(text_element.GetParameterizedToken()); current_message_parsed.append(text_element.GetParameterizedToken()); @@ -388,13 +390,15 @@ TextElement MessageEditor::FindMatchingCommand(uint8_t b) { } TextElement MessageEditor::FindMatchingSpecial(uint8_t value) { - TextElement empty_element; - for (const auto text_element : SpecialChars) { - if (text_element.ID == value) { - return text_element; - } + auto it = std::find_if(SpecialChars.begin(), SpecialChars.end(), + [value](const TextElement& text_element) { + return text_element.ID == value; + }); + if (it != SpecialChars.end()) { + return *it; } - return empty_element; + + return TextElement(); } ParsedElement MessageEditor::FindMatchingElement(std::string str) { @@ -468,7 +472,7 @@ std::vector MessageEditor::ParseMessageToData(std::string str) { pos = next + 1; continue; } else { - uint8_t bb = MessageEditor::FindMatchingCharacter(temp_string[pos++]); + uint8_t bb = FindMatchingCharacter(temp_string[pos++]); if (bb != 0xFF) { core::logf("Error parsing message: %s", temp_string); diff --git a/src/app/editor/message/message_editor.h b/src/app/editor/message/message_editor.h index 72ad082f..eafc77f2 100644 --- a/src/app/editor/message/message_editor.h +++ b/src/app/editor/message/message_editor.h @@ -31,6 +31,7 @@ constexpr int kTextData2End = 0x773FF; constexpr int kPointersDictionaries = 0x74703; constexpr int kCharactersWidth = 0x74ADF; constexpr int kNumDictionaryEntries = 97; +constexpr int kNumMessages = 396; constexpr uint8_t kBlockTerminator = 0x80; constexpr uint8_t DICTOFF = 0x88; @@ -43,7 +44,7 @@ constexpr uint8_t kLine3 = 0x76; const std::string DICTIONARYTOKEN = "D"; const std::string BANKToken = "BANK"; -static const TextElement TextCommands[] = { +static const std::vector TextCommands = { TextElement(0x6B, "W", true, "Window border"), TextElement(0x6D, "P", true, "Window position"), TextElement(0x6E, "SPD", true, "Scroll speed"), @@ -93,84 +94,23 @@ static std::vector SpecialChars = { }; static const std::unordered_map CharEncoder = { - {0x00, 'A'}, - {0x01, 'B'}, - {0x02, 'C'}, - {0x03, 'D'}, - {0x04, 'E'}, - {0x05, 'F'}, - {0x06, 'G'}, - {0x07, 'H'}, - {0x08, 'I'}, - {0x09, 'J'}, - {0x0A, 'K'}, - {0x0B, 'L'}, - {0x0C, 'M'}, - {0x0D, 'N'}, - {0x0E, 'O'}, - {0x0F, 'P'}, - {0x10, 'Q'}, - {0x11, 'R'}, - {0x12, 'S'}, - {0x13, 'T'}, - {0x14, 'U'}, - {0x15, 'V'}, - {0x16, 'W'}, - {0x17, 'X'}, - {0x18, 'Y'}, - {0x19, 'Z'}, - {0x1A, 'a'}, - {0x1B, 'b'}, - {0x1C, 'c'}, - {0x1D, 'd'}, - {0x1E, 'e'}, - {0x1F, 'f'}, - {0x20, 'g'}, - {0x21, 'h'}, - {0x22, 'i'}, - {0x23, 'j'}, - {0x24, 'k'}, - {0x25, 'l'}, - {0x26, 'm'}, - {0x27, 'n'}, - {0x28, 'o'}, - {0x29, 'p'}, - {0x2A, 'q'}, - {0x2B, 'r'}, - {0x2C, 's'}, - {0x2D, 't'}, - {0x2E, 'u'}, - {0x2F, 'v'}, - {0x30, 'w'}, - {0x31, 'x'}, - {0x32, 'y'}, - {0x33, 'z'}, - {0x34, '0'}, - {0x35, '1'}, - {0x36, '2'}, - {0x37, '3'}, - {0x38, '4'}, - {0x39, '5'}, - {0x3A, '6'}, - {0x3B, '7'}, - {0x3C, '8'}, - {0x3D, '9'}, - {0x3E, '!'}, - {0x3F, '?'}, - {0x40, '-'}, - {0x41, '.'}, - {0x42, ','}, - {0x44, '>'}, - {0x45, '('}, - {0x46, ')'}, - {0x4C, '"'}, - {0x51, '\''}, - {0x59, ' '}, - {0x5A, '<'}, - // {0x5F, '¡'}, {0x60, '¡'}, {0x61, '¡'}, {0x62, ' '}, {0x63, ' '}, {0x64, - // ' '}, - {0x65, ' '}, - {0x66, '_'}, + {0x00, 'A'}, {0x01, 'B'}, {0x02, 'C'}, {0x03, 'D'}, {0x04, 'E'}, + {0x05, 'F'}, {0x06, 'G'}, {0x07, 'H'}, {0x08, 'I'}, {0x09, 'J'}, + {0x0A, 'K'}, {0x0B, 'L'}, {0x0C, 'M'}, {0x0D, 'N'}, {0x0E, 'O'}, + {0x0F, 'P'}, {0x10, 'Q'}, {0x11, 'R'}, {0x12, 'S'}, {0x13, 'T'}, + {0x14, 'U'}, {0x15, 'V'}, {0x16, 'W'}, {0x17, 'X'}, {0x18, 'Y'}, + {0x19, 'Z'}, {0x1A, 'a'}, {0x1B, 'b'}, {0x1C, 'c'}, {0x1D, 'd'}, + {0x1E, 'e'}, {0x1F, 'f'}, {0x20, 'g'}, {0x21, 'h'}, {0x22, 'i'}, + {0x23, 'j'}, {0x24, 'k'}, {0x25, 'l'}, {0x26, 'm'}, {0x27, 'n'}, + {0x28, 'o'}, {0x29, 'p'}, {0x2A, 'q'}, {0x2B, 'r'}, {0x2C, 's'}, + {0x2D, 't'}, {0x2E, 'u'}, {0x2F, 'v'}, {0x30, 'w'}, {0x31, 'x'}, + {0x32, 'y'}, {0x33, 'z'}, {0x34, '0'}, {0x35, '1'}, {0x36, '2'}, + {0x37, '3'}, {0x38, '4'}, {0x39, '5'}, {0x3A, '6'}, {0x3B, '7'}, + {0x3C, '8'}, {0x3D, '9'}, {0x3E, '!'}, {0x3F, '?'}, {0x40, '-'}, + {0x41, '.'}, {0x42, ','}, {0x44, '>'}, {0x45, '('}, {0x46, ')'}, + {0x4C, '"'}, {0x51, '\''}, {0x59, ' '}, {0x5A, '<'}, {0x5F, L'¡'}, + {0x60, L'¡'}, {0x61, L'¡'}, {0x62, L' '}, {0x63, L' '}, {0x64, L' '}, + {0x65, ' '}, {0x66, '_'}, }; static TextElement DictionaryElement =