Add LoadExpandedMessages function to handle loading and parsing of expanded messages from a BIN file
This commit is contained in:
@@ -420,5 +420,23 @@ std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos) {
|
||||
return list_of_texts;
|
||||
}
|
||||
|
||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
||||
std::vector<std::string> &parsed_messages,
|
||||
std::vector<MessageData> &expanded_messages,
|
||||
std::vector<DictionaryEntry> &dictionary) {
|
||||
static Rom expanded_message_rom;
|
||||
if (!expanded_message_rom.LoadFromFile(expanded_message_path, false).ok()) {
|
||||
return absl::InternalError("Failed to load expanded message ROM");
|
||||
}
|
||||
expanded_messages = ReadAllTextData(expanded_message_rom.mutable_data(), 0);
|
||||
auto parsed_expanded_messages =
|
||||
ParseMessageData(expanded_messages, dictionary);
|
||||
// Insert into parsed_messages
|
||||
for (const auto &expanded_message : expanded_messages) {
|
||||
parsed_messages.push_back(parsed_expanded_messages[expanded_message.ID]);
|
||||
}
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
} // namespace editor
|
||||
} // namespace yaze
|
||||
|
||||
@@ -309,6 +309,12 @@ constexpr int kTextData2End = 0x773FF;
|
||||
// Reads all text data from the ROM and returns a vector of MessageData objects.
|
||||
std::vector<MessageData> ReadAllTextData(uint8_t *rom, int pos = kTextData);
|
||||
|
||||
// Calls the file dialog and loads expanded messages from a BIN file.
|
||||
absl::Status LoadExpandedMessages(std::string &expanded_message_path,
|
||||
std::vector<std::string> &parsed_messages,
|
||||
std::vector<MessageData> &expanded_messages,
|
||||
std::vector<DictionaryEntry> &dictionary);
|
||||
|
||||
} // namespace editor
|
||||
} // namespace yaze
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "absl/status/status.h"
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "app/core/platform/file_dialog.h"
|
||||
#include "app/core/window.h"
|
||||
#include "app/gfx/bitmap.h"
|
||||
#include "app/gfx/snes_palette.h"
|
||||
@@ -240,21 +241,12 @@ void MessageEditor::DrawExpandedMessageSettings() {
|
||||
if (ImGui::Button("Load Expanded Message")) {
|
||||
expanded_message_path = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||
if (!expanded_message_path.empty()) {
|
||||
// Load the expanded message from the path.
|
||||
static Rom expanded_message_rom;
|
||||
if (!expanded_message_rom.LoadFromFile(expanded_message_path, false)
|
||||
if (!LoadExpandedMessages(expanded_message_path, parsed_messages_,
|
||||
expanded_messages_,
|
||||
message_preview_.all_dictionaries_)
|
||||
.ok()) {
|
||||
context_->popup_manager->Show("Error");
|
||||
}
|
||||
expanded_messages_ =
|
||||
ReadAllTextData(expanded_message_rom.mutable_data(), 0);
|
||||
auto parsed_expanded_messages = ParseMessageData(
|
||||
expanded_messages_, message_preview_.all_dictionaries_);
|
||||
// Insert into parsed_messages
|
||||
for (const auto& expanded_message : expanded_messages_) {
|
||||
parsed_messages_.push_back(
|
||||
parsed_expanded_messages[expanded_message.ID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user