Refactor MessageEditor: improve code readability and maintainability by adjusting formatting, updating variable names, and reorganizing includes

This commit is contained in:
scawful
2025-02-27 17:44:22 -05:00
parent b6498bf5e9
commit df2bc1035c
2 changed files with 13 additions and 13 deletions

View File

@@ -301,9 +301,9 @@ void MessageEditor::ReadAllTextDataV2() {
uint32_t address = Get24LocalFromPC(
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
uint32_t address_end = Get24LocalFromPC(
rom()->mutable_data(),
kPointersDictionaries + ((dictionary + 1) * 2));
uint32_t address_end =
Get24LocalFromPC(rom()->mutable_data(),
kPointersDictionaries + ((dictionary + 1) * 2));
for (uint32_t i = address; i < address_end; i++) {
parsed_message.push_back(rom()->data()[i]);
@@ -399,9 +399,9 @@ void MessageEditor::ReadAllTextData() {
uint32_t address = Get24LocalFromPC(
rom()->mutable_data(), kPointersDictionaries + (dictionary * 2));
uint32_t address_end = Get24LocalFromPC(
rom()->mutable_data(),
kPointersDictionaries + ((dictionary + 1) * 2));
uint32_t address_end =
Get24LocalFromPC(rom()->mutable_data(),
kPointersDictionaries + ((dictionary + 1) * 2));
for (uint32_t i = address; i < address_end; i++) {
temp_bytes_parsed.push_back(rom()->data()[i]);
@@ -538,7 +538,7 @@ void MessageEditor::DrawCharacterToPreview(const std::vector<uint8_t> &text) {
void MessageEditor::DrawMessagePreview() {
// From Parsing.
text_line_ = 0;
for (int i = 0; i < (172 * 4096); i++) {
for (int i = 0; i < kFontGfx16Size; i++) {
current_font_gfx16_data_[i] = 0;
}
text_position_ = 0;
@@ -614,18 +614,17 @@ absl::Status MessageEditor::Save() {
pos++;
}
RETURN_IF_ERROR(rom()->WriteByte(
pos++, kMessageTerminator)); // , true, "Terminator text"
RETURN_IF_ERROR(rom()->WriteByte(pos++, kMessageTerminator));
}
// Verify that we didn't go over the space available for the second block.
// 0x14BF available.
if ((in_second_bank & pos) > kTextData2End) {
// rom()->data() = backup;
// TODO: Restore the backup.
return absl::InternalError(DisplayTextOverflowError(pos, false));
}
RETURN_IF_ERROR(rom()->WriteByte(pos, 0xFF)); // , true, "End of text"
RETURN_IF_ERROR(rom()->WriteByte(pos, 0xFF));
return absl::OkStatus();
}

View File

@@ -6,8 +6,8 @@
#include <vector>
#include "absl/status/status.h"
#include "app/editor/message/message_data.h"
#include "app/editor/editor.h"
#include "app/editor/message/message_data.h"
#include "app/gfx/bitmap.h"
#include "app/gui/canvas.h"
#include "app/rom.h"
@@ -24,6 +24,7 @@ constexpr int kCurrentMessageWidth = 172;
constexpr int kCurrentMessageHeight = 4096;
constexpr int kFontGfxMessageSize = 128;
constexpr int kFontGfxMessageDepth = 8;
constexpr int kFontGfx16Size = 172 * 4096;
constexpr uint8_t kWidthArraySize = 100;
constexpr uint8_t kBlockTerminator = 0x80;
@@ -80,7 +81,7 @@ class MessageEditor : public Editor, public SharedRom {
std::string search_text_ = "";
std::array<uint8_t, kWidthArraySize> width_array = {0};
std::array<uint8_t, kWidthArraySize> width_array = {0};
std::vector<uint8_t> font_gfx16_data_;
std::vector<uint8_t> current_font_gfx16_data_;
std::vector<std::string> parsed_messages_;