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:
@@ -706,7 +706,7 @@ void OverworldEditor::DrawTile8Selector() {
|
||||
graphics_bin_canvas_.DrawContextMenu();
|
||||
if (all_gfx_loaded_) {
|
||||
int key = 0;
|
||||
for (auto &value : rom_.gfx_sheets()) {
|
||||
for (auto &value : GraphicsSheetManager::GetInstance().gfx_sheets()) {
|
||||
int offset = 0x40 * (key + 1);
|
||||
int top_left_y = graphics_bin_canvas_.zero_point().y + 2;
|
||||
if (key >= 1) {
|
||||
@@ -1077,9 +1077,15 @@ absl::Status OverworldEditor::LoadGraphics() {
|
||||
for (int i = 0; i < zelda3::kNumOverworldMaps; ++i) {
|
||||
overworld_.set_current_map(i);
|
||||
auto palette = overworld_.current_area_palette();
|
||||
RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap(
|
||||
kOverworldMapSize, kOverworldMapSize, 0x200,
|
||||
try {
|
||||
RETURN_IF_ERROR(Renderer::GetInstance().CreateAndRenderBitmap(
|
||||
kOverworldMapSize, kOverworldMapSize, 0x80,
|
||||
overworld_.current_map_bitmap_data(), maps_bmp_[i], palette));
|
||||
}
|
||||
catch (const std::bad_alloc& e) {
|
||||
std::cout << "Error: " << e.what() << std::endl;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (core::ExperimentFlags::get().overworld.kDrawOverworldSprites) {
|
||||
|
||||
@@ -252,7 +252,7 @@ class OverworldEditor : public Editor, public gfx::GfxContext {
|
||||
gfx::Bitmap current_gfx_bmp_;
|
||||
gfx::Bitmap all_gfx_bmp;
|
||||
|
||||
gfx::BitmapTable maps_bmp_;
|
||||
std::array<gfx::Bitmap, zelda3::kNumOverworldMaps> maps_bmp_;
|
||||
gfx::BitmapTable current_graphics_set_;
|
||||
gfx::BitmapTable sprite_previews_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user