From df2bc1035c487712d7d00e09bd30974dab851a5d Mon Sep 17 00:00:00 2001 From: scawful Date: Thu, 27 Feb 2025 17:44:22 -0500 Subject: [PATCH] Refactor MessageEditor: improve code readability and maintainability by adjusting formatting, updating variable names, and reorganizing includes --- src/app/editor/message/message_editor.cc | 21 ++++++++++----------- src/app/editor/message/message_editor.h | 5 +++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/app/editor/message/message_editor.cc b/src/app/editor/message/message_editor.cc index 882faad0..1309e1ee 100644 --- a/src/app/editor/message/message_editor.cc +++ b/src/app/editor/message/message_editor.cc @@ -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 &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(); } diff --git a/src/app/editor/message/message_editor.h b/src/app/editor/message/message_editor.h index 99afae90..30cbf3f0 100644 --- a/src/app/editor/message/message_editor.h +++ b/src/app/editor/message/message_editor.h @@ -6,8 +6,8 @@ #include #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 width_array = {0}; + std::array width_array = {0}; std::vector font_gfx16_data_; std::vector current_font_gfx16_data_; std::vector parsed_messages_;