yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
object_tile_editor.h
Go to the documentation of this file.
1#ifndef YAZE_ZELDA3_DUNGEON_OBJECT_TILE_EDITOR_H_
2#define YAZE_ZELDA3_DUNGEON_OBJECT_TILE_EDITOR_H_
3
4#include <cstdint>
5#include <string>
6#include <vector>
7
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "app/gfx/core/bitmap.h"
13#include "rom/rom.h"
15#include "zelda3/dungeon/room.h"
16
17namespace yaze {
18namespace zelda3 {
19
27 int16_t object_id = 0;
30
31 struct Cell {
32 int rel_x = 0; // 0-based tile X within bounding box
33 int rel_y = 0; // 0-based tile Y within bounding box
34 gfx::TileInfo tile_info; // Decomposed SNES tilemap word
35 uint16_t original_word = 0;
36 // Original traced tile-data word index used for ROM write-back.
37 int write_index = -1;
38 bool modified = false;
39 };
40
41 std::vector<Cell> cells;
42 int bounds_width = 0; // Bounding box width in 8px tiles
43 int bounds_height = 0; // Bounding box height in 8px tiles
44
45 int tile_data_address = -1; // ROM address for write-back
46 bool is_custom = false;
47 std::string custom_filename;
48
50 const std::vector<ObjectDrawer::TileTrace>& traces);
51
52 // Create an empty layout for new custom object creation
53 static ObjectTileLayout CreateEmpty(int width, int height, int16_t object_id,
54 const std::string& filename);
55
56 Cell* FindCell(int rel_x, int rel_y);
57 const Cell* FindCell(int rel_x, int rel_y) const;
58
59 bool HasModifications() const;
60 void RevertAll();
61};
62
71 public:
72 static constexpr int kAtlasTilesPerRow = 16;
73 static constexpr int kAtlasTileRows = 64;
75 static constexpr int kAtlasWidthPx = kAtlasTilesPerRow * 8;
76 static constexpr int kAtlasHeightPx = kAtlasTileRows * 8;
77
78 explicit ObjectTileEditor(Rom* rom);
79
80 // Capture: run object draw in trace_only mode, build editable layout
81 absl::StatusOr<ObjectTileLayout> CaptureObjectLayout(
82 int16_t object_id, const Room& room, const gfx::PaletteGroup& palette);
83
84 // Render: draw layout to preview bitmap using room's gfx buffer
85 absl::Status RenderLayoutToBitmap(const ObjectTileLayout& layout,
86 gfx::Bitmap& bitmap,
87 const uint8_t* room_gfx_buffer,
88 const gfx::PaletteGroup& palette);
89
90 // Build tile8 atlas from room graphics buffer.
91 absl::Status BuildTile8Atlas(gfx::Bitmap& atlas,
92 const uint8_t* room_gfx_buffer,
93 const gfx::PaletteGroup& palette,
94 int display_palette = 2);
95
96 // Write-back: standard objects patch ROM, custom objects write .bin
97 absl::Status WriteBack(const ObjectTileLayout& layout);
98
99 // Check how many objects share the same tile data pointer
100 int CountObjectsSharingTileData(int16_t object_id) const;
101
102 private:
104};
105
106} // namespace zelda3
107} // namespace yaze
108
109#endif // YAZE_ZELDA3_DUNGEON_OBJECT_TILE_EDITOR_H_
The Rom class is used to load, save, and modify Rom data. This is a generic SNES ROM container and do...
Definition rom.h:28
Represents a bitmap image optimized for SNES ROM hacking.
Definition bitmap.h:67
SNES 16-bit tile metadata container.
Definition snes_tile.h:52
Captures and edits the tile8 composition of dungeon objects.
absl::Status WriteBack(const ObjectTileLayout &layout)
static constexpr int kAtlasTilesPerRow
absl::Status RenderLayoutToBitmap(const ObjectTileLayout &layout, gfx::Bitmap &bitmap, const uint8_t *room_gfx_buffer, const gfx::PaletteGroup &palette)
int CountObjectsSharingTileData(int16_t object_id) const
static constexpr int kAtlasTileRows
absl::StatusOr< ObjectTileLayout > CaptureObjectLayout(int16_t object_id, const Room &room, const gfx::PaletteGroup &palette)
static constexpr int kAtlasTileCount
static constexpr int kAtlasHeightPx
absl::Status BuildTile8Atlas(gfx::Bitmap &atlas, const uint8_t *room_gfx_buffer, const gfx::PaletteGroup &palette, int display_palette=2)
Represents a group of palettes.
Editable tile8 layout captured from an object's draw trace.
static ObjectTileLayout CreateEmpty(int width, int height, int16_t object_id, const std::string &filename)
Cell * FindCell(int rel_x, int rel_y)
static ObjectTileLayout FromTraces(const std::vector< ObjectDrawer::TileTrace > &traces)