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 bool modified = false;
37 };
38
39 std::vector<Cell> cells;
40 int bounds_width = 0; // Bounding box width in 8px tiles
41 int bounds_height = 0; // Bounding box height in 8px tiles
42
43 int tile_data_address = -1; // ROM address for write-back
44 bool is_custom = false;
45 std::string custom_filename;
46
48 const std::vector<ObjectDrawer::TileTrace>& traces);
49
50 // Create an empty layout for new custom object creation
51 static ObjectTileLayout CreateEmpty(int width, int height,
52 int16_t object_id,
53 const std::string& filename);
54
55 Cell* FindCell(int rel_x, int rel_y);
56 const Cell* FindCell(int rel_x, int rel_y) const;
57
58 bool HasModifications() const;
59 void RevertAll();
60};
61
70 public:
71 static constexpr int kAtlasTilesPerRow = 16;
72 static constexpr int kAtlasTileRows = 64;
74 static constexpr int kAtlasWidthPx = kAtlasTilesPerRow * 8;
75 static constexpr int kAtlasHeightPx = kAtlasTileRows * 8;
76
77 explicit ObjectTileEditor(Rom* rom);
78
79 // Capture: run object draw in trace_only mode, build editable layout
80 absl::StatusOr<ObjectTileLayout> CaptureObjectLayout(
81 int16_t object_id, const Room& room,
82 const gfx::PaletteGroup& palette);
83
84 // Render: draw layout to preview bitmap using room's gfx buffer
85 absl::Status RenderLayoutToBitmap(
86 const ObjectTileLayout& layout, 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(
92 gfx::Bitmap& atlas, const uint8_t* room_gfx_buffer,
93 const gfx::PaletteGroup& palette, int display_palette = 2);
94
95 // Write-back: standard objects patch ROM, custom objects write .bin
96 absl::Status WriteBack(const ObjectTileLayout& layout);
97
98 // Check how many objects share the same tile data pointer
99 int CountObjectsSharingTileData(int16_t object_id) const;
100
101 private:
103};
104
105} // namespace zelda3
106} // namespace yaze
107
108#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)