yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
graphics_edit_context.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDIT_CONTEXT_H_
2#define YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDIT_CONTEXT_H_
3
4#include <array>
5#include <cstdint>
6#include <functional>
7#include <map>
8#include <optional>
9#include <string>
10#include <vector>
11
12#include "absl/status/statusor.h"
16
17namespace yaze::zelda3 {
18class Room;
19class RoomObject;
20struct GameData;
21} // namespace yaze::zelda3
22
23namespace yaze::editor {
24
25// Addresses for raw 3bpp indices. Index zero is fixed transparency/backdrop and
26// deliberately has no writable address. Every nonzero entry must be proven.
28 const zelda3::GameData* owner = nullptr;
29 uint8_t row = 0;
30 uint8_t half_offset = 0;
31 std::array<std::optional<zelda3::PaletteColorAddress>, 8> colors{};
32};
33
34// A source editor supplies the resolved colors for raw sheet indices. The
35// Graphics editor never infers a palette from a sheet ID in this workflow.
37 uint16_t sheet_id = 0;
38 uint16_t tile_index = 0;
39 std::string label;
41 // Pattern uses of this source tile: bits 0/1/2/3 = normal/H/V/HV.
42 // Zero means the source editor did not supply orientation information.
44 std::optional<GraphicsPaletteAddressing> writable_palette;
46 "No loader-owned palette address mapping.";
47
48 std::string SourceOrientationLabel() const;
49};
50
51// A rendered object cell points at its actual physical source target. Cell
52// coordinates are relative to the object's drawn bounds, in 8x8 tiles.
54 int x = 0;
55 int y = 0;
56 size_t target = 0;
57 bool hflip = false;
58 bool vflip = false;
59};
60
61// Read-only validation against the owning session's current palette model.
62// No fallback RGB lookup or palette/pixel mutation is performed.
64 const zelda3::GameData* owner);
66 GraphicsEditTarget& target, const zelda3::GameData* owner,
67 const zelda3::PaletteAddressMap& addresses, int row, int half_offset);
68
69// Session-local navigation and preview state, not ROM/project data. Callbacks
70// belong to editors in the same EditorSet and are cleared on ROM replacement.
71// Each surface can supply its own live renderer without another graphics cache.
73 const zelda3::GameData* owner = nullptr;
74 std::string label;
75 std::string limitation;
77 std::vector<GraphicsEditTarget> targets;
78 size_t selected_target = 0;
79 std::function<absl::StatusOr<usage_preview::PreviewImage>()> render_preview;
80 std::function<void()> return_to_source;
81 // Cheap source-model identity for unsaved Tile16, placement, and object
82 // edits. Sampled before rendering and again afterward because rendering can
83 // itself advance a source cache revision. Never performs a ROM write.
84 std::function<absl::StatusOr<uint64_t>()> preview_revision;
86 // Re-resolve display colors through the source loader without replacing
87 // the selected raw sheet/tile or pending pixel edits.
88 std::function<absl::Status(GraphicsEditContext&)> refresh_palettes;
89 // Authoritative mutation boundary: resolve the owning live model, including
90 // assignments and tile definitions. A cached preview is insufficient.
91 // Missing callback means palette/pixel commands are unsupported.
92 std::function<absl::Status(GraphicsEditContext&)> resolve_live_source;
93 std::optional<uint64_t> palette_revision;
94 std::string palette_error;
97 std::vector<GraphicsSourceCell> pattern_cells;
98 // A source-owned detached renderer. Supplied pixels never enter the store,
99 // active room, undo history or ROM merely to draw an art candidate.
100 std::function<absl::StatusOr<usage_preview::PreviewImage>(
101 const std::map<uint16_t, std::vector<uint8_t>>&)>
103};
104
105// Applies fresh colors only when the source still addresses the same tiles.
106// A source assignment change requires reopening rather than silently redirecting
107// a pending stroke or paste to a different sheet.
109 GraphicsEditContext refreshed);
110
111// The room must already have its entrance context applied and be prepared for
112// rendering. Animated spans are omitted until they have explicit source maps.
113absl::StatusOr<GraphicsEditContext> MakeDungeonGraphicsEditContext(
114 const zelda3::Room& room, const zelda3::RoomObject& object,
115 const zelda3::GameData* owner);
116
117} // namespace yaze::editor
118
119#endif // YAZE_APP_EDITOR_GRAPHICS_GRAPHICS_EDIT_CONTEXT_H_
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Editors are the view controllers for the application.
absl::Status UpdateGraphicsContextPalettes(GraphicsEditContext &context, GraphicsEditContext refreshed)
void ResolveGraphicsPaletteAddressing(GraphicsEditTarget &target, const zelda3::GameData *owner, const zelda3::PaletteAddressMap &addresses, int row, int half_offset)
absl::StatusOr< GraphicsEditContext > MakeDungeonGraphicsEditContext(const zelda3::Room &room, const zelda3::RoomObject &object, const zelda3::GameData *owner)
absl::Status ValidateGraphicsPaletteAddressing(const GraphicsEditTarget &target, const zelda3::GameData *owner)
Zelda 3 specific classes and functions.
std::array< std::optional< PaletteColorAddress >, 128 > PaletteAddressMap
std::function< absl::StatusOr< usage_preview::PreviewImage >(const std::map< uint16_t, std::vector< uint8_t > > &) render_staged_preview)
std::function< absl::StatusOr< uint64_t >()> preview_revision
zelda3::ResolvedGraphicsContext resolved
std::vector< GraphicsEditTarget > targets
std::function< absl::StatusOr< usage_preview::PreviewImage >()> render_preview
std::function< absl::Status(GraphicsEditContext &) resolve_live_source)
std::vector< GraphicsSourceCell > pattern_cells
std::optional< uint64_t > palette_revision
std::function< absl::Status(GraphicsEditContext &) refresh_palettes)
std::optional< GraphicsPaletteAddressing > writable_palette
std::array< std::optional< zelda3::PaletteColorAddress >, 8 > colors