Refactor graphics sheet management with singleton class
Refactor the handling of graphics sheets by introducing a singleton class `GraphicsSheetManager`. This centralizes the management of graphics sheets, replacing direct access through the `Rom` object. Key changes include: - Updated various methods across multiple classes to use `GraphicsSheetManager::GetInstance()` for accessing and manipulating graphics sheets. - Introduced standalone functions `LoadLinkGraphics`, `LoadAllGraphicsData`, and `SaveAllGraphicsData` for loading and saving graphics data. - Refactored the `Rom` class to remove methods and member variables related to graphics sheet management. - Updated `OverworldEditor` to use `std::array` for `maps_bmp_` and added error handling for `std::bad_alloc` exceptions. - Improved code modularity and error handling throughout the application.
This commit is contained in:
@@ -64,7 +64,9 @@ absl::Status EditorManager::Update() {
|
||||
DrawInfoPopup();
|
||||
|
||||
if (rom()->is_loaded() && !rom_assets_loaded_) {
|
||||
RETURN_IF_ERROR(rom()->LoadAllGraphicsData())
|
||||
auto& sheet_manager = GraphicsSheetManager::GetInstance();
|
||||
ASSIGN_OR_RETURN(*sheet_manager.mutable_gfx_sheets(),
|
||||
LoadAllGraphicsData(*rom()))
|
||||
RETURN_IF_ERROR(overworld_editor_.LoadGraphics());
|
||||
rom_assets_loaded_ = true;
|
||||
}
|
||||
@@ -691,6 +693,10 @@ void EditorManager::SaveRom() {
|
||||
status_ = overworld_editor_.Save();
|
||||
RETURN_VOID_IF_ERROR(status_);
|
||||
|
||||
if (core::ExperimentFlags::get().kSaveGraphicsSheet)
|
||||
PRINT_IF_ERROR(SaveAllGraphicsData(*rom(),
|
||||
GraphicsSheetManager::GetInstance().gfx_sheets()));
|
||||
|
||||
status_ = rom()->SaveToFile(backup_rom_, save_new_auto_);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user