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